Skip to content

Commit d7d2e5b

Browse files
committed
selftests/seccomp: Add SKIPs for failed unshare()
Running the seccomp tests as a regular user shouldn't just fail tests that require CAP_SYS_ADMIN (for getting a PID namespace). Instead, detect those cases and SKIP them. Additionally, gracefully SKIP missing CONFIG_USER_NS (and add to "config" since we'd prefer to actually test this case). Signed-off-by: Kees Cook <[email protected]>
1 parent 8b1bc88 commit d7d2e5b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
CONFIG_SECCOMP=y
22
CONFIG_SECCOMP_FILTER=y
3+
CONFIG_USER_NS=y

tools/testing/selftests/seccomp/seccomp_bpf.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,7 +3444,10 @@ TEST(user_notification_child_pid_ns)
34443444
struct seccomp_notif req = {};
34453445
struct seccomp_notif_resp resp = {};
34463446

3447-
ASSERT_EQ(unshare(CLONE_NEWUSER | CLONE_NEWPID), 0);
3447+
ASSERT_EQ(unshare(CLONE_NEWUSER | CLONE_NEWPID), 0) {
3448+
if (errno == EINVAL)
3449+
SKIP(return, "kernel missing CLONE_NEWUSER support");
3450+
};
34483451

34493452
listener = user_trap_syscall(__NR_getppid,
34503453
SECCOMP_FILTER_FLAG_NEW_LISTENER);
@@ -3509,7 +3512,10 @@ TEST(user_notification_sibling_pid_ns)
35093512
}
35103513

35113514
/* Create the sibling ns, and sibling in it. */
3512-
ASSERT_EQ(unshare(CLONE_NEWPID), 0);
3515+
ASSERT_EQ(unshare(CLONE_NEWPID), 0) {
3516+
if (errno == EPERM)
3517+
SKIP(return, "CLONE_NEWPID requires CAP_SYS_ADMIN");
3518+
}
35133519
ASSERT_EQ(errno, 0);
35143520

35153521
pid2 = fork();

0 commit comments

Comments
 (0)