Bug 1778309 (CVE-2019-18276) - CVE-2019-18276 bash: when effective UID is not equal to its real UID the saved UID is not dropped
Summary: CVE-2019-18276 bash: when effective UID is not equal to its real UID the save...
Keywords:
Status: NEW
Alias: CVE-2019-18276
Product: Security Response
Classification: Other
Component: vulnerability
Version: unspecified
Hardware: All
OS: Linux
low
low
Target Milestone: ---
Assignee: Red Hat Product Security
QA Contact:
URL:
Whiteboard:
Depends On: 1778310 1793942 1793943
Blocks: 1778311
TreeView+ depends on / blocked
 
Reported: 2019-11-29 20:08 UTC by Guilherme de Almeida Suckevicz
Modified: 2020-01-24 17:11 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
A privilege escalation vulnerability was found in bash in the way it dropped privileges when started with an effective user id not equal to the real user id. Bash may be vulnerable to this flaw if the setuid permission is set and the owner of the bash program itself is a non-root user. A local attacker could exploit this flaw to escalate their privileges on the system.
Clone Of:
Environment:
Last Closed:


Attachments (Terms of Use)

Description Guilherme de Almeida Suckevicz 2019-11-29 20:08:38 UTC
An issue was discovered in disable_priv_mode in shell.c in GNU Bash through 5.0 patch 11. By default, if Bash is run with its effective UID not equal to its real UID, it will drop privileges by setting its effective UID to its real UID. However, it does so incorrectly. On Linux and other systems that support "saved UID" functionality, the saved UID is not dropped. An attacker with command execution in the shell can use "enable -f" for runtime loading of a new builtin, which can be a shared object that calls setuid() and therefore regains privileges. However, binaries running with an effective UID of 0 are unaffected.

Reference and upstream commit:
https://git.savannah.gnu.org/cgit/bash.git/commit/?h=devel&id=951bdaad7a18cc0dc1036bba86b18b90874d39ff

Comment 1 Guilherme de Almeida Suckevicz 2019-11-29 20:08:49 UTC
Created bash tracking bugs for this issue:

Affects: fedora-all [bug 1778310]

Comment 2 Mauro Matteo Cascella 2020-01-20 16:27:52 UTC
The setuid() function has different behaviors depending weather it is running as root or not. In the former case (running as root) it sets all three UIDs (effective UID, real UID and saved UID), whereas in the latter case (running as non-root) it only sets the effective UID.
It is worth noting that Bash is affected by this flaw only when running as non-root user; this lowers the exposure of the vulnerability.

Comment 3 Mauro Matteo Cascella 2020-01-20 17:17:45 UTC
Also note that in order to exploit this flaw, the bash process has to call setuid() without exec()-ing any other process as in this case the saved UID would be lost. Hence the need of the bash builtin feature mentioned above.

Comment 4 Mauro Matteo Cascella 2020-01-22 09:38:54 UTC
If the shell is started with the effective UID not equal to the real UID, and the -p option is not supplied, function disable_priv_mode() attempts to drop privileges by calling setuid(). However, as discussed in Comment 2, setuid() may fail to set the saved UID.

Upstream patch simply replaces this call with setresuid(), thus making sure the saved UID is also set appropriately:
https://git.savannah.gnu.org/cgit/bash.git/diff/shell.c?h=devel&id=951bdaad7a18cc0dc1036bba86b18b90874d39ff


Note You need to log in before you can comment on or make changes to this bug.