Skip to content

Commit 6998a73

Browse files
Keith LucasKAGA-KOKO
authored andcommitted
selftests/mm: Add new testcases for pkeys
Add a few new tests to exercise the signal handler flow, especially with PKEY 0 disabled: - Verify that the SIGSEGV handler is invoked when pkey 0 is disabled. - Verify that a thread which disables PKEY 0 segfaults with PKUERR when accessing the stack. - Verify that the SIGSEGV handler that uses an alternate signal stack is correctly invoked when the thread disabled PKEY 0 - Verify that the PKRU value set by the application is correctly restored upon return from signal handling. - Verify that sigreturn() is able to restore the altstack even if the thread had PKEY 0 disabled [ Aruna: Adapted to upstream ] [ tglx: Made it actually compile. Restored protection_keys compile. Added useful info to the changelog instead of bare function names. ] Signed-off-by: Keith Lucas <keith.lucas@oracle.com> Signed-off-by: Aruna Ramakrishna <aruna.ramakrishna@oracle.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/all/20240802061318.2140081-6-aruna.ramakrishna@oracle.com
1 parent d10b554 commit 6998a73

4 files changed

Lines changed: 494 additions & 11 deletions

File tree

tools/testing/selftests/mm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ CAN_BUILD_X86_64 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_64bit_pr
8888
CAN_BUILD_WITH_NOPIE := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_program.c -no-pie)
8989

9090
VMTARGETS := protection_keys
91+
VMTARGETS += pkey_sighandler_tests
9192
BINARIES_32 := $(VMTARGETS:%=%_32)
9293
BINARIES_64 := $(VMTARGETS:%=%_64)
9394

tools/testing/selftests/mm/pkey-helpers.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,18 @@ extern void abort_hooks(void);
7979
} \
8080
} while (0)
8181

82-
__attribute__((noinline)) int read_ptr(int *ptr);
82+
#define barrier() __asm__ __volatile__("": : :"memory")
83+
#ifndef noinline
84+
# define noinline __attribute__((noinline))
85+
#endif
86+
87+
noinline int read_ptr(int *ptr)
88+
{
89+
/* Keep GCC from optimizing this away somehow */
90+
barrier();
91+
return *ptr;
92+
}
93+
8394
void expected_pkey_fault(int pkey);
8495
int sys_pkey_alloc(unsigned long flags, unsigned long init_val);
8596
int sys_pkey_free(unsigned long pkey);

0 commit comments

Comments
 (0)