Bug 1970887 (CVE-2021-33910) - CVE-2021-33910 systemd: uncontrolled allocation on the stack in function unit_name_path_escape leads to crash
Summary: CVE-2021-33910 systemd: uncontrolled allocation on the stack in function unit...
Keywords:
Status: CLOSED ERRATA
Alias: CVE-2021-33910
Product: Security Response
Classification: Other
Component: vulnerability
Version: unspecified
Hardware: All
OS: Linux
high
high
Target Milestone: ---
Assignee: Red Hat Product Security
QA Contact:
URL:
Whiteboard:
Depends On: 1976591 1974696 1974697 1974698 1974699 1974700 1974721 1976592 1976593 1976594 1976595 1976596 1976597 1979859 1984020 1984299
Blocks: 1974594
TreeView+ depends on / blocked
 
Reported: 2021-06-11 12:08 UTC by msiddiqu
Modified: 2022-04-17 21:27 UTC (History)
38 users (show)

Fixed In Version: systemd 249
Doc Type: If docs needed, set a value
Doc Text:
A flaw was found in systemd. The use of alloca function with an uncontrolled size in function unit_name_path_escape allows a local attacker, able to mount a filesystem on a very long path, to crash systemd and the whole system by allocating a very large space in the stack. The highest threat from this vulnerability is to the system availability.
Clone Of:
Environment:
Last Closed: 2021-07-21 03:54:50 UTC
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2021:2861 0 None None None 2021-07-21 20:51:01 UTC
Red Hat Product Errata RHBA-2021:2862 0 None None None 2021-07-21 21:07:36 UTC
Red Hat Product Errata RHBA-2021:2863 0 None None None 2021-07-21 21:26:12 UTC
Red Hat Product Errata RHBA-2021:2869 0 None None None 2021-07-22 14:48:42 UTC
Red Hat Product Errata RHBA-2021:2870 0 None None None 2021-07-22 19:17:15 UTC
Red Hat Product Errata RHBA-2021:2871 0 None None None 2021-07-22 19:17:45 UTC
Red Hat Product Errata RHBA-2021:2872 0 None None None 2021-07-22 19:18:12 UTC
Red Hat Product Errata RHBA-2021:2876 0 None None None 2021-07-26 01:14:56 UTC
Red Hat Product Errata RHBA-2021:2887 0 None None None 2021-07-26 16:26:13 UTC
Red Hat Product Errata RHBA-2021:2892 0 None None None 2021-07-26 16:33:15 UTC
Red Hat Product Errata RHBA-2021:2893 0 None None None 2021-07-26 16:31:15 UTC
Red Hat Product Errata RHBA-2021:2908 0 None None None 2021-07-26 16:33:48 UTC
Red Hat Product Errata RHBA-2021:2910 0 None None None 2021-07-26 21:02:04 UTC
Red Hat Product Errata RHBA-2021:2923 0 None None None 2021-07-27 17:56:40 UTC
Red Hat Product Errata RHBA-2021:2924 0 None None None 2021-07-27 19:50:21 UTC
Red Hat Product Errata RHBA-2021:2941 0 None None None 2021-07-28 19:30:41 UTC
Red Hat Product Errata RHBA-2021:2946 0 None None None 2021-07-29 12:11:55 UTC
Red Hat Product Errata RHBA-2021:2953 0 None None None 2021-07-29 15:35:14 UTC
Red Hat Product Errata RHBA-2021:2958 0 None None None 2021-07-29 18:04:12 UTC
Red Hat Product Errata RHBA-2021:2987 0 None None None 2021-08-20 04:20:47 UTC
Red Hat Product Errata RHBA-2021:3183 0 None None None 2021-08-17 11:23:09 UTC
Red Hat Product Errata RHBA-2021:3194 0 None None None 2021-08-17 15:18:41 UTC
Red Hat Product Errata RHBA-2021:3203 0 None None None 2021-08-17 18:59:10 UTC
Red Hat Product Errata RHBA-2021:3210 0 None None None 2021-08-18 15:20:28 UTC
Red Hat Product Errata RHBA-2021:3239 0 None None None 2021-08-20 04:22:02 UTC
Red Hat Product Errata RHBA-2021:3664 0 None None None 2021-09-23 20:29:17 UTC
Red Hat Product Errata RHSA-2021:2717 0 None None None 2021-07-21 00:28:19 UTC
Red Hat Product Errata RHSA-2021:2721 0 None None None 2021-07-20 22:32:27 UTC
Red Hat Product Errata RHSA-2021:2724 0 None None None 2021-07-20 22:29:06 UTC
Red Hat Product Errata RHSA-2021:2736 0 None None None 2021-07-22 15:06:55 UTC
Red Hat Product Errata RHSA-2021:2763 0 None None None 2021-07-26 16:40:32 UTC

Description msiddiqu 2021-06-11 12:08:50 UTC
A flaw was found in systemd. Attacker controlled alloca() in function unit_name_path_escape() leads to a crash in systemd and ultimately a kernel panic. Systemd parses the content of /proc/self/mountinfo and each mountpoint is passed to mount_setup_unit(), which calls unit_name_path_escape() underneath to duplicate the string through alloca(). A local attacker who is able to mount a filesystem on a very long path can crash systemd and the whole system.

Upstream PR:
https://github.com/systemd/systemd/pull/20256

Upstream commit:
https://github.com/systemd/systemd/pull/20256/commits/441e0115646d54f080e5c3bb0ba477c892861ab9

Comment 1 Riccardo Schirone 2021-06-22 10:26:11 UTC
systemd as shipped in RHEL7 is not affected by this flaw because `unit_name_path_escape()` uses the heap instead of the stack.

```
char *unit_name_path_escape(const char *f) {
        _cleanup_free_ char *p = NULL;

        assert(f);

        p = strdup(f);
        if (!p)
                return NULL;

        path_kill_slashes(p);

        if (STR_IN_SET(p, "/", ""))
                return strdup("-");

        return unit_name_escape(p[0] == '/' ? p + 1 : p);
}
```

Comment 2 Riccardo Schirone 2021-06-22 10:29:05 UTC
This vulnerability was likely introduced in systemd v220 with the following commit which replaced a strdup() in the heap with a strdupa() on the stack.

https://github.com/systemd/systemd/commit/7410616cd9dbbec97cf98d75324da5cda2b2f7a2

Comment 5 Riccardo Schirone 2021-06-22 10:50:25 UTC
Function unit_name_path_escape() uses strdupa to duplicate the path string passed as argument. strdupa is like strdup but it allocates the buffer on the stack with `alloca()`. If the size passed to `alloca()` is bigger than the available stack, the program writes to the wrong memory region (e.g. unallocated space) causing a crash.

systemd parses the content of /proc/self/mountinfo and each mountpoint is passed to mount_setup_unit(), which calls unit_name_path_escape() underneath. A local attacker who is able to mount a filesystem with a very long path can crash systemd and the whole system.

Comment 7 Riccardo Schirone 2021-06-22 16:05:01 UTC
This flaw is considered as having an Important impact due to the ability to stop the whole system by making systemd (PID 1) crash.

Comment 20 Riccardo Schirone 2021-07-06 10:16:14 UTC
File /proc/self/mountinfo is constantly monitored by systemd and its content parsed by mount_load_proc_self_mountinfo() function whenever a change to the file is detected. Each mount entry in the file is passed to mount_setup_unit(), which calls unit_name_from_path() to retrieve the systemd unit name for the mount point and use it to check if a mount unit configuration file is available for it. Function unit_name_from_path() calls unit_name_path_escape() that uses strdupa() to duplicate the path string passed as argument, which is like strdup() but it allocates the buffer on the stack with alloca().

Comment 23 errata-xmlrpc 2021-07-20 22:29:03 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8.1 Extended Update Support

Via RHSA-2021:2724 https://access.redhat.com/errata/RHSA-2021:2724

Comment 24 errata-xmlrpc 2021-07-20 22:32:27 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8.2 Extended Update Support

Via RHSA-2021:2721 https://access.redhat.com/errata/RHSA-2021:2721

Comment 25 errata-xmlrpc 2021-07-21 00:28:20 UTC
This issue has been addressed in the following products:

  Red Hat Enterprise Linux 8

Via RHSA-2021:2717 https://access.redhat.com/errata/RHSA-2021:2717

Comment 26 Product Security DevOps Team 2021-07-21 03:54:50 UTC
This bug is now closed. Further updates for individual products will be reflected on the CVE page(s):

https://access.redhat.com/security/cve/cve-2021-33910

Comment 28 errata-xmlrpc 2021-07-22 15:06:50 UTC
This issue has been addressed in the following products:

  Red Hat Virtualization 4 for Red Hat Enterprise Linux 8

Via RHSA-2021:2736 https://access.redhat.com/errata/RHSA-2021:2736

Comment 29 errata-xmlrpc 2021-07-26 16:40:32 UTC
This issue has been addressed in the following products:

  Red Hat OpenShift Container Platform 4.7

Via RHSA-2021:2763 https://access.redhat.com/errata/RHSA-2021:2763


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