@@ -1487,7 +1487,7 @@ TEST_F(precedence, log_is_fifth_in_any_order)
1487
1487
#define PTRACE_EVENT_SECCOMP 7
1488
1488
#endif
1489
1489
1490
- #define IS_SECCOMP_EVENT (status ) ((status >> 16) == PTRACE_EVENT_SECCOMP )
1490
+ #define PTRACE_EVENT_MASK (status ) ((status) >> 16)
1491
1491
bool tracer_running ;
1492
1492
void tracer_stop (int sig )
1493
1493
{
@@ -1539,12 +1539,22 @@ void start_tracer(struct __test_metadata *_metadata, int fd, pid_t tracee,
1539
1539
1540
1540
if (wait (& status ) != tracee )
1541
1541
continue ;
1542
- if (WIFSIGNALED (status ) || WIFEXITED (status ))
1543
- /* Child is dead. Time to go. */
1542
+
1543
+ if (WIFSIGNALED (status )) {
1544
+ /* Child caught a fatal signal. */
1545
+ return ;
1546
+ }
1547
+ if (WIFEXITED (status )) {
1548
+ /* Child exited with code. */
1544
1549
return ;
1550
+ }
1545
1551
1546
- /* Check if this is a seccomp event. */
1547
- ASSERT_EQ (!ptrace_syscall , IS_SECCOMP_EVENT (status ));
1552
+ /* Check if we got an expected event. */
1553
+ ASSERT_EQ (WIFCONTINUED (status ), false);
1554
+ ASSERT_EQ (WIFSTOPPED (status ), true);
1555
+ ASSERT_EQ (WSTOPSIG (status ) & SIGTRAP , SIGTRAP ) {
1556
+ TH_LOG ("Unexpected WSTOPSIG: %d" , WSTOPSIG (status ));
1557
+ }
1548
1558
1549
1559
tracer_func (_metadata , tracee , status , args );
1550
1560
@@ -1961,6 +1971,11 @@ void tracer_seccomp(struct __test_metadata *_metadata, pid_t tracee,
1961
1971
int ret ;
1962
1972
unsigned long msg ;
1963
1973
1974
+ EXPECT_EQ (PTRACE_EVENT_MASK (status ), PTRACE_EVENT_SECCOMP ) {
1975
+ TH_LOG ("Unexpected ptrace event: %d" , PTRACE_EVENT_MASK (status ));
1976
+ return ;
1977
+ }
1978
+
1964
1979
/* Make sure we got the right message. */
1965
1980
ret = ptrace (PTRACE_GETEVENTMSG , tracee , NULL , & msg );
1966
1981
EXPECT_EQ (0 , ret );
@@ -2011,6 +2026,11 @@ void tracer_ptrace(struct __test_metadata *_metadata, pid_t tracee,
2011
2026
long * syscall_nr = NULL , * syscall_ret = NULL ;
2012
2027
FIXTURE_DATA (TRACE_syscall ) * self = args ;
2013
2028
2029
+ EXPECT_EQ (WSTOPSIG (status ) & 0x80 , 0x80 ) {
2030
+ TH_LOG ("Unexpected WSTOPSIG: %d" , WSTOPSIG (status ));
2031
+ return ;
2032
+ }
2033
+
2014
2034
/*
2015
2035
* The traditional way to tell PTRACE_SYSCALL entry/exit
2016
2036
* is by counting.
@@ -2128,6 +2148,7 @@ FIXTURE_SETUP(TRACE_syscall)
2128
2148
ret = prctl (PR_SET_NO_NEW_PRIVS , 1 , 0 , 0 , 0 );
2129
2149
ASSERT_EQ (0 , ret );
2130
2150
2151
+ /* Do not install seccomp rewrite filters, as we'll use ptrace instead. */
2131
2152
if (variant -> use_ptrace )
2132
2153
return ;
2133
2154
@@ -2186,6 +2207,29 @@ TEST_F(TRACE_syscall, syscall_faked)
2186
2207
EXPECT_SYSCALL_RETURN (45000 , syscall (__NR_gettid ));
2187
2208
}
2188
2209
2210
+ TEST_F_SIGNAL (TRACE_syscall , kill_immediate , SIGSYS )
2211
+ {
2212
+ struct sock_filter filter [] = {
2213
+ BPF_STMT (BPF_LD |BPF_W |BPF_ABS ,
2214
+ offsetof(struct seccomp_data , nr )),
2215
+ BPF_JUMP (BPF_JMP |BPF_JEQ |BPF_K , __NR_mknodat , 0 , 1 ),
2216
+ BPF_STMT (BPF_RET |BPF_K , SECCOMP_RET_KILL_THREAD ),
2217
+ BPF_STMT (BPF_RET |BPF_K , SECCOMP_RET_ALLOW ),
2218
+ };
2219
+ struct sock_fprog prog = {
2220
+ .len = (unsigned short )ARRAY_SIZE (filter ),
2221
+ .filter = filter ,
2222
+ };
2223
+ long ret ;
2224
+
2225
+ /* Install "kill on mknodat" filter. */
2226
+ ret = prctl (PR_SET_SECCOMP , SECCOMP_MODE_FILTER , & prog , 0 , 0 );
2227
+ ASSERT_EQ (0 , ret );
2228
+
2229
+ /* This should immediately die with SIGSYS, regardless of tracer. */
2230
+ EXPECT_EQ (-1 , syscall (__NR_mknodat , -1 , NULL , 0 , 0 ));
2231
+ }
2232
+
2189
2233
TEST_F (TRACE_syscall , skip_after )
2190
2234
{
2191
2235
struct sock_filter filter [] = {
@@ -4087,7 +4131,7 @@ TEST(user_notification_addfd)
4087
4131
* lowest available fd to be assigned here.
4088
4132
*/
4089
4133
EXPECT_EQ (fd , nextfd ++ );
4090
- EXPECT_EQ (filecmp (getpid (), pid , memfd , fd ), 0 );
4134
+ ASSERT_EQ (filecmp (getpid (), pid , memfd , fd ), 0 );
4091
4135
4092
4136
/*
4093
4137
* This sets the ID of the ADD FD to the last request plus 1. The
0 commit comments