Commit 6998a73e authored by Keith Lucas's avatar Keith Lucas Committed by Thomas Gleixner

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: default avatarKeith Lucas <keith.lucas@oracle.com>
Signed-off-by: default avatarAruna Ramakrishna <aruna.ramakrishna@oracle.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Link: https://lore.kernel.org/all/20240802061318.2140081-6-aruna.ramakrishna@oracle.com
parent d10b5549
...@@ -88,6 +88,7 @@ CAN_BUILD_X86_64 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_64bit_pr ...@@ -88,6 +88,7 @@ CAN_BUILD_X86_64 := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_64bit_pr
CAN_BUILD_WITH_NOPIE := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_program.c -no-pie) CAN_BUILD_WITH_NOPIE := $(shell ./../x86/check_cc.sh "$(CC)" ../x86/trivial_program.c -no-pie)
VMTARGETS := protection_keys VMTARGETS := protection_keys
VMTARGETS += pkey_sighandler_tests
BINARIES_32 := $(VMTARGETS:%=%_32) BINARIES_32 := $(VMTARGETS:%=%_32)
BINARIES_64 := $(VMTARGETS:%=%_64) BINARIES_64 := $(VMTARGETS:%=%_64)
......
...@@ -79,7 +79,18 @@ extern void abort_hooks(void); ...@@ -79,7 +79,18 @@ extern void abort_hooks(void);
} \ } \
} while (0) } while (0)
__attribute__((noinline)) int read_ptr(int *ptr); #define barrier() __asm__ __volatile__("": : :"memory")
#ifndef noinline
# define noinline __attribute__((noinline))
#endif
noinline int read_ptr(int *ptr)
{
/* Keep GCC from optimizing this away somehow */
barrier();
return *ptr;
}
void expected_pkey_fault(int pkey); void expected_pkey_fault(int pkey);
int sys_pkey_alloc(unsigned long flags, unsigned long init_val); int sys_pkey_alloc(unsigned long flags, unsigned long init_val);
int sys_pkey_free(unsigned long pkey); int sys_pkey_free(unsigned long pkey);
......
This diff is collapsed.
...@@ -950,16 +950,6 @@ void close_test_fds(void) ...@@ -950,16 +950,6 @@ void close_test_fds(void)
nr_test_fds = 0; nr_test_fds = 0;
} }
#define barrier() __asm__ __volatile__("": : :"memory")
__attribute__((noinline)) int read_ptr(int *ptr)
{
/*
* Keep GCC from optimizing this away somehow
*/
barrier();
return *ptr;
}
void test_pkey_alloc_free_attach_pkey0(int *ptr, u16 pkey) void test_pkey_alloc_free_attach_pkey0(int *ptr, u16 pkey)
{ {
int i, err; int i, err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment