diff options
| author | Bijan Tabatabai <btabatabai@wisc.edu> | 2026-07-16 17:06:04 -0500 |
|---|---|---|
| committer | Dave Hansen <dave.hansen@linux.intel.com> | 2026-08-13 10:18:58 -0700 |
| commit | dee87e09b0dd63da9b1e1876167ccae37842dfd0 (patch) | |
| tree | 992fcee06d6023941d44381eba19067647140e8c /include/linux/platform_data | |
| parent | 7da514d819a0afb148634aac92b3d190f34947c3 (diff) | |
| download | linux-dee87e09b0dd63da9b1e1876167ccae37842dfd0.tar.gz linux-dee87e09b0dd63da9b1e1876167ccae37842dfd0.zip | |
x86/pkeys: Fix pkey_alloc() return value when pkeys are not supported
The man page for pkey_alloc(2) specifies that it should return -1 with
the errno set to ENOSPC when pkeys are not supported [1]. However, on
x86 pkey_alloc() sets errno to EINVAL when called for the first time
on a CPU that does not support pkeys.
The root cause of this is the x86 implementation of mm_pkey_alloc() not
directly checking if pkeys are supported. It only checks if all the
pkeys have been allocated by comparing the allocation map against
all_pkeys_mask. When OSPKE is not enabled, init_new_context() skips the
initialization of the allocation map, leaving it as 0, while
all_pkeys_mask is 1. mm_pkey_alloc() interprets this as there being a
pkey available and it returns pkey 0. Then, pkey_alloc() fails with
-EINVAL from arch_set_user_pkey_access() instead of returning -ENOSPC.
Subsequent calls to pkey_alloc() do return -ENOSPC because pkey 0 is
left marked as allocated.
Change mm_pkey_alloc() to directly check if OSPKE is enabled, and
return -1 if it is not, which causes pkey_alloc() to return -ENOSPC. The
arm64 and powerpc implementations of mm_pkey_alloc() already do this
check.
[1] https://man7.org/linux/man-pages/man2/pkey_alloc.2.html
[ dhansen: use arch_pkeys_enabled() to follow arm ]
Fixes: e8c24d3a23a4 ("x86/pkeys: Allocation/free syscalls")
Signed-off-by: Bijan Tabatabai <btabatabai@wisc.edu>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Link: https://patch.msgid.link/20260716220604.26452-1-bijan311@gmail.com
Diffstat (limited to 'include/linux/platform_data')
0 files changed, 0 insertions, 0 deletions
