Skip to content

Commit ff6d500

Browse files
Terry TrittonSasha Levin
authored andcommitted
selftests/seccomp: Handle EINVAL on unshare(CLONE_NEWPID)
commit ecaaa55 upstream. unshare(CLONE_NEWPID) can return EINVAL if the kernel does not have the CONFIG_PID_NS option enabled. Add a check on these calls to skip the test if we receive EINVAL. Signed-off-by: Terry Tritton <terry.tritton@linaro.org> Link: https://lore.kernel.org/r/20240124141357.1243457-2-terry.tritton@linaro.org Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0eba298 commit ff6d500

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tools/testing/selftests/seccomp/seccomp_bpf.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3709,7 +3709,12 @@ TEST(user_notification_sibling_pid_ns)
37093709
ASSERT_GE(pid, 0);
37103710

37113711
if (pid == 0) {
3712-
ASSERT_EQ(unshare(CLONE_NEWPID), 0);
3712+
ASSERT_EQ(unshare(CLONE_NEWPID), 0) {
3713+
if (errno == EPERM)
3714+
SKIP(return, "CLONE_NEWPID requires CAP_SYS_ADMIN");
3715+
else if (errno == EINVAL)
3716+
SKIP(return, "CLONE_NEWPID is invalid (missing CONFIG_PID_NS?)");
3717+
}
37133718

37143719
pid2 = fork();
37153720
ASSERT_GE(pid2, 0);
@@ -3727,6 +3732,8 @@ TEST(user_notification_sibling_pid_ns)
37273732
ASSERT_EQ(unshare(CLONE_NEWPID), 0) {
37283733
if (errno == EPERM)
37293734
SKIP(return, "CLONE_NEWPID requires CAP_SYS_ADMIN");
3735+
else if (errno == EINVAL)
3736+
SKIP(return, "CLONE_NEWPID is invalid (missing CONFIG_PID_NS?)");
37303737
}
37313738
ASSERT_EQ(errno, 0);
37323739

0 commit comments

Comments
 (0)