]> git.baikalelectronics.ru Git - kernel.git/commitdiff
selftests/vm/pkeys: handle negative sys_pkey_alloc() return code
authorDave Hansen <dave.hansen@linux.intel.com>
Thu, 1 Jul 2021 01:56:56 +0000 (18:56 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 1 Jul 2021 18:06:06 +0000 (11:06 -0700)
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/20210611164157.87AB4246@viggo.jf.intel.com
Fixes: a0091bbe41a7 ("x86/pkeys: Add self-tests")
Reported-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Tested-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
Cc: Ram Pai <linuxram@us.ibm.com>
Cc: Sandipan Das <sandipan@linux.ibm.com>
Cc: Florian Weimer <fweimer@redhat.com>
Cc: "Desnes A. Nunes do Rosario" <desnesn@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Thiago Jung Bauermann <bauerman@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Michal Suchanek <msuchanek@suse.de>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
tools/testing/selftests/vm/protection_keys.c

index 9ee0ae5d3e06cad3d9927dbadad36b7666f7c61d..356d62fca27f0180cf58e8a3d67895f8fb585e03 100644 (file)
@@ -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);