[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210611164200.EF76AB73@viggo.jf.intel.com>
Date: Fri, 11 Jun 2021 09:42:00 -0700
From: Dave Hansen <dave.hansen@...ux.intel.com>
To: linux-mm@...ck.org
Cc: linux-kernel@...r.kernel.org,
Dave Hansen <dave.hansen@...ux.intel.com>, tglx@...utronix.de,
linuxram@...ibm.com, sandipan@...ux.ibm.com,
akpm@...ux-foundation.org, fweimer@...hat.com,
desnesn@...ux.vnet.ibm.com, mingo@...nel.org,
bauerman@...ux.ibm.com, aneesh.kumar@...ux.ibm.com,
mpe@...erman.id.au, mhocko@...nel.org, msuchanek@...e.de,
shuah@...nel.org, x86@...nel.org
Subject: [PATCH 3/4] selftests/vm/pkeys: Refill shadow register after implicit kernel write
From: Dave Hansen <dave.hansen@...ux.intel.com>
The pkey test code keeps a "shadow" of the pkey register around. This
ensures that any bugs which might write to the register can be caught
more quickly.
Generally, userspace has a good idea when the kernel is going to write
to the register. For instance, alloc_pkey() is passed a permission
mask. The caller of alloc_pkey() can update the shadow based on the
return value and the mask.
But, the kernel can also modify the pkey register in a more sneaky
way. For mprotect(PROT_EXEC) mappings, the kernel will allocate a
pkey and write the pkey register to create an execute-only mapping.
The kernel never tells userspace what key it uses for this.
This can cause the test to fail with messages like:
protection_keys_64.2: pkey-helpers.h:132: _read_pkey_reg: Assertion `pkey_reg == shadow_pkey_reg' failed.
because the shadow was not updated with the new kernel-set value.
Forcibly update the shadow value immediately after an mprotect().
Fixes: 6af17cf89e99 ("x86/pkeys/selftests: Add PROT_EXEC test")
Signed-off-by: Dave Hansen <dave.hansen@...ux.intel.com>
Signed-off-by: Thomas Gleixner <tglx@...utronix.de>
Cc: Ram Pai <linuxram@...ibm.com>
Cc: Sandipan Das <sandipan@...ux.ibm.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>
Cc: Florian Weimer <fweimer@...hat.com>
Cc: "Desnes A. Nunes do Rosario" <desnesn@...ux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@...nel.org>
Cc: Thiago Jung Bauermann <bauerman@...ux.ibm.com>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@...ux.ibm.com>
Cc: Michael Ellerman <mpe@...erman.id.au>
Cc: Michal Hocko <mhocko@...nel.org>
Cc: Michal Suchanek <msuchanek@...e.de>
Cc: Shuah Khan <shuah@...nel.org>
Cc: x86@...nel.org
---
b/tools/testing/selftests/vm/protection_keys.c | 7 +++++++
1 file changed, 7 insertions(+)
diff -puN tools/testing/selftests/vm/protection_keys.c~selftests_vm_pkeys_Refill_shadow_register_after_implict_kernel_write-1 tools/testing/selftests/vm/protection_keys.c
--- a/tools/testing/selftests/vm/protection_keys.c~selftests_vm_pkeys_Refill_shadow_register_after_implict_kernel_write-1 2021-06-11 09:41:33.508468061 -0700
+++ b/tools/testing/selftests/vm/protection_keys.c 2021-06-11 09:41:33.517468061 -0700
@@ -1448,6 +1448,13 @@ void test_implicit_mprotect_exec_only_me
ret = mprotect(p1, PAGE_SIZE, PROT_EXEC);
pkey_assert(!ret);
+ /*
+ * Reset the shadow, assuming that the above mprotect()
+ * correctly changed PKRU, but to an unknown value since
+ * the actual alllocated pkey is unknown.
+ */
+ shadow_pkey_reg = __read_pkey_reg();
+
dprintf2("pkey_reg: %016llx\n", read_pkey_reg());
/* Make sure this is an *instruction* fault */
_
Powered by blists - more mailing lists