Bug 1964125 (CVE-2021-35937)

Summary: CVE-2021-35937 rpm: TOCTOU race in checks for unsafe symlinks
Product: [Other] Security Response Reporter: msiddiqu
Component: vulnerabilityAssignee: Nobody <nobody>
Status: NEW --- QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: unspecifiedCC: ajak, caswilli, derrick.roach.ctr, ffesti, kaycoth, mdogra, packaging-team-maint, pmatilai, sbalasub, sbueno, vmugicag, vmukhame
Target Milestone: ---Keywords: Security
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
A race condition vulnerability was found in rpm. A local unprivileged user could use this flaw to bypass the checks that were introduced in response to CVE-2017-7500 and CVE-2017-7501, potentially gaining root privileges. The highest threat from this vulnerability is to data confidentiality and integrity as well as system availability.
Story Points: ---
Clone Of: Environment:
Last Closed: Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1971282, 1969801, 1969802, 1969803, 1977846, 2003065, 2070454    
Bug Blocks: 1964123, 1977373    

Description msiddiqu 2021-05-24 18:55:14 UTC
In response to CVE-2017-7500 and CVE-2017-7501, it was decided that the policy of RPM is "Only follow directory symlinks owned by target directory owner or root." [1]. This check was implemented in a way that is subject to race conditions. If an attacker manages to change things between the call to lstat() that finds a safe symlink and the open() that creates a new file, the policy is not enforced.

Exploits are tricky because of the narrow timing window between the calls, but mazes [2] could probably be used to delay the stat() long enough for a reliable exploit. Fixing this would require opening the directory with O_PATH|O_NOFOLLOW, followed by fstat() to check ownership and openat() to create the final file.

References:

1. https://github.com/rpm-software-management/rpm/commit/f2d3be2a8741234faaa96f5fd05fdfdc75779a79
2. https://www.usenix.org/legacy/event/sec05/tech/full_papers/borisov/borisov.pdf
3. https://bugzilla.suse.com/show_bug.cgi?id=1157882

Comment 4 Mauro Matteo Cascella 2021-06-30 15:21:41 UTC
Created rpm tracking bugs for this issue:

Affects: fedora-all [bug 1977846]

Comment 5 Mauro Matteo Cascella 2021-07-07 16:22:32 UTC
This flaw, along with CVE-2021-35938 and CVE-2021-35939, belong to a set of complex issues that may allow an unprivileged user to trick RPM into modifying root-owned files during installation, due to race conditions and/or symlink attacks. These issues do not have a solution upstream. Fixing would require rather involved refactoring of RPM internals.

Note that in this context, unprivileged users are actually system accounts (like the pcpqa user mentioned in one of the SUSE bugs) that are usually more tightly controlled than ordinary users. In general, access to files and directories installed by RPMs requires high privileges. Regular users should not be allowed to manipulate RPM artifacts during installation. A local attacker would first need to compromise a system account in order to exploit these flaws, thus reducing the overall impact considerably.

Comment 9 Panu Matilainen 2022-05-13 07:36:06 UTC
This is considered fixed in RPM 4.18 (https://rpm.org/wiki/Releases/4.18.0) which is currently in alpha stage of the release process, final version is expected in Q3.

Comment 10 John Helmert III 2022-08-26 16:06:55 UTC
(In reply to Panu Matilainen from comment #9)
> This is considered fixed in RPM 4.18 (https://rpm.org/wiki/Releases/4.18.0)
> which is currently in alpha stage of the release process, final version is
> expected in Q3.

Is there a patch for this issue anywhere?

Comment 11 Panu Matilainen 2022-08-29 07:29:41 UTC
(In reply to John Helmert III from comment #10)
> Is there a patch for this issue anywhere?

No. As indicated in the comments, fixing the set of related issues is a complicated refactoring job, some of which can be found here: https://github.com/rpm-software-management/rpm/pull/1919.

Comment 15 errata-xmlrpc 2024-01-24 15:26:12 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 9.0 Extended Update Support

Via RHSA-2024:0435 https://access.redhat.com/errata/RHSA-2024:0435

Comment 16 errata-xmlrpc 2024-01-24 16:30:40 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 9

Via RHSA-2024:0463 https://access.redhat.com/errata/RHSA-2024:0463

Comment 17 errata-xmlrpc 2024-01-24 16:40:08 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 9.2 Extended Update Support

Via RHSA-2024:0453 https://access.redhat.com/errata/RHSA-2024:0453

Comment 18 errata-xmlrpc 2024-01-24 16:48:33 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8.6 Extended Update Support

Via RHSA-2024:0424 https://access.redhat.com/errata/RHSA-2024:0424

Comment 19 errata-xmlrpc 2024-01-30 13:24:41 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8.8 Extended Update Support

Via RHSA-2024:0582 https://access.redhat.com/errata/RHSA-2024:0582

Comment 20 errata-xmlrpc 2024-02-01 12:29:34 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8

Via RHSA-2024:0647 https://access.redhat.com/errata/RHSA-2024:0647