Gentoo Archives: gentoo-commits

From: Mike Frysinger <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/sandbox:master commit in: libsandbox/
Date: Wed, 03 Nov 2021 16:40:34
Message-Id: 1635957294.01318f0d48654425b4ea3a90520a52f774b60ead.vapier@gentoo
1 commit: 01318f0d48654425b4ea3a90520a52f774b60ead
2 Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
3 AuthorDate: Wed Nov 3 16:34:54 2021 +0000
4 Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
5 CommitDate: Wed Nov 3 16:34:54 2021 +0000
6 URL: https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=01318f0d
7
8 libsandbox: refine yama check to abort on level 3+
9
10 There's no way we can support level 3+ since the kernel blocks it,
11 so give up and inform the user their setup is incompatible.
12
13 Bug: https://bugs.gentoo.org/771360
14 Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>
15
16 libsandbox/trace.c | 30 +++++++++++++++++++++---------
17 1 file changed, 21 insertions(+), 9 deletions(-)
18
19 diff --git a/libsandbox/trace.c b/libsandbox/trace.c
20 index d2899b7..036d57f 100644
21 --- a/libsandbox/trace.c
22 +++ b/libsandbox/trace.c
23 @@ -49,13 +49,7 @@ pid_t trace_pid;
24 static int trace_yama_level(void)
25 {
26 char ch;
27 - int fd;
28 -
29 - /* ptrace scope binds access to specific capabilities. Lets use uid==0 as a
30 - * lazy proxy for "we have all capabilities" until we can refine this.
31 - */
32 - if (getuid() == 0)
33 - return 0;
34 + int fd, level;
35
36 fd = open("/proc/sys/kernel/yama/ptrace_scope", O_RDONLY | O_CLOEXEC);
37 if (fd == -1)
38 @@ -63,7 +57,25 @@ static int trace_yama_level(void)
39
40 RETRY_EINTR(read(fd, &ch, 1));
41 close(fd);
42 - return ch - '0';
43 + level = ch - '0';
44 +
45 + switch (level) {
46 + case 0:
47 + /* Normal levels work fine. */
48 + return 0;
49 +
50 + case 1:
51 + case 2:
52 + /* ptrace scope binds access to specific capabilities. Lets use uid==0 as a
53 + * lazy proxy for "we have all capabilities" until we can refine this.
54 + */
55 + return getuid() == 0 ? 0 : level;
56 +
57 + case 3:
58 + default:
59 + /* Level 3+ is not supported. */
60 + sb_ebort("YAMA ptrace_scope=%i+ is not supported as it makes tracing impossible.\n", level);
61 + }
62 }
63
64 static void trace_exit(int status)
65 @@ -709,7 +721,7 @@ bool trace_possible(const char *filename, char *const argv[], const void *data)
66 /* If YAMA ptrace_scope is very high, then we can't trace at all. #771360 */
67 int yama = trace_yama_level();
68 if (yama >= 2) {
69 - sb_eqawarn("YAMA ptrace_scope=%i\n", yama);
70 + sb_eqawarn("YAMA ptrace_scope=%i is not currently supported\n", yama);
71 goto fail;
72 }