Skip to content

Commit 8feae5a

Browse files
avaginkees
authored andcommitted
selftest/seccomp: add a new test for the sync mode of seccomp_user_notify
Test output: # RUN global.user_notification_sync ... # OK global.user_notification_sync ok 51 global.user_notification_sync Signed-off-by: Andrei Vagin <[email protected]> Acked-by: "Peter Zijlstra (Intel)" <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 48a1084 commit 8feae5a

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tools/testing/selftests/seccomp/seccomp_bpf.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4255,6 +4255,61 @@ TEST(user_notification_addfd_rlimit)
42554255
close(memfd);
42564256
}
42574257

4258+
#ifndef SECCOMP_USER_NOTIF_FD_SYNC_WAKE_UP
4259+
#define SECCOMP_USER_NOTIF_FD_SYNC_WAKE_UP (1UL << 0)
4260+
#define SECCOMP_IOCTL_NOTIF_SET_FLAGS SECCOMP_IOW(4, __u64)
4261+
#endif
4262+
4263+
TEST(user_notification_sync)
4264+
{
4265+
struct seccomp_notif req = {};
4266+
struct seccomp_notif_resp resp = {};
4267+
int status, listener;
4268+
pid_t pid;
4269+
long ret;
4270+
4271+
ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
4272+
ASSERT_EQ(0, ret) {
4273+
TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!");
4274+
}
4275+
4276+
listener = user_notif_syscall(__NR_getppid,
4277+
SECCOMP_FILTER_FLAG_NEW_LISTENER);
4278+
ASSERT_GE(listener, 0);
4279+
4280+
/* Try to set invalid flags. */
4281+
EXPECT_SYSCALL_RETURN(-EINVAL,
4282+
ioctl(listener, SECCOMP_IOCTL_NOTIF_SET_FLAGS, 0xffffffff, 0));
4283+
4284+
ASSERT_EQ(ioctl(listener, SECCOMP_IOCTL_NOTIF_SET_FLAGS,
4285+
SECCOMP_USER_NOTIF_FD_SYNC_WAKE_UP, 0), 0);
4286+
4287+
pid = fork();
4288+
ASSERT_GE(pid, 0);
4289+
if (pid == 0) {
4290+
ret = syscall(__NR_getppid);
4291+
ASSERT_EQ(ret, USER_NOTIF_MAGIC) {
4292+
_exit(1);
4293+
}
4294+
_exit(0);
4295+
}
4296+
4297+
req.pid = 0;
4298+
ASSERT_EQ(ioctl(listener, SECCOMP_IOCTL_NOTIF_RECV, &req), 0);
4299+
4300+
ASSERT_EQ(req.data.nr, __NR_getppid);
4301+
4302+
resp.id = req.id;
4303+
resp.error = 0;
4304+
resp.val = USER_NOTIF_MAGIC;
4305+
resp.flags = 0;
4306+
ASSERT_EQ(ioctl(listener, SECCOMP_IOCTL_NOTIF_SEND, &resp), 0);
4307+
4308+
ASSERT_EQ(waitpid(pid, &status, 0), pid);
4309+
ASSERT_EQ(status, 0);
4310+
}
4311+
4312+
42584313
/* Make sure PTRACE_O_SUSPEND_SECCOMP requires CAP_SYS_ADMIN. */
42594314
FIXTURE(O_SUSPEND_SECCOMP) {
42604315
pid_t pid;

0 commit comments

Comments
 (0)