selftests/seccomp: allow clock_nanosleep instead of nanosleep
Subsystems (5)
PATCH 1/1 selftests/seccomp: allow clock_nanosleep instead of nanosleep
glibc 2.31 calls clock_nanosleep when its nanosleep function is used. So the restart_syscall fails after that. In order to deal with it, we trace clock_nanosleep and nanosleep. Then we check for either.
This works just fine on systems with both glibc 2.30 and glibc 2.31, whereas it failed before on a system with glibc 2.31.
--- tools/testing/selftests/seccomp/seccomp_bpf.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
tools/testing/selftests/seccomp/seccomp_bpf.c +8 -6
@@ -2803,12 +2803,13 @@ TEST(syscall_restart) offsetof(struct seccomp_data, nr)),#ifdef __NR_sigreturn -BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_sigreturn,6 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_sigreturn,7 ,0 ), #endif -BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_read,5 ,0 ), -BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_exit,4 ,0 ), -BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_rt_sigreturn,3 ,0 ), -BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_nanosleep,4 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_read,6 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_exit,5 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_rt_sigreturn,4 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_nanosleep,5 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_clock_nanosleep,4 ,0 ), BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_restart_syscall, 4, 0),/* Allow __NR_write for easy logging. */
@@ -2895,7 +2896,8 @@ TEST(syscall_restart)ASSERT_EQ (PTRACE_EVENT_SECCOMP , (status >>16 ));ASSERT_EQ (0 ,ptrace (PTRACE_GETEVENTMSG , child_pid,NULL , &msg));ASSERT_EQ (0x100 , msg); -EXPECT_EQ (__NR_nanosleep,get_syscall (_metadata, child_pid)); + ret =get_syscall (_metadata, child_pid); +EXPECT_TRUE (ret == __NR_nanosleep || ret == __NR_clock_nanosleep);/* Might as well check siginfo for sanity while we're here. */ ASSERT_EQ (0 ,ptrace (PTRACE_GETSIGINFO , child_pid,NULL , &info));
Signature · 1 line
2.20.1
Quoted 8 lines · Thadeu Lima de Souza Cascardo
glibc 2.31 calls
clock_nanosleepwhen its nanosleep function is used. So therestart_syscallfails after that. In order to deal with it, we traceclock_nanosleepand nanosleep. Then we check for either.This works just fine on systems with both glibc 2.30 and glibc 2.31, whereas it failed before on a system with glibc 2.31.
Signed-off-by Thadeu Lima de Souza Cascardo <[email protected]>
Thanks for this! I'm trying to determine if all architectures have __NR_clock_nanosleep ... got some test builds running now, but if it all builds fine, then I'll get this sent to Linus for -rc2.
-Kees
Quoted 40 lines
--- tools/testing/selftests/seccomp/seccomp_bpf.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)tools/testing/selftests/seccomp/seccomp_bpf.c +8
-6@@ -2803,12 +2803,13 @@ TEST(syscall_restart) offsetof(struct seccomp_data, nr)),#ifdef __NR_sigreturn -BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_sigreturn,6 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_sigreturn,7 ,0 ), #endif -BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_read,5 ,0 ), -BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_exit,4 ,0 ), -BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_rt_sigreturn,3 ,0 ), -BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_nanosleep,4 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_read,6 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_exit,5 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_rt_sigreturn,4 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_nanosleep,5 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_clock_nanosleep,4 ,0 ), BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_restart_syscall, 4, 0),/* Allow __NR_write for easy logging. */ @@ -2895,7 +2896,8 @@ TEST(syscall_restart)ASSERT_EQ (PTRACE_EVENT_SECCOMP , (status >>16 ));ASSERT_EQ (0 ,ptrace (PTRACE_GETEVENTMSG , child_pid,NULL , &msg));ASSERT_EQ (0x100 , msg); -EXPECT_EQ (__NR_nanosleep,get_syscall (_metadata, child_pid)); + ret =get_syscall (_metadata, child_pid); +EXPECT_TRUE (ret == __NR_nanosleep || ret == __NR_clock_nanosleep);/* Might as well check siginfo for sanity while we're here. */ ASSERT_EQ (0 ,ptrace (PTRACE_GETSIGINFO , child_pid,NULL , &info));Signature · 1 line
2.20.1
Signature · 1 line
Kees Cook
Quoted 8 lines · Thadeu Lima de Souza Cascardo
glibc 2.31 calls
clock_nanosleepwhen its nanosleep function is used. So therestart_syscallfails after that. In order to deal with it, we traceclock_nanosleepand nanosleep. Then we check for either.This works just fine on systems with both glibc 2.30 and glibc 2.31, whereas it failed before on a system with glibc 2.31.
Signed-off-by Thadeu Lima de Souza Cascardo <[email protected]>
Actually, sorry, this should go via Shuah's tree. :) Shuah, do you have anything going Linus's way already for -rc2?
-Kees
Quoted 40 lines
--- tools/testing/selftests/seccomp/seccomp_bpf.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)tools/testing/selftests/seccomp/seccomp_bpf.c +8
-6@@ -2803,12 +2803,13 @@ TEST(syscall_restart) offsetof(struct seccomp_data, nr)),#ifdef __NR_sigreturn -BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_sigreturn,6 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_sigreturn,7 ,0 ), #endif -BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_read,5 ,0 ), -BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_exit,4 ,0 ), -BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_rt_sigreturn,3 ,0 ), -BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_nanosleep,4 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_read,6 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_exit,5 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_rt_sigreturn,4 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_nanosleep,5 ,0 ), +BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_clock_nanosleep,4 ,0 ), BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, __NR_restart_syscall, 4, 0),/* Allow __NR_write for easy logging. */ @@ -2895,7 +2896,8 @@ TEST(syscall_restart)ASSERT_EQ (PTRACE_EVENT_SECCOMP , (status >>16 ));ASSERT_EQ (0 ,ptrace (PTRACE_GETEVENTMSG , child_pid,NULL , &msg));ASSERT_EQ (0x100 , msg); -EXPECT_EQ (__NR_nanosleep,get_syscall (_metadata, child_pid)); + ret =get_syscall (_metadata, child_pid); +EXPECT_TRUE (ret == __NR_nanosleep || ret == __NR_clock_nanosleep);/* Might as well check siginfo for sanity while we're here. */ ASSERT_EQ (0 ,ptrace (PTRACE_GETSIGINFO , child_pid,NULL , &info));Signature · 1 line
2.20.1
Signature · 1 line
Kees Cook
shuah
maintainerQuoted 8 lines · Kees Cook
Quoted 7 lines · Thadeu Lima de Souza Cascardo
glibc 2.31 calls
clock_nanosleepwhen its nanosleep function is used. So therestart_syscallfails after that. In order to deal with it, we traceclock_nanosleepand nanosleep. Then we check for either.This works just fine on systems with both glibc 2.30 and glibc 2.31, whereas it failed before on a system with glibc 2.31.
Quoted 7 lines
Quoted 1 line
Signed-off-by Thadeu Lima de Souza Cascardo <[email protected]>Actually, sorry, this should go via Shuah's tree. :) Shuah, do you have anything going Linus's way already for -rc2?
Acked-by Kees Cook <[email protected]>
I have a few patches for rc2. I will pick this up.
thanks,
-- Shuah