RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1478761 - Double sudo no longer sets USER environment variable
Summary: Double sudo no longer sets USER environment variable
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: sudo
Version: 7.6
Hardware: x86_64
OS: Linux
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Marek Tamaskovic
QA Contact: BaseOS QE Security Team
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-08-07 00:45 UTC by tiernan.messmer
Modified: 2017-10-02 11:20 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-10-02 11:19:48 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description tiernan.messmer 2017-08-07 00:45:28 UTC
Description of problem:
When sudo is used to switch user, the environment variable USER is set with the new username. After the latest security patch, this appears to have broken when sudo is used twice in a row, eg userA sudos to userB, which then sudos to userC - after the final sudo the USER environment variable is still equal to userB not userC as expected.

This behaviour worked correctly on earlier patch versions of sudo on RHEL7

Version-Release number of selected component (if applicable):
sudo.x86_64 1.8.19p2-10.el7

How reproducible:
Completely reproducible

Steps to Reproduce:
1. On a system create 2 users, userA and userB. root will be used as the third user, but the specific users do not matter
2. Add the following to the sudoers file

userA ALL=(ALL) ALL

2. Login to the system as userA
3. Run the following commands as per actual results. Notice the final echo $USER outputs the wrong username. It doesn't seem to matter which users are used, as long as sudo is invoked twice.

Actual results:

[userA@system ~] echo $USER
usera
[userA@system ~] sudo -s
[root@system ~] echo $USER
root
[root@system ~] sudo -s -u userB
[userB@system ~] echo $USER
root


Expected results:
On a system with an older version of sudo the following is observed:

[userA@system ~] echo $USER
usera
[userA@system ~] sudo -s
[root@system ~] echo $USER
root
[root@system ~] sudo -s -u userB
[userB@system ~] echo $USER
userB


Additional info:
env_reset is set and env_keep does not contain USER as per the defaults in /etc/sudoers.

Comment 2 Marek Tamaskovic 2017-09-27 06:37:20 UTC
Here's what is happening:

1) sudo is invoked without USERNAME set

2) sudo executes the other sudo command, setting LOGNAME, USER and
USERNAME to the name of target user

3) the second sudo preserves USERNAME as per sudoers, which is set to
the name of the user the first sudo ran as (root in your example)

4) sudo also preserves LOGNAME and USER to avoid having LOGNAME, USER
and USERNAME be inconsistent.

Sudo is behaving as intended, though the behavior with respect to
keeping LOGNAME, USER and USERNAME be consistent is not well
documented.

It would probably be less surprising if sudo were to preserve USER and
LOGNAME too if USERNAME is listed in env_keep.

Comment 3 tiernan.messmer 2017-09-27 07:41:10 UTC
This explains the behaviour. Removing USERNAME from env_keep reverts the the previous behaviour as seen on systems with sudo version before 1.8.19p2-10.el7. The sudoers file did not not appear to have been changed between versions, so env_keep including USERNAME on older versions did not exhibit this behaviour.

I guess the question at this stage though is why the behaviour changed between versions. Was this a part of the security bug that was fixed in 1.8.19p2-10.el7? Or was this an additional bugfix that was accidentally backported with the security fix?

Comment 4 Marek Tamaskovic 2017-10-02 11:19:48 UTC
I think it was fixed in new version.


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