From: Sargun Dhillon <sargun@sargun.me>
To: linux-kernel@vger.kernel.org,
containers@lists.linux-foundation.org, linux-api@vger.kernel.org
Cc: Sargun Dhillon <sargun@sargun.me>,
christian.brauner@ubuntu.com, tycho@tycho.ws,
keescook@chromium.org, cyphar@cyphar.com
Subject: [PATCH] seccomp: Add group_leader pid to seccomp_notif
Date: Fri, 15 May 2020 16:40:05 -0700 [thread overview]
Message-ID: <20200515234005.32370-1-sargun@sargun.me> (raw)
This includes the thread group leader ID in the seccomp_notif. This is
immediately useful for opening up a pidfd for the group leader, as
pidfds only work on group leaders.
Previously, it was considered to include an actual pidfd in the
seccomp_notif structure[1], but it was suggested to avoid proliferating
mechanisms to create pidfds[2].
[1]: https://lkml.org/lkml/2020/1/24/133
[2]: https://lkml.org/lkml/2020/5/15/481
Suggested-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Sargun Dhillon <sargun@sargun.me>
---
include/uapi/linux/seccomp.h | 2 +
kernel/seccomp.c | 1 +
tools/testing/selftests/seccomp/seccomp_bpf.c | 50 +++++++++++++++++++
3 files changed, 53 insertions(+)
diff --git a/include/uapi/linux/seccomp.h b/include/uapi/linux/seccomp.h
index c1735455bc53..f0c272ef0f1e 100644
--- a/include/uapi/linux/seccomp.h
+++ b/include/uapi/linux/seccomp.h
@@ -75,6 +75,8 @@ struct seccomp_notif {
__u32 pid;
__u32 flags;
struct seccomp_data data;
+ __u32 tgid;
+ __u8 pad0[4];
};
/*
diff --git a/kernel/seccomp.c b/kernel/seccomp.c
index 55a6184f5990..538bcbbcf4da 100644
--- a/kernel/seccomp.c
+++ b/kernel/seccomp.c
@@ -1061,6 +1061,7 @@ static long seccomp_notify_recv(struct seccomp_filter *filter,
unotif.id = knotif->id;
unotif.pid = task_pid_vnr(knotif->task);
+ unotif.tgid = task_tgid_vnr(knotif->task);
unotif.data = *(knotif->data);
knotif->state = SECCOMP_NOTIFY_SENT;
diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c
index c0aa46ce14f6..5658c6e95461 100644
--- a/tools/testing/selftests/seccomp/seccomp_bpf.c
+++ b/tools/testing/selftests/seccomp/seccomp_bpf.c
@@ -187,6 +187,8 @@ struct seccomp_notif {
__u32 pid;
__u32 flags;
struct seccomp_data data;
+ __u32 tgid;
+ __u8 pad0[4];
};
struct seccomp_notif_resp {
@@ -3226,6 +3228,8 @@ TEST(user_notification_basic)
req.pid = 0;
EXPECT_EQ(ioctl(listener, SECCOMP_IOCTL_NOTIF_RECV, &req), 0);
}
+ EXPECT_EQ(pid, req.pid);
+ EXPECT_EQ(pid, req.tgid);
pollfd.fd = listener;
pollfd.events = POLLIN | POLLOUT;
@@ -3453,6 +3457,7 @@ TEST(user_notification_child_pid_ns)
EXPECT_EQ(ioctl(listener, SECCOMP_IOCTL_NOTIF_RECV, &req), 0);
EXPECT_EQ(req.pid, pid);
+ EXPECT_EQ(req.tgid, pid);
resp.id = req.id;
resp.error = 0;
@@ -3686,6 +3691,51 @@ TEST(user_notification_continue)
}
}
+void *getppid_thread(void *arg)
+{
+ int *tid = arg;
+
+ *tid = syscall(__NR_gettid);
+ if (*tid <= 0)
+ return (void *)(long)errno;
+ return NULL;
+}
+
+TEST(user_notification_groupleader)
+{
+ struct seccomp_notif_resp resp = {};
+ struct seccomp_notif req = {};
+ int ret, listener, tid, pid;
+ pthread_t thread;
+ void *status;
+
+ pid = getpid();
+ ASSERT_GT(pid, 0);
+
+ ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
+ ASSERT_EQ(0, ret) {
+ TH_LOG("Kernel does not support PR_SET_NO_NEW_PRIVS!");
+ }
+
+ listener = user_trap_syscall(__NR_gettid,
+ SECCOMP_FILTER_FLAG_NEW_LISTENER);
+ ASSERT_GE(listener, 0);
+
+ ASSERT_EQ(0, pthread_create(&thread, NULL, getppid_thread, &tid));
+
+ ASSERT_EQ(ioctl(listener, SECCOMP_IOCTL_NOTIF_RECV, &req), 0);
+ resp.id = req.id;
+ resp.flags = SECCOMP_USER_NOTIF_FLAG_CONTINUE;
+ ASSERT_EQ(ioctl(listener, SECCOMP_IOCTL_NOTIF_SEND, &resp), 0);
+
+ ASSERT_EQ(0, pthread_join(thread, &status));
+ ASSERT_EQ(0, status);
+
+ EXPECT_EQ(tid, req.pid);
+ EXPECT_EQ(pid, req.tgid);
+}
+
+
/*
* TODO:
* - add microbenchmarks
--
2.20.1
next reply other threads:[~2020-05-15 23:40 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-15 23:40 Sargun Dhillon [this message]
2020-05-17 7:17 ` [PATCH] seccomp: Add group_leader pid to seccomp_notif Kees Cook
2020-05-17 10:47 ` Christian Brauner
2020-05-17 11:21 ` Aleksa Sarai
2020-05-17 14:23 ` Tycho Andersen
2020-05-17 14:33 ` Christian Brauner
2020-05-17 14:35 ` Christian Brauner
2020-05-17 14:46 ` Tycho Andersen
2020-05-17 15:02 ` Tycho Andersen
2020-05-17 21:30 ` Kees Cook
2020-05-18 8:32 ` Sargun Dhillon
2020-05-18 12:45 ` Christian Brauner
2020-05-18 13:23 ` Tycho Andersen
2020-05-18 14:00 ` Christian Brauner
2020-05-18 12:05 ` Christian Brauner
2020-05-18 21:10 ` Kees Cook
2020-05-18 12:53 ` Christian Brauner
2020-05-18 13:20 ` Tycho Andersen
2020-05-18 21:37 ` Sargun Dhillon
2020-05-17 11:17 ` Sargun Dhillon
2020-05-18 23:08 ` Eric W. Biederman
2020-05-22 17:54 ` Sargun Dhillon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200515234005.32370-1-sargun@sargun.me \
--to=sargun@sargun.me \
--cc=christian.brauner@ubuntu.com \
--cc=containers@lists.linux-foundation.org \
--cc=cyphar@cyphar.com \
--cc=keescook@chromium.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tycho@tycho.ws \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).