Skip to content
/ linux Public
forked from torvalds/linux

Commit

Permalink
selftests/vm/pkeys: handle negative sys_pkey_alloc() return code
Browse files Browse the repository at this point in the history
The alloc_pkey() sefltest function wraps the sys_pkey_alloc() system call.
On success, it updates its "shadow" register value because
sys_pkey_alloc() updates the real register.

But, the success check is wrong.  pkey_alloc() considers any non-zero
return code to indicate success where the pkey register will be modified.
This fails to take negative return codes into account.

Consider only a positive return value as a successful call.

Link: https://lkml.kernel.org/r/[email protected]
Fixes: 5f23f6d ("x86/pkeys: Add self-tests")
Reported-by: Thomas Gleixner <[email protected]>
Signed-off-by: Dave Hansen <[email protected]>
Tested-by: Aneesh Kumar K.V <[email protected]>
Cc: Ram Pai <[email protected]>
Cc: Sandipan Das <[email protected]>
Cc: Florian Weimer <[email protected]>
Cc: "Desnes A. Nunes do Rosario" <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Thiago Jung Bauermann <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Michal Suchanek <[email protected]>
Cc: Shuah Khan <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
hansendc authored and torvalds committed Jul 1, 2021
1 parent f36ef40 commit bf68294
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tools/testing/selftests/vm/protection_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ int alloc_pkey(void)
" shadow: 0x%016llx\n",
__func__, __LINE__, ret, __read_pkey_reg(),
shadow_pkey_reg);
if (ret) {
if (ret > 0) {
/* clear both the bits: */
shadow_pkey_reg = set_pkey_bits(shadow_pkey_reg, ret,
~PKEY_MASK);
Expand Down

0 comments on commit bf68294

Please sign in to comment.