Skip to content

Commit 93bfcb7

Browse files
Terry TrittonMa Wupeng
authored andcommitted
selftests/seccomp: Handle EINVAL on unshare(CLONE_NEWPID)
stable inclusion from stable-v6.6.30 commit 612fbf658803dd19d49bcc66e7bbfdbe9b6981ff bugzilla: https://gitee.com/openeuler/kernel/issues/I9MPZ8 Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=612fbf658803dd19d49bcc66e7bbfdbe9b6981ff -------------------------------- commit ecaaa55c9fa5e8058445a8b891070b12208cdb6d 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> Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
1 parent 9bc0f52 commit 93bfcb7

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
@@ -3722,7 +3722,12 @@ TEST(user_notification_sibling_pid_ns)
37223722
ASSERT_GE(pid, 0);
37233723

37243724
if (pid == 0) {
3725-
ASSERT_EQ(unshare(CLONE_NEWPID), 0);
3725+
ASSERT_EQ(unshare(CLONE_NEWPID), 0) {
3726+
if (errno == EPERM)
3727+
SKIP(return, "CLONE_NEWPID requires CAP_SYS_ADMIN");
3728+
else if (errno == EINVAL)
3729+
SKIP(return, "CLONE_NEWPID is invalid (missing CONFIG_PID_NS?)");
3730+
}
37263731

37273732
pid2 = fork();
37283733
ASSERT_GE(pid2, 0);
@@ -3740,6 +3745,8 @@ TEST(user_notification_sibling_pid_ns)
37403745
ASSERT_EQ(unshare(CLONE_NEWPID), 0) {
37413746
if (errno == EPERM)
37423747
SKIP(return, "CLONE_NEWPID requires CAP_SYS_ADMIN");
3748+
else if (errno == EINVAL)
3749+
SKIP(return, "CLONE_NEWPID is invalid (missing CONFIG_PID_NS?)");
37433750
}
37443751
ASSERT_EQ(errno, 0);
37453752

0 commit comments

Comments
 (0)