public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Mike Frysinger" <vapier@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/sandbox:master commit in: libsandbox/wrapper-funcs/
Date: Mon, 24 Dec 2012 08:02:38 +0000 (UTC)	[thread overview]
Message-ID: <1356336096.26ad6af1a4f246bda3cd7a19a24c1767ec9c835e.vapier@gentoo> (raw)

commit:     26ad6af1a4f246bda3cd7a19a24c1767ec9c835e
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Mon Dec  3 06:15:15 2012 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Mon Dec 24 08:01:36 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/sandbox.git;a=commit;h=26ad6af1

libsandbox: fall back to tracing set*id programs

If we are non-root and run a set*id program, the ldso will ignore our
LD_PRELOAD (rightly so).  Unfortunately, this opens up the ability to
run set*id apps that modify things and sandbox cannot catch it.

Instead, force ptracing of these ELFs.  While the kernel will disallow
the set*id aspect when running, for the most part, that shouldn't be a
problem if it was already safe.

URL: http://bugs.gentoo.org/442172
Reported-by: Nikoli <nikoli <AT> lavabit.com>
Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>

---
 libsandbox/wrapper-funcs/__wrapper_exec.c |   23 ++++++++++++++++++-----
 1 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/libsandbox/wrapper-funcs/__wrapper_exec.c b/libsandbox/wrapper-funcs/__wrapper_exec.c
index 0ffc08a..b7c7dfa 100644
--- a/libsandbox/wrapper-funcs/__wrapper_exec.c
+++ b/libsandbox/wrapper-funcs/__wrapper_exec.c
@@ -31,7 +31,7 @@ static void sb_check_exec(const char *filename, char *const argv[])
 	fd = open(filename, O_RDONLY|O_CLOEXEC);
 	if (fd == -1)
 		return;
-	if (stat(filename, &st))
+	if (fstat(fd, &st))
 		goto out_fd;
 	if (st.st_size < sizeof(Elf64_Ehdr))
 		goto out_fd;
@@ -47,6 +47,17 @@ static void sb_check_exec(const char *filename, char *const argv[])
 	      elf[EI_CLASS] != ELFCLASS64))
 		goto out_mmap;
 
+	/* If we are non-root but attempt to execute a set*id program,
+	 * our LD_PRELOAD trick won't work.  So skip the static check.
+	 * This might break some apps, but it shouldn't, and is better
+	 * than doing nothing since it might mean `mount` or `umount`
+	 * won't get caught if/when they modify things. #442172
+	 *
+	 * Only other option is to code a set*id sandbox helper that
+	 * gains root just to preload libsandbox.so.  That unfortunately
+	 * could easily open up people to root vulns.
+	 */
+	if (getuid() == 0 || !(st.st_mode & (S_ISUID | S_ISGID))) {
 #define PARSE_ELF(n) \
 ({ \
 	Elf##n##_Ehdr *ehdr = (void *)elf; \
@@ -60,10 +71,12 @@ static void sb_check_exec(const char *filename, char *const argv[])
 		if (phdr[p].p_type == PT_INTERP) \
 			goto done; \
 })
-	if (elf[EI_CLASS] == ELFCLASS32)
-		PARSE_ELF(32);
-	else
-		PARSE_ELF(64);
+		if (elf[EI_CLASS] == ELFCLASS32)
+			PARSE_ELF(32);
+		else
+			PARSE_ELF(64);
+#undef PARSE_ELF
+	}
 
 	do_trace = trace_possible(filename, argv, elf);
 	/* Now that we're done with stuff, clean up before forking */


             reply	other threads:[~2012-12-24  8:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-24  8:02 Mike Frysinger [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-02-22 19:49 [gentoo-commits] proj/sandbox:master commit in: libsandbox/wrapper-funcs/ Mike Gilbert
2024-12-22  3:49 [gentoo-commits] proj/sandbox:stable-2.x " Mike Gilbert
2025-01-14  4:38 ` [gentoo-commits] proj/sandbox:master " Mike Gilbert
2024-12-22  3:41 Mike Gilbert
2021-10-18  5:21 Mike Frysinger
2019-03-09 19:21 Sergei Trofimovich
2016-11-16 22:19 Mike Frysinger
2016-03-30  5:16 Mike Frysinger
2013-02-25  4:03 Mike Frysinger
2012-06-24  0:06 Mike Frysinger

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=1356336096.26ad6af1a4f246bda3cd7a19a24c1767ec9c835e.vapier@gentoo \
    --to=vapier@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /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