pam_motd runs commands as root with unsanitised environment
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
pam (Ubuntu) |
Fix Released
|
Low
|
Dustin Kirkland | ||
Lucid |
Fix Released
|
Low
|
Dustin Kirkland | ||
Maverick |
Won't Fix
|
Low
|
Dustin Kirkland | ||
Natty |
Won't Fix
|
Low
|
Dustin Kirkland | ||
Oneiric |
Fix Released
|
Low
|
Dustin Kirkland | ||
Precise |
Fix Released
|
Low
|
Dustin Kirkland |
Bug Description
ii libpam-modules 1.1.1-2ubuntu5 Pluggable Authentication Modules for PAM
(lucid amd64)
pam_motd calls the scripts in /etc/update-motd.d/ as root without sanitising the environment. While that is acceptable when called for instance by sshd or by getty through login where the environment should be controlled, it becomes an issue if for instance "session optional pam_motd.so" is added to /etc/pam.d/su
With that done, a user can simply update his $PATH to look first in a directory that contains malicious replacements for commands called by the /etc/update-motd.d/ scripts (for instance "uname" called by 00_header).
pam_motd should perform the same kind of sanitisation as pam_exec, or even better not do the run-part /etc/update-motd.d/ at all but add some pam_exec calls to the pam configuration.
That issue is made worse by the fact that the running of those scripts by pam_motd is not documented.
[SRU JUSTIFICATION]
IMPACT
This bug affects those who might have manually modified their PAM configuration to add something like "session optional pam_motd.so" to a pam configuration in pam.d, such as /etc/pam.d/su, where the user controls the environment prior to executing the PAM stack. If so, the user can elevate her privileges to root by simply modifying her PATH to look in a directory that contains a malicious replacement for any of the programs called by the shell scripts in /etc/update-motd.d, such as 'uname'. Note that default Ubuntu installs are NOT affected, as pam_motd only runs in sshd and login PAM stacks, where the environment is already well controlled.
HOW ADDRESSED
The bug is trivially fixed by wrapping the run-parts shell call with an env -i, which clears the entire environment, and manually sets the PATH variable (to the same value lifted from /etc/login.defs.
PATCH
See the patch attached to this bug. It applies equally to all of the affected Ubuntu versions.
REPRODUCE INSTRUCTIONS
To test, add $HOME/bin to the path of non-root user 'kirkland'. Add a shell script, $HOME/bin/uname which does a "date >> /root/howdy". I then add "session optional pam_motd.so" to the end of /etc/pam.d/su. Before installing patched pam, su and definite see the file /root/howdy created (verifying the vulnerability). After applying and installing patched pam, you should not see /root/howdy created.
REGRESSION POTENTIAL
As far as I could tell, the rest of the update-motd part of pam_motd seemed to work correctly without regression. In the absolute worst case, /etc/motd might not be updated correctly, which is obviously not ideal, but hardly critical functionality to system operation.
Changed in pam (Ubuntu): | |
assignee: | nobody → Dustin Kirkland (kirkland) |
status: | New → Confirmed |
importance: | Undecided → Low |
Changed in pam (Ubuntu): | |
assignee: | Dustin Kirkland (kirkland) → nobody |
Changed in pam (Ubuntu Maverick): | |
status: | New → Triaged |
Changed in pam (Ubuntu Lucid): | |
status: | New → Triaged |
Changed in pam (Ubuntu Maverick): | |
importance: | Undecided → Low |
Changed in pam (Ubuntu Lucid): | |
importance: | Undecided → Low |
assignee: | nobody → Dustin Kirkland (kirkland) |
Changed in pam (Ubuntu Maverick): | |
assignee: | nobody → Dustin Kirkland (kirkland) |
Changed in pam (Ubuntu Natty): | |
assignee: | nobody → Dustin Kirkland (kirkland) |
Changed in pam (Ubuntu Lucid): | |
milestone: | none → lucid-updates |
Changed in pam (Ubuntu Maverick): | |
milestone: | none → maverick-updates |
Changed in pam (Ubuntu Natty): | |
milestone: | none → natty-updates |
Changed in pam (Ubuntu Oneiric): | |
status: | New → Triaged |
importance: | Undecided → Low |
assignee: | nobody → Dustin Kirkland (kirkland) |
Changed in pam (Ubuntu Oneiric): | |
status: | Triaged → In Progress |
Changed in pam (Ubuntu Natty): | |
status: | Triaged → In Progress |
Changed in pam (Ubuntu Maverick): | |
status: | Triaged → In Progress |
Changed in pam (Ubuntu Lucid): | |
status: | Triaged → In Progress |
Changed in pam (Ubuntu Precise): | |
status: | Triaged → Fix Released |
Changed in pam (Ubuntu Oneiric): | |
status: | Triaged → Fix Released |
Changed in pam (Ubuntu): | |
status: | Triaged → Fix Released |
@Dustin, you removed yourself from the assignment even though aiui you implemented the feature. Can you provide more details?