Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 70838 - app-admin/sudo exported bash functions carried through sudo
Summary: app-admin/sudo exported bash functions carried through sudo
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Security
Classification: Unclassified
Component: Vulnerabilities (show other bugs)
Hardware: All All
: High major (vote)
Assignee: Gentoo Security
URL: http://www.courtesan.com/bugzilla/sho...
Whiteboard: B1 [noglsa] jaervosz
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-11 12:19 UTC by Sune Kloppenborg Jeppesen (RETIRED)
Modified: 2009-07-13 22:34 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2004-11-11 12:19:29 UTC
Here's an interesting bug in app-admin/sudo, that I discovered in the
course of testing StrongBox (a security oriented gentoo-based distro). I
posted it upstream, where there's now a patch available. In brief, any
bash script that is run from sudo is vulnerable to having bash functions
implanted by the original user, resulting in local privilege escalation.

http://www.courtesan.com/bugzilla/show_bug.cgi?id=157

The patch listed in the bug report above has been tested with gentoo on
x86/i686/kernel 2.6.8.1 with the latest stable glibc, etc, and appears
to work fine.

I think that someone should probably find out if there's any other
shells that export functions through the environment; I definitely
haven't had time to go through systematically and find out.

Anyways, keep me posted if you find out anything more.
Comment 1 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2004-11-11 12:24:23 UTC
Sorry above was reported by: Liam Helmer <lhelmer@strongboxlinux.com> 

This one is no herd, so grabbing devs from ChangeLog. Please provide a fixed ebuild.
Comment 2 Tavis Ormandy (RETIRED) gentoo-dev 2004-11-11 12:50:07 UTC
i dont think this is a security bug, i think it was fixed upstream because it could confuse users (exported functions in your current shell affecting your sudo comands), after all, you could just make a script called ifconfig and put it in your $PATH before /sbin/ifconfig.

The fix is obviously to use absolute paths, eg /sbin/ifconfig in your scripts.

Could we get some clarification that this _is_ a security bug?
Comment 3 solar (RETIRED) gentoo-dev 2004-11-11 12:51:26 UTC
I have a local ebuild with the existing patch already and am testing.
However the patch may be a little incomplete as it sits right now and perhaps should scrub the entire env. Hopefully Todd C Miller will provide an update here http://www.courtesan.com/bugzilla/show_bug.cgi?id=157
Comment 4 Kurt Lieber (RETIRED) gentoo-dev 2004-11-11 12:53:04 UTC
It's a security bug.  Look at the courtesan.com bug detail -- it explains exactly how to exploit it.

ping me on IRC if you want to discuss it further.  happy to walk through the exploit to explain it more.
Comment 5 solar (RETIRED) gentoo-dev 2004-11-11 13:06:34 UTC
Sorry about that tavis did not mean to yank you out of the CC: loop. 
See comment #4 from Kurt to you.
Comment 6 Tavis Ormandy (RETIRED) gentoo-dev 2004-11-11 13:08:07 UTC
Uhh, thanks Kurt, but if this is a bug, then so is the $PATH exploit I described above.

the patch is a convenience fix, you can stop the $PATH "exploit" by using env_reset, but stripping all the names of commands using env_delete would be tedious. 

I'm not convinced this is a security bug.

If you want me to demonstrate my exploit:

from sudoers:
%wheel  ALL=(ALL)   NOPASSWD: /tmp/script

/tmp/script:

#!/bin/bash
uptime
$ sudo /tmp/script 
 21:06:43 up  4:47,  3 users,  load average: 0.27, 0.13, 0.12
taviso@insomniac:~$ printf "%s\n$s" '#!/bin/bash' 'cat /etc/shadow' > uptime
taviso@insomniac:~$ chmod 755 uptime 
taviso@insomniac:~$ PATH=.:$PATH sudo /tmp/script 
root:xxxxxxxxxxxxxxx
...



Comment 7 Tavis Ormandy (RETIRED) gentoo-dev 2004-11-11 13:09:39 UTC
sorry, just to clarify: adding env_delete ifconfig to sudoers would his exploit working, just as adding env_reset to sudoers would stop mine.
Comment 8 solar (RETIRED) gentoo-dev 2004-11-11 14:55:03 UTC
Tavis Ormandy discussed this bug in great detail. The finial solution for gentoo will be to add this patch for good house keeping and enable by default env_reset to mitigate the problems with PATH and any other unknowns with env handling.

For those wishing to work around this problem now simply adding
Defaults        env_reset
# Solves the problem at hand.
Additionaly if you find you need a group/user which needs to not have his env flushed then you can add something like this to your conf as well.
Defaults:%wheel !env_reset

Tavis Ormandy will be patching sudo and making any conf changes.
Comment 9 solar (RETIRED) gentoo-dev 2004-11-11 14:56:07 UTC
^^^ Tavis Ormandy and myself discussed this bug in great detail.
Comment 10 Tavis Ormandy (RETIRED) gentoo-dev 2004-11-11 15:35:57 UTC
Okay, I've committed an ebuild that sets env_reset to the default sudoers file, this setting effectively stops this issue, although the reason it isn't defined by default is that some scripts rely on this behaviour (being able to export variables to the sudo session), there are comments in the file explaining how to enable the old behaviour.

Sudo access really is for trusted users, giving sudo access to users who are going to abuse it is tantamount to mailing them the root pass :)

I've applied the patch from the bug, although this is really just a convenience patch, not a security patch. without env_reset there are many other ways you could get root through the environment, IFS,PATH,etc,etc.

The ebuild is ~*, do the security team feel it needs to go live asap, or are you okay for this to get some testing in ~x86 to see if there are any complaints about it?
Comment 11 solar (RETIRED) gentoo-dev 2004-11-11 15:54:10 UTC
I think leaving it ~arch would be ideal for testing. If there are any scripts that rely on this new 'old' behavior they will have atleast have a chance to manifest themselves.
It's my understanding also that a 1.6.8p2 should be released tomorrow.
Comment 12 Florian Schilhabel (RETIRED) gentoo-dev 2004-11-11 23:24:28 UTC
hi,
much of this reminds me of a similar thing, i discovered a few days ago...
look:
sudoers:
%wheel        ALL=(ALL)       NOPASSWD:/sbin/modprobe

in this case, an administrator allows users to use the modprobe command...
(which is a bad idea anyways, but who knows...)
now:
as user do the following:
$ sudo /sbin/modprobe -c -C /etc/shadow > test

... and you'll be very surprised...

i dont think however, that this is a security bug... (comments?)

just in case, i can a open a bug for it, if you want

best regards

florian
Comment 13 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2004-11-12 04:11:47 UTC
Arches please test and report back on failure and success for sudo-1.6.8_p1-r2. Do NOT mark stable yet.

Solar just pointed out that this also works if you use the absolute paths.
Comment 14 solar (RETIRED) gentoo-dev 2004-11-12 04:18:31 UTC
Re comment #12 Agreed.
This appears configuration error only.

Comment 15 Gustavo Zacarias (RETIRED) gentoo-dev 2004-11-12 05:04:57 UTC
Looks Ok for sparc.
Comment 16 solar (RETIRED) gentoo-dev 2004-11-12 05:17:16 UTC
Note to those arch testing. don't forget to make sure the env_reset makes it into your /etc/sudoers file. If you ever installed sudo before your going to end up with the default suoders file. so etc-update and all that jazz.
Comment 17 Gustavo Zacarias (RETIRED) gentoo-dev 2004-11-12 05:27:21 UTC
On the other hand, having a restricted sudoers (no su - for instace) this fails:

gustavoz@ayanami gustavoz $ sudo su -

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

Password:
Segmentation fault
Comment 18 Tavis Ormandy (RETIRED) gentoo-dev 2004-11-12 05:42:53 UTC
Gustavo: you mean like this?: %wheel ALL=(ALL) NOPASSWD: ALL, !/bin/su

if so, perhaps this is an unrelated bug on sparc?

Re comment #13, there are a million ways to get around it, giving away sudo access to non-trusted users is asking for trouble.
Comment 19 Gustavo Zacarias (RETIRED) gentoo-dev 2004-11-12 05:48:45 UTC
Actually i have almost the same sudoers as taviso has:

Defaults        env_reset
%wheel          ALL=(ALL) NOPASSWD:/tmp/script
Comment 20 Aron Griffis (RETIRED) gentoo-dev 2004-11-12 13:00:17 UTC
I've tested sudo-1.6.8_p1-r2.ebuild on alpha, amd64 and ia64.  It works fine on all of them, including env_reset.
Comment 21 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2004-11-12 15:35:53 UTC
Issue is now fixed upstream and described here:

http://www.sudo.ws/sudo/alerts/bash_functions.html
Comment 22 Jochen Maes (RETIRED) gentoo-dev 2004-11-13 08:45:30 UTC
env_reset seems to work as does sudo on ppc.
Comment 23 Markus Rothe (RETIRED) gentoo-dev 2004-11-13 12:14:54 UTC
that version of sudo and env_reset seem to work on ppc64.  Markus
Comment 24 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2004-11-15 10:59:57 UTC
Tavis any ETA for a push to stable?
Comment 25 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2004-11-16 23:31:38 UTC
Solar, Tavis seems to be away. Do you have any ETA for a push to stable?
Comment 26 Tavis Ormandy (RETIRED) gentoo-dev 2004-11-17 01:36:44 UTC
app-admin/sudo-1.6.7_p5-r2 has been marked stable on x86
Comment 27 Thierry Carrez (RETIRED) gentoo-dev 2004-11-17 02:18:36 UTC
Arches, please mark app-admin/sudo-1.6.7_p5-r2 stable
Comment 28 Bryan Østergaard (RETIRED) gentoo-dev 2004-11-17 02:56:27 UTC
Stable on alpha.
Comment 29 Jochen Maes (RETIRED) gentoo-dev 2004-11-17 03:19:34 UTC
stable on ppc
Comment 30 Simon Stelling (RETIRED) gentoo-dev 2004-11-17 04:21:09 UTC
stable on amd64
Comment 31 Gustavo Zacarias (RETIRED) gentoo-dev 2004-11-17 04:54:03 UTC
sparc stable.
Comment 32 Markus Rothe (RETIRED) gentoo-dev 2004-11-17 07:02:26 UTC
stable on ppc64
Comment 33 Hardave Riar (RETIRED) gentoo-dev 2004-11-17 07:59:29 UTC
Stable on mips
Comment 34 Thierry Carrez (RETIRED) gentoo-dev 2004-11-19 01:52:05 UTC
Ready for a GLSA but blocked waiting for other vulnerabilities to come in
Comment 35 solar (RETIRED) gentoo-dev 2004-11-19 05:23:05 UTC
"
Candidate: CAN-2004-1051
URL: http://cve.mitre.org/cgi-bin/cvename.cgi?name=CAN-2004-1051
Reference: CONFIRM:http://www.sudo.ws/sudo/alerts/bash_functions.html
Reference: BUGTRAQ:20041112 Sudo version 1.6.8p2 now available (fwd)
Reference: URL:http://marc.theaimsgroup.com/?l=bugtraq&m=110028877431192&w=2

sudo before 1.6.8p2 allows local users to execute arbitrary commands
by using "()" style environment variables to create functions that are
executed instead of any program within the bash script that do not
have full pathnames
"
Comment 36 Thierry Carrez (RETIRED) gentoo-dev 2004-11-23 01:46:45 UTC
Debian apparently chose not to issue an advisory on this one.

From Martin Schulze :

"I'd consider this problem a non-issue or a design glitch and it seems
that it will only be a problem if the admin isn't careful with giving
access to various users."

I think we shouldn't issue a GLSA about it as well. I would rather add a few comments to the sudoers file warning about the risks associated with sudo : use full pathnames, if using bash scripts you should env_reset, and do not give access to untrusted people / untrusted applications.
Comment 37 Guy Martin (RETIRED) gentoo-dev 2004-11-23 05:15:59 UTC
Stable on hppa.
Comment 38 Thierry Carrez (RETIRED) gentoo-dev 2004-11-23 05:44:52 UTC
Does everyone agree that we shouldn't send a GLSA on this one ?

About the sudo general "insecurity" and documentation need, it's taken care of in bug 71750.
Comment 39 Matthias Geerdsen (RETIRED) gentoo-dev 2004-11-23 08:49:34 UTC
agreed, koon

Warnings in sudoers sounds like a good idea.
Comment 40 Sune Kloppenborg Jeppesen (RETIRED) gentoo-dev 2004-11-24 04:55:01 UTC
Debian just released an advisory:

http://www.debian.org/security/2004/dsa-596
Comment 41 Tavis Ormandy (RETIRED) gentoo-dev 2004-11-25 02:26:03 UTC
oopa, accidentally posted to wrong bug, this was meant to go here:

http://bugs.gentoo.org/show_bug.cgi?id=71750#c14
Comment 42 Thierry Carrez (RETIRED) gentoo-dev 2004-11-29 07:57:32 UTC
Two "NO" votes, closing without GLSA.

The warning thing will be handled on bug 71750.
Anyone that disagrees should reopen this bug.