Skip to contentSkip to conversation

Fix busybox SUID support

PATCH In review Tom Rini 10 participants 15 messages Feb 23, 2010 – Feb 26, 2010

lore
Share & tools
lore

Tom Rini

author
#0 lore raw

PATCH 1/1 Fix busybox SUID support

I was about to just push this and I noticed that a number of distributions (SlugOS, Angstrom, Kaelios, micro) currently set FEATURE_SUID=y, but it's not actually install SUID. And since I recall some way-back-when's of "busybox SUID is dangerous / crap!", I thought it best to post the patch first and let folks speak up / ask me to drop FEATURE_SUID=y when I do this. So, here's the patch:

recipes/busybox/busybox.inc +6 -2
index 5f52850..b165d0f 100644
@@ -11,7 +11,7 @@ LICENSE = "GPL"
 SECTION = "base"
 PRIORITY = "required"
 
-INC_PR = "r24"
+INC_PR = "r25"
 
 SRC_URI = "\
   file://busybox-cron \
@@ -96,7 +96,11 @@ do_install () {
 	# Install /bin/busybox, and the /bin/sh link so the postinst script
 	# can run. Let update-alternatives handle the rest.
 	install -d ${D}${base_bindir}
-	install -m 0755 ${S}/busybox ${D}${base_bindir}
+	if grep -q "CONFIG_FEATURE_SUID=y" ${WORKDIR}/defconfig; then
+		install -m 4755 ${S}/busybox ${D}${base_bindir}
+	else
+		install -m 0755 ${S}/busybox ${D}${base_bindir}
+	fi
 	ln -sf busybox ${D}${base_bindir}/sh
 
 	if grep -q "CONFIG_SYSLOGD=y" ${WORKDIR}/defconfig; then
Signature · 2 lines
Tom Rini <[email protected]>
Mentor Graphics Corporation
#1 lore raw
Quoted 21 lines · Tom Rini

I was about to just push this and I noticed that a number of distributions (SlugOS, Angstrom, Kaelios, micro) currently set FEATURE_SUID=y, but it's not actually install SUID.  And since I recall some way-back-when's of "busybox SUID is dangerous / crap!", I thought it best to post the patch first and let folks speak up / ask me to drop FEATURE_SUID=y when I do this.  So, here's the patch:

recipes/busybox/busybox.inc +0 -0
index 5f52850..b165d0f 100644
@@ -11,7 +11,7 @@ LICENSE = "GPL"

 SECTION = "base"
 PRIORITY = "required"

recipes/busybox/busybox.inc +1 -1
-INC_PR = "r24"
+INC_PR = "r25"

 SRC_URI = "\
  file://busybox-cron \

recipes/busybox/busybox.inc do_install () { · line 99

Quoted 5 lines
recipes/busybox/busybox.inc +1 -1
@@ -96,7 +96,11 @@ do_install () {
        # Install /bin/busybox, and the /bin/sh link so the postinst script
        # can run. Let update-alternatives handle the rest.
        install -d ${D}${base_bindir}
-       install -m 0755 ${S}/busybox ${D}${base_bindir}
+       if grep -q "CONFIG_FEATURE_SUID=y" ${WORKDIR}/defconfig; then

may be you should grep it in ${S}/.config because thats what defconfig turns into finally
and used by busybox build.

recipes/busybox/busybox.inc do_install () { · line 100

Quoted 1 line
recipes/busybox/busybox.inc +1 -0
+               install -m 4755 ${S}/busybox ${D}${base_bindir}

what does 4755 translate to ? (curiosity)

Quoted 17 lines
recipes/busybox/busybox.inc +3 -0
+       else
+               install -m 0755 ${S}/busybox ${D}${base_bindir}
+       fi

       ln -sf busybox ${D}${base_bindir}/sh

       if grep -q "CONFIG_SYSLOGD=y" ${WORKDIR}/defconfig; then

--
Tom Rini <[email protected]>
Mentor Graphics Corporation

_______________________________________________
Openembedded-devel mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-devel

author
#2 lore raw
Quoted 19 lines · Khem Raj
Quoted 18 lines · Tom Rini

I was about to just push this and I noticed that a number of distributions (SlugOS, Angstrom, Kaelios, micro) currently set FEATURE_SUID=y, but it's not actually install SUID. And since I recall some way-back-when's of "busybox SUID is dangerous / crap!", I thought it best to post the patch first and let folks speak up / ask me to drop FEATURE_SUID=y when I do this. So, here's the patch:

recipes/busybox/busybox.inc +1 -1
index 5f52850..b165d0f 100644
@@ -11,7 +11,7 @@ LICENSE = "GPL"
 SECTION = "base"
 PRIORITY = "required"
 
-INC_PR = "r24"
+INC_PR = "r25"
 
Quoted 12 lines

recipes/busybox/busybox.inc do_install () { · line 99

Quoted 8 lines
recipes/busybox/busybox.inc +1 -1
 SRC_URI = "\
  file://busybox-cron \
@@ -96,7 +96,11 @@ do_install () {
       # Install /bin/busybox, and the /bin/sh link so the postinst script
       # can run. Let update-alternatives handle the rest.
       install -d ${D}${base_bindir}
-       install -m 0755 ${S}/busybox ${D}${base_bindir}
+       if grep -q "CONFIG_FEATURE_SUID=y" ${WORKDIR}/defconfig; then

may be you should grep it in ${S}/.config because thats what defconfig turns into finally
and used by busybox build.

I'd be fine doing a follow-up to clean them all up, but today busybox.inc does all of its checks to ${WORKDIR}/defconfig.

Quoted 3 lines

recipes/busybox/busybox.inc do_install () { · line 100

Quoted 1 line
recipes/busybox/busybox.inc +1 -0
+               install -m 4755 ${S}/busybox ${D}${base_bindir}

what does 4755 translate to ? (curiosity)

4 is suid (2 is sgid, 1 is i forget the name but what you stick on /tmp & such).

Signature · 2 lines
Tom Rini <[email protected]>
Mentor Graphics Corporation
#3 lore raw
Quoted 37 lines · Tom Rini
Quoted 16 lines · Khem Raj
Quoted 15 lines · Tom Rini

I was about to just push this and I noticed that a number of distributions (SlugOS, Angstrom, Kaelios, micro) currently set FEATURE_SUID=y, but it's not actually install SUID. And since I recall some way-back-when's of "busybox SUID is dangerous / crap!", I thought it best to post the patch first and let folks speak up / ask me to drop FEATURE_SUID=y when I do this. So, here's the patch:

recipes/busybox/busybox.inc +0 -0
index 5f52850..b165d0f 100644
@@ -11,7 +11,7 @@ LICENSE = "GPL"
 SECTION = "base"
 PRIORITY = "required"
 
Quoted 7 lines

recipes/busybox/busybox.inc do_install () { · line 96

Quoted 7 lines
recipes/busybox/busybox.inc +1 -1
-INC_PR = "r24"
+INC_PR = "r25"
 
 SRC_URI = "\
  file://busybox-cron \
@@ -96,7 +96,11 @@ do_install () {
       # Install /bin/busybox, and the /bin/sh link so the postinst

script

Quoted 8 lines

recipes/busybox/busybox.inc do_install () { · line 99

Quoted 4 lines
recipes/busybox/busybox.inc +1 -1
       # can run. Let update-alternatives handle the rest.
       install -d ${D}${base_bindir}
-       install -m 0755 ${S}/busybox ${D}${base_bindir}
+       if grep -q "CONFIG_FEATURE_SUID=y" ${WORKDIR}/defconfig; then

may be you should grep it in ${S}/.config because thats what defconfig turns into finally
and used by busybox build.

I'd be fine doing a follow-up to clean them all up, but today busybox.inc does all of its checks to ${WORKDIR}/defconfig.

Quoted 6 lines
Quoted 3 lines

recipes/busybox/busybox.inc do_install () { · line 100

Quoted 1 line
recipes/busybox/busybox.inc +1 -0
+               install -m 4755 ${S}/busybox ${D}${base_bindir}

what does 4755 translate to ? (curiosity)

4 is suid (2 is sgid, 1 is i forget the name but what you stick on /tmp & such).

Sticky :)

Signature · 5 lines
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics
#4 lore raw
In reply to Tom Rini

recipes/busybox/busybox.inc do_install () { · line 103

Quoted 5 lines · Tom Rini
recipes/busybox/busybox.inc +5 -0
+	if grep -q "CONFIG_FEATURE_SUID=y" ${WORKDIR}/defconfig; then
+		install -m 4755 ${S}/busybox ${D}${base_bindir}
+	else
+		install -m 0755 ${S}/busybox ${D}${base_bindir}
+	fi

Looks good to me.

p.

author
#6 lore raw
Quoted 3 lines · Michael 'Mickey' Lauer

Ah, finally someone does something about it. Next step would be to dump tinylogin which is known broken and use busyboxes login utilities instead.

Not wanting to open that can of worms up just yet, yes, this will let distros opt in to that kind of thing (I hit this because of 'su' the other day..).

Signature · 2 lines
Tom Rini <[email protected]>
Mentor Graphics Corporation
Acked-by on v1 1/1
#7 lore raw
In reply to Tom Rini

Dnia wtorek, 23 lutego 2010 o 20:02:56 Tom Rini napisał(a):

Quoted 6 lines

I was about to just push this and I noticed that a number of distributions (SlugOS, Angstrom, Kaelios, micro) currently set FEATURE_SUID=y, but it's not actually install SUID. And since I recall some way-back-when's of "busybox SUID is dangerous / crap!", I thought it best to post the patch first and let folks speak up / ask me to drop FEATURE_SUID=y when I do this. So, here's the patch:

Ok, but does not it require /etc/something to list which applets are allowed to be suid and which are not?

Hm. checked sources. with FEATURE_SUID suid will be active only for "crontab, dnsd, findfs, ipcrm, ipcs, login, passwd, ping, su, traceroute, vlock" commands. /etc/busybox.conf is CONFIG_FEATURE_SUID_CONFIG option.

Regards,

Signature · 3 lines
JID:      [email protected]
Website:  http://marcin.juszkiewicz.com.pl/
LinkedIn: http://www.linkedin.com/in/marcinjuszkiewicz
author
#8 lore raw
Quoted 8 lines · Marcin Juszkiewicz

Dnia wtorek, 23 lutego 2010 o 20:02:56 Tom Rini napisał(a):

Quoted 6 lines

I was about to just push this and I noticed that a number of distributions (SlugOS, Angstrom, Kaelios, micro) currently set FEATURE_SUID=y, but it's not actually install SUID. And since I recall some way-back-when's of "busybox SUID is dangerous / crap!", I thought it best to post the patch first and let folks speak up / ask me to drop FEATURE_SUID=y when I do this. So, here's the patch:

Quoted 6 lines

Ok, but does not it require /etc/something to list which applets are allowed to be suid and which are not?

Hm. checked sources. with FEATURE_SUID suid will be active only for "crontab, dnsd, findfs, ipcrm, ipcs, login, passwd, ping, su, traceroute, vlock" commands. /etc/busybox.conf is CONFIG_FEATURE_SUID_CONFIG option.

To be clear, enabling one of those applets will force FEATURE_SUID to be set. FEATURE_SUID_CONFIG lets you configure who can run these SUID programs.

Signature · 2 lines
Tom Rini <[email protected]>
Mentor Graphics Corporation
#9 lore raw
In reply to Tom Rini
Quoted 6 lines · Tom Rini

I was about to just push this and I noticed that a number of distributions (SlugOS, Angstrom, Kaelios, micro) currently set FEATURE_SUID=y, but it's not actually install SUID. And since I recall some way-back-when's of "busybox SUID is dangerous / crap!", I thought it best to post the patch first and let folks speak up / ask me to drop FEATURE_SUID=y when I do this. So, here's the patch:

In the case of SlugOS, this was deliberate -- the thinking was that we would let the user decide if they wanted to run busybox SUID after installation. In retrospect, that actually led to more problems than good, so this change gets an ACK from me (albeit late - sorry for the delay!)

+1

-Mike

Acked-by
#10 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 8 lines · Mike Westerhof
Quoted 6 lines · Tom Rini

I was about to just push this and I noticed that a number of distributions (SlugOS, Angstrom, Kaelios, micro) currently set FEATURE_SUID=y, but it's not actually install SUID. And since I recall some way-back-when's of "busybox SUID is dangerous / crap!", I thought it best to post the patch first and let folks speak up / ask me to drop FEATURE_SUID=y when I do this. So, here's the patch:

Quoted 5 lines

In the case of SlugOS, this was deliberate -- the thinking was that we would let the user decide if they wanted to run busybox SUID after installation. In retrospect, that actually led to more problems than good, so this change gets an ACK from me (albeit late - sorry for the delay!)

The same logic was applied to angstrom "let users sort it out", but I think this patch is a better way to go.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)

iD8DBQFLiBDuMkyGM64RGpERAj1iAJ92l81A14+d1zbGez1GZ1B2wtsxRgCdE5oP sYCctrQ1jucxDfR0R4PMMf8=
=Bi6n
-----END PGP SIGNATURE-----

#11 lore raw
Quoted 12 lines · Koen Kooi

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 8 lines · Mike Westerhof
Quoted 6 lines · Tom Rini

I was about to just push this and I noticed that a number of distributions (SlugOS, Angstrom, Kaelios, micro) currently set FEATURE_SUID=y, but it's not actually install SUID. And since I recall some way-back-when's of "busybox SUID is dangerous / crap!", I thought it best to post the patch first and let folks speak up / ask me to drop FEATURE_SUID=y when I do this. So, here's the patch:

Quoted 10 lines
Quoted 5 lines

In the case of SlugOS, this was deliberate -- the thinking was that we would let the user decide if they wanted to run busybox SUID after installation. In retrospect, that actually led to more problems than good, so this change gets an ACK from me (albeit late - sorry for the delay!)

The same logic was applied to angstrom "let users sort it out", but I think this patch is a better way to go.

just to give you a heads up, we're currently working on a patch to busybox (and well have an OE recipe for it too) which will allow us to currently create two busybox executables: busybox-suid and busybox-nsuid. this way we can have the best of both worlds. maintain suid for programs that really require it while keeping the likes of ls and cat safe for the masses...

once its through our internal review, we'll send it out.

mike

#12 lore raw
Quoted 24 lines · C Michael Sundius
Quoted 12 lines · Koen Kooi

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 8 lines · Mike Westerhof
Quoted 6 lines · Tom Rini

I was about to just push this and I noticed that a number of distributions (SlugOS, Angstrom, Kaelios, micro) currently set FEATURE_SUID=y, but it's not actually install SUID. And since I recall some way-back-when's of "busybox SUID is dangerous / crap!", I thought it best to post the patch first and let folks speak up / ask me to drop FEATURE_SUID=y when I do this. So, here's the patch:

Quoted 10 lines
Quoted 5 lines

In the case of SlugOS, this was deliberate -- the thinking was that we would let the user decide if they wanted to run busybox SUID after installation. In retrospect, that actually led to more problems than good, so this change gets an ACK from me (albeit late - sorry for the delay!)

The same logic was applied to angstrom "let users sort it out", but I think this patch is a better way to go.

Quoted 5 lines

just to give you a heads up, we're currently working on a patch to busybox (and well have an OE recipe for it too) which will allow us to currently create two busybox executables: busybox-suid and busybox-nsuid. this way we can have the best of both worlds. maintain suid for programs that really require it while keeping the likes of ls and cat safe for the masses...

SUID_DROP applets do just that before the individual applet_main is called, i.e. drops privs. But whatever..
If you really think you want to build the thing twice then i'd try FEATURE_SHARED_BUSYBOX, fyi.

$ size 0_lib/{busybox,libbusybox.so.1.17.0.git}
   text	   data	    bss	    dec	    hex	filename
   1379	    520	     16	   1915	    77b	0_lib/busybox
 339569	   6705	   8552	 354826	  56a0a	0_lib/libbusybox.so.1.17.0.git

duplicating 2k is better than duplicating all the innocent rest, but maybe that's just me..

cheers,

Quoted 1 line

once its through our internal review, we'll send it out.

#13 lore raw
Quoted 11 lines · Bernhard Reutner-Fischer

SUID_DROP applets do just that before the individual applet_main is called, i.e. drops privs. But whatever..
If you really think you want to build the thing twice then i'd try FEATURE_SHARED_BUSYBOX, fyi.

$ size 0_lib/{busybox,libbusybox.so.1.17.0.git}
   text	   data	    bss	    dec	    hex	filename
   1379	    520	     16	   1915	    77b	0_lib/busybox
 339569	   6705	   8552	 354826	  56a0a	0_lib/libbusybox.so.1.17.0.git

duplicating 2k is better than duplicating all the innocent rest, but maybe that's just me..

Whether this is a good idea or not rather depends on what you're trying to protect against. The threat scenarios for a setuid busybox basically fall into two categories:

a) user invokes an applet which shouldn't be setuid, but busybox fails (for whatever reason) to drop its privs and allows the applet to run in root context

b) user invokes an applet which is intended to be setuid, busybox correctly retains the elevated privs while running it, but there is some bug or vulnerability in the code which causes unwanted results

If you're primarily worried about case (a) then building two copies of the frontend which share a common libbusybox, one setuid and one not, probably is a reasonable thing to do. However, as you say, busybox does already have a fairly robust mechanism in place for dropping privs when they are not wanted by a particular applet and hence the threat from this side seems to be quite low anyway.

If you are primarily worried about case (b) then the easiest way to mitigate the threat is to reduce the amount of code which is linked in to the setuid binary (either statically or dynamically) and hence the amount of code that you need to audit for security hazards. In that situation, linking with a shared libbusybox would not help, since you still have essentially the whole of busybox to worry about and you might as well just stick with a single large binary. Instead you would be better off making a minimal, standalone busybox binary which contained the bare minimum of code that was required to fulfil its setuid functions.

p.

#14 lore raw
Quoted 6 lines · Phil Blundell

If you're primarily worried about case (a) then building two copies of the frontend which share a common libbusybox, one setuid and one not, probably is a reasonable thing to do. However, as you say, busybox does already have a fairly robust mechanism in place for dropping privs when they are not wanted by a particular applet and hence the threat from this side seems to be quite low anyway.

Yes, and that's what i've read into Michaels mail that this was what he was primarily concerned about, but rereading him he didn't actually say that. My apologies.

Quoted 3 lines

If you are primarily worried about case (b) then the easiest way to mitigate the threat is to reduce the amount of code which is linked in

indeed