Skip to content

Commit

Permalink
selftests/seccomp: Handle EINVAL on unshare(CLONE_NEWPID)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Terry Tritton authored and gregkh committed May 2, 2024
1 parent f4b1e2c commit 612fbf6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tools/testing/selftests/seccomp/seccomp_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3709,7 +3709,12 @@ TEST(user_notification_sibling_pid_ns)
ASSERT_GE(pid, 0);

if (pid == 0) {
ASSERT_EQ(unshare(CLONE_NEWPID), 0);
ASSERT_EQ(unshare(CLONE_NEWPID), 0) {
if (errno == EPERM)
SKIP(return, "CLONE_NEWPID requires CAP_SYS_ADMIN");
else if (errno == EINVAL)
SKIP(return, "CLONE_NEWPID is invalid (missing CONFIG_PID_NS?)");
}

pid2 = fork();
ASSERT_GE(pid2, 0);
Expand All @@ -3727,6 +3732,8 @@ TEST(user_notification_sibling_pid_ns)
ASSERT_EQ(unshare(CLONE_NEWPID), 0) {
if (errno == EPERM)
SKIP(return, "CLONE_NEWPID requires CAP_SYS_ADMIN");
else if (errno == EINVAL)
SKIP(return, "CLONE_NEWPID is invalid (missing CONFIG_PID_NS?)");
}
ASSERT_EQ(errno, 0);

Expand Down

0 comments on commit 612fbf6

Please sign in to comment.