selftests, x86: updates for x86 protection keys self tests
Dave Hansen
maintainercover selftests, x86: updates for x86 protection keys self tests
The memory protection keys selftests are spewing warnings. This fixes them up. Thanks, Shuah, for sending these first two a few weeks ago! I wrongly assumed they would get picked up somewhere.
I also included a fix that affected the 32-bit version of the pkeys test case. It was parsing the siginfo incorrectly.
Dave Hansen
maintainerPATCH 1/4 selftests, x86, protection_keys: fix unused variable compile warnings
From: Shuah Khan <[email protected]>
Fix unused variable compile warnings in protection_keys.c
---
b/tools/testing/selftests/x86/protection_keys.c | 5 ----- 1 file changed, 5 deletions(-)
tools/testing/selftests/x86/protection_keys.c renamed from tools/testing/selftests/x86/protection_keys.c~selftests-x86-protection-keys-fix-unused-variable-compile-warnings +0 -5
@@ -812,8 +812,6 @@ void setup_hugetlbfs(void) {int err;int fd; -int validated_nr_pages; -int i;char buf[] ="123" ;if (geteuid () !=0 ) {
@@ -1133,7 +1131,6 @@ void test_pkey_syscalls_on_non_allocatedvoid test_pkey_syscalls_bad_args (int *ptr,u16 pkey) {int err; -int bad_flag = (PKEY_DISABLE_ACCESS |PKEY_DISABLE_WRITE ) +1 ;int bad_pkey =NR_PKEYS +99 ;/* not enforced when pkey_get() is not a syscall
@@ -1149,8 +1146,6 @@ void test_pkey_syscalls_bad_args(int *pt/* Assumes that all pkeys other than 'pkey' are unallocated */ void test_pkey_alloc_exhaust (int *ptr,u16 pkey) { -unsigned long flags; -unsigned long init_val;int err;int allocated_pkeys[NR_PKEYS ] = {0 };int nr_allocated_pkeys =0 ;
_
Re: [PATCH 1/4] selftests, x86, protection_keys: fix unused variable compile warnings
Quoted 6 lines · Dave Hansen
From: Shuah Khan <[email protected]>
Fix unused variable compile warnings in
protection_keys.cSigned-off-by Shuah Khan <[email protected]>Signed-off-by Dave Hansen <[email protected]>
Hi Dave,
This patches is already in linux-kselftest next for 4.11
Is there a reason why you chose to resend these.
-- Shuah
Quoted 36 lines
---
b/tools/testing/selftests/x86/protection_keys.c | 5 ----- 1 file changed, 5 deletions(-)diff -puN
tools/testing/selftests/x86/protection_keys.c~selftests-x86-protection-keys-fix-unused-variable-compile-warningstools/testing/selftests/x86/protection_keys.ctools/testing/selftests/x86/protection_keys.c renamed from tools/testing/selftests/x86/protection_keys.c~selftests-x86-protection-keys-fix-unused-variable-compile-warnings +0
-5@@ -812,8 +812,6 @@ void setup_hugetlbfs(void) {int err;int fd; -int validated_nr_pages; -int i;char buf[] ="123" ;if (geteuid () !=0 ) {@@ -1133,7 +1131,6 @@ void test_pkey_syscalls_on_non_allocatedvoid test_pkey_syscalls_bad_args (int *ptr,u16 pkey) {int err; -int bad_flag = (PKEY_DISABLE_ACCESS |PKEY_DISABLE_WRITE ) +1 ;int bad_pkey =NR_PKEYS +99 ;/* not enforced when pkey_get() is not a syscall @@ -1149,8 +1146,6 @@ void test_pkey_syscalls_bad_args(int *pt/* Assumes that all pkeys other than 'pkey' are unallocated */ void test_pkey_alloc_exhaust (int *ptr,u16 pkey) { -unsigned long flags; -unsigned long init_val;int err;int allocated_pkeys[NR_PKEYS ] = {0 };int nr_allocated_pkeys =0 ;_
Dave Hansen
maintainerRe: [PATCH 1/4] selftests, x86, protection_keys: fix unused variable compile warnings
Quoted 3 lines · Shuah Khan
This patches is already in linux-kselftest next for 4.11
Is there a reason why you chose to resend these.
Oh, my apologies! I didn't realize it had been picked up elsewhere. Ingo had mentioned a few times in the last few days that he'd noticed the warnings.
So, x86 maintainers, do we want these to go through the kselftest tree or the x86 tree?
Re: [PATCH 1/4] selftests, x86, protection_keys: fix unused variable compile warnings
Quoted 12 lines · Dave Hansen
Quoted 3 lines · Shuah Khan
This patches is already in linux-kselftest next for 4.11
Is there a reason why you chose to resend these.
Oh, my apologies! I didn't realize it had been picked up elsewhere. Ingo had mentioned a few times in the last few days that he'd noticed the warnings.
So, x86 maintainers, do we want these to go through the kselftest tree or the x86 tree?
I usually let many of the new tests that depend on new features go through x86 tree. Patches that fix problems that are already in kselftest, I send them up in via kselftest.
I noticed these when very early on when 4.10-rc1 came out and send the patches out. SO they have been in linux-kselftest next for a while now.
thanks,
-- Shuah
Ingo Molnar
Acked-byRe: [PATCH 1/4] selftests, x86, protection_keys: fix unused variable compile warnings
Quoted 14 lines · Shuah Khan
Quoted 12 lines · Dave Hansen
Quoted 3 lines · Shuah Khan
This patches is already in linux-kselftest next for 4.11
Is there a reason why you chose to resend these.
Oh, my apologies! I didn't realize it had been picked up elsewhere. Ingo had mentioned a few times in the last few days that he'd noticed the warnings.
So, x86 maintainers, do we want these to go through the kselftest tree or the x86 tree?
Quoted 6 lines
I usually let many of the new tests that depend on new features go through x86 tree. Patches that fix problems that are already in kselftest, I send them up in via kselftest.
I noticed these when very early on when 4.10-rc1 came out and send the patches out. SO they have been in linux-kselftest next for a while now.
That's OK, but please Cc: me (or at least lkml) next time around.
Also, these should have been sent to Linus as fixes once the warnings were noticed, not queued up for v4.11 - but it's probably too late for that.
Are you going to pick up the other two fixes as well? They look good to me:
Thanks,
Ingo
Dave Hansen
maintainerPATCH 2/4 selftests, x86, protection_keys: remove dead code
In reply to Dave HansenFrom: Shuah Khan <[email protected]>
Remove commented out calls to pkey_get().
---
b/tools/testing/selftests/x86/protection_keys.c | 10 ---------- 1 file changed, 10 deletions(-)
tools/testing/selftests/x86/protection_keys.c renamed from tools/testing/selftests/x86/protection_keys.c~selftests-x86-protection-keys-remove-dead-code +0 -10
@@ -1114,11 +1114,6 @@ void test_pkey_syscalls_on_non_allocated err =sys_pkey_free (i);pkey_assert (err); -/* not enforced when pkey_get() is not a syscall -err = pkey_get(i, 0); -pkey_assert(err < 0); -*/ - err =sys_pkey_free (i);pkey_assert (err);
@@ -1133,11 +1128,6 @@ void test_pkey_syscalls_bad_args(int *ptint err;int bad_pkey =NR_PKEYS +99 ; -/* not enforced when pkey_get() is not a syscall -err = pkey_get(bad_pkey, bad_flag); -pkey_assert(err < 0); -*/ -/* pass a known-invalid pkey in: */ err =sys_mprotect_pkey (ptr,PAGE_SIZE ,PROT_READ , bad_pkey);pkey_assert (err);
_
Re: [PATCH 2/4] selftests, x86, protection_keys: remove dead code
Quoted 6 lines · Dave Hansen
From: Shuah Khan <[email protected]>
Remove commented out calls to
pkey_get().Signed-off-by Shuah Khan <[email protected]>Signed-off-by Dave Hansen <[email protected]>
Hi Dave,
This patches is already in linux-kselftest next for 4.11
Is there a reason why you chose to resend these.
-- Shuah
Quoted 34 lines
---
b/tools/testing/selftests/x86/protection_keys.c | 10 ---------- 1 file changed, 10 deletions(-)diff -puN
tools/testing/selftests/x86/protection_keys.c~selftests-x86-protection-keys-remove-dead-codetools/testing/selftests/x86/protection_keys.ctools/testing/selftests/x86/protection_keys.c renamed from tools/testing/selftests/x86/protection_keys.c~selftests-x86-protection-keys-remove-dead-code +0
-10@@ -1114,11 +1114,6 @@ void test_pkey_syscalls_on_non_allocated err =sys_pkey_free (i);pkey_assert (err); -/* not enforced when pkey_get() is not a syscall -err = pkey_get(i, 0); -pkey_assert(err < 0); -*/ - err =sys_pkey_free (i);pkey_assert (err);@@ -1133,11 +1128,6 @@ void test_pkey_syscalls_bad_args(int *ptint err;int bad_pkey =NR_PKEYS +99 ; -/* not enforced when pkey_get() is not a syscall -err = pkey_get(bad_pkey, bad_flag); -pkey_assert(err < 0); -*/ -/* pass a known-invalid pkey in: */ err =sys_mprotect_pkey (ptr,PAGE_SIZE ,PROT_READ , bad_pkey);pkey_assert (err);_
Dave Hansen
maintainerPATCH 3/4 selftests, x86, protection_keys: fix uninitialized variable warning
In reply to Dave HansenFrom: Dave Hansen <[email protected]>
'orig_pkru' might have been uninitialized here. Fix it.
---
b/tools/testing/selftests/x86/protection_keys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/x86/protection_keys.c renamed from tools/testing/selftests/x86/protection_keys.c~pkeys-selftests-cleanrup-4-10-ish +1 -1
@@ -462,7 +462,7 @@ void pkey_disable_set(int pkey, int flagunsigned long syscall_flags =0 ;int ret;int pkey_rights; -u32 orig_pkru; +u32 orig_pkru =rdpkru ();dprintf1 ("START->%s(%d, 0x%x)\n" , __func__, pkey, flags);
_
Dave Hansen
maintainerPATCH 4/4 selftests, x86, protection_keys: fix wrong offset in siginfo
In reply to Dave HansenFrom: Dave Hansen <[email protected]>
The siginfo contains a bunch of information about the fault. For protection keys, it tells us which protection key's permissions were violated.
The wrong offset in here leads to reading garbage and thus failures in the tests.
We should probably eventually move this over to using the kernel's headers defining the siginfo instead of a hard-coded offset. But, for now, just do the simplest fix.
---
b/tools/testing/selftests/x86/protection_keys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/x86/protection_keys.c renamed from tools/testing/selftests/x86/protection_keys.c~pkeys-selftest-fix-32bit-offset +1 -1
@@ -192,7 +192,7 @@ void lots_o_noops_around_write(int *writ#define SYS_pkey_alloc 381#define SYS_pkey_free 382#define REG_IP_IDX REG_EIP -#define si_pkey_offset 0x18 +#define si_pkey_offset 0x14#else #define SYS_mprotect_key 329#define SYS_pkey_alloc 330
_