mirror of
https://github.com/torvalds/linux.git
synced 2026-12-03 20:06:35 +00:00
sys_pkey_alloc, sys_pkey_free and sys_mprotect_pkey are currently used in
protections_keys.c, while pkey_sighandler_tests.c calls the libc wrappers
directly (e.g. pkey_mprotect()). This is probably ok when using glibc
(those symbols appeared a while ago), but Musl does not currently provide
them. The logging in the helpers from pkey-helpers.h can also come in
handy.
Make things more consistent by using the sys_pkey helpers in
pkey_sighandler_tests.c too. To that end their implementation is moved to
a common .c file (pkey_util.c). This also enables calling
is_pkeys_supported() outside of protections_keys.c, since it relies on
sys_pkey_{alloc,free}.
[[email protected]: fix dependency on pkey_util.c]
Link: https://lkml.kernel.org/r/[email protected]
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Kevin Brodsky <[email protected]>
Cc: Aruna Ramakrishna <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: Joey Gouly <[email protected]>
Cc: Keith Lucas <[email protected]>
Cc: Ryan Roberts <[email protected]>
Cc: Shuah Khan <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
41 lines
1.0 KiB
C
41 lines
1.0 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
#include <sys/syscall.h>
|
|
#include <unistd.h>
|
|
|
|
#include "pkey-helpers.h"
|
|
|
|
int sys_pkey_alloc(unsigned long flags, unsigned long init_val)
|
|
{
|
|
int ret = syscall(SYS_pkey_alloc, flags, init_val);
|
|
dprintf1("%s(flags=%lx, init_val=%lx) syscall ret: %d errno: %d\n",
|
|
__func__, flags, init_val, ret, errno);
|
|
return ret;
|
|
}
|
|
|
|
int sys_pkey_free(unsigned long pkey)
|
|
{
|
|
int ret = syscall(SYS_pkey_free, pkey);
|
|
dprintf1("%s(pkey=%ld) syscall ret: %d\n", __func__, pkey, ret);
|
|
return ret;
|
|
}
|
|
|
|
int sys_mprotect_pkey(void *ptr, size_t size, unsigned long orig_prot,
|
|
unsigned long pkey)
|
|
{
|
|
int sret;
|
|
|
|
dprintf2("%s(0x%p, %zx, prot=%lx, pkey=%lx)\n", __func__,
|
|
ptr, size, orig_prot, pkey);
|
|
|
|
errno = 0;
|
|
sret = syscall(__NR_pkey_mprotect, ptr, size, orig_prot, pkey);
|
|
if (errno) {
|
|
dprintf2("SYS_mprotect_key sret: %d\n", sret);
|
|
dprintf2("SYS_mprotect_key prot: 0x%lx\n", orig_prot);
|
|
dprintf2("SYS_mprotect_key failed, errno: %d\n", errno);
|
|
if (DEBUG_LEVEL >= 2)
|
|
perror("SYS_mprotect_pkey");
|
|
}
|
|
return sret;
|
|
}
|