Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/seccomp: Handle EINVAL on unshare(CLONE_NEWPID)

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>

authored by

Terry Tritton and committed by
Kees Cook
ecaaa55c 41bccc98

+8 -1
+8 -1
tools/testing/selftests/seccomp/seccomp_bpf.c
··· 3709 3709 ASSERT_GE(pid, 0); 3710 3710 3711 3711 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 + } 3713 3718 3714 3719 pid2 = fork(); 3715 3720 ASSERT_GE(pid2, 0); ··· 3732 3727 ASSERT_EQ(unshare(CLONE_NEWPID), 0) { 3733 3728 if (errno == EPERM) 3734 3729 SKIP(return, "CLONE_NEWPID requires CAP_SYS_ADMIN"); 3730 + else if (errno == EINVAL) 3731 + SKIP(return, "CLONE_NEWPID is invalid (missing CONFIG_PID_NS?)"); 3735 3732 } 3736 3733 ASSERT_EQ(errno, 0); 3737 3734