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

selftests/seccomp: Catch garbage on SECCOMP_IOCTL_NOTIF_RECV

This adds logic to the user_notification_basic test to set a member
of struct seccomp_notif to an invalid value to ensure that the kernel
returns EINVAL if any of the struct seccomp_notif members are set to
invalid values.

Signed-off-by: Sargun Dhillon <sargun@sargun.me>
Suggested-by: Christian Brauner <christian.brauner@ubuntu.com>
Link: https://lore.kernel.org/r/20191230203811.4996-1-sargun@sargun.me
Fixes: 6a21cc50f0c7 ("seccomp: add a return code to trap to userspace")
Cc: stable@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>

authored by

Sargun Dhillon and committed by
Kees Cook
e4ab5ccc 2882d53c

+12 -1
+12 -1
tools/testing/selftests/seccomp/seccomp_bpf.c
··· 3158 3158 EXPECT_GT(poll(&pollfd, 1, -1), 0); 3159 3159 EXPECT_EQ(pollfd.revents, POLLIN); 3160 3160 3161 - EXPECT_EQ(ioctl(listener, SECCOMP_IOCTL_NOTIF_RECV, &req), 0); 3161 + /* Test that we can't pass garbage to the kernel. */ 3162 + memset(&req, 0, sizeof(req)); 3163 + req.pid = -1; 3164 + errno = 0; 3165 + ret = ioctl(listener, SECCOMP_IOCTL_NOTIF_RECV, &req); 3166 + EXPECT_EQ(-1, ret); 3167 + EXPECT_EQ(EINVAL, errno); 3168 + 3169 + if (ret) { 3170 + req.pid = 0; 3171 + EXPECT_EQ(ioctl(listener, SECCOMP_IOCTL_NOTIF_RECV, &req), 0); 3172 + } 3162 3173 3163 3174 pollfd.fd = listener; 3164 3175 pollfd.events = POLLIN | POLLOUT;