Patch "selftests/vm/pkeys: refill shadow register after implicit kernel write" has been added to the 5.13-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    selftests/vm/pkeys: refill shadow register after implicit kernel write

to the 5.13-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     selftests-vm-pkeys-refill-shadow-register-after-impl.patch
and it can be found in the queue-5.13 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 9b4cde27542760691573109a97682b0f18da9e7b
Author: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
Date:   Wed Jun 30 18:56:59 2021 -0700

    selftests/vm/pkeys: refill shadow register after implicit kernel write
    
    [ Upstream commit 6039ca254979694c5362dfebadd105e286c397bb ]
    
    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().
    
    Link: https://lkml.kernel.org/r/20210611164200.EF76AB73@xxxxxxxxxxxxxxxxxx
    Fixes: 6af17cf89e99 ("x86/pkeys/selftests: Add PROT_EXEC test")
    Signed-off-by: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
    Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
    Tested-by: Aneesh Kumar K.V <aneesh.kumar@xxxxxxxxxxxxx>
    Cc: Ram Pai <linuxram@xxxxxxxxxx>
    Cc: Sandipan Das <sandipan@xxxxxxxxxxxxx>
    Cc: Florian Weimer <fweimer@xxxxxxxxxx>
    Cc: "Desnes A. Nunes do Rosario" <desnesn@xxxxxxxxxxxxxxxxxx>
    Cc: Ingo Molnar <mingo@xxxxxxxxxx>
    Cc: Thiago Jung Bauermann <bauerman@xxxxxxxxxxxxx>
    Cc: Michael Ellerman <mpe@xxxxxxxxxxxxxx>
    Cc: Michal Hocko <mhocko@xxxxxxxxxx>
    Cc: Michal Suchanek <msuchanek@xxxxxxx>
    Cc: Shuah Khan <shuah@xxxxxxxxxx>
    Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c
index 356d62fca27f..87eecd5ba577 100644
--- a/tools/testing/selftests/vm/protection_keys.c
+++ b/tools/testing/selftests/vm/protection_keys.c
@@ -1448,6 +1448,13 @@ void test_implicit_mprotect_exec_only_memory(int *ptr, u16 pkey)
 	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 */



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux