basic/unit-name: do not use strdupa() on a path
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 23 Jun 2021 09:46:41 +0000 (11:46 +0200)
committerAdrian Bunk <bunk@debian.org>
Thu, 29 Jun 2023 13:57:02 +0000 (14:57 +0100)
commit594e0af28ebb5743690c3260162946d2743ba427
tree63e8b7dbc891ae65ff360464434dc7b1c5cf58e3
parent46103fbe6b36c198cd4576ce777ee276b88a3d20
basic/unit-name: do not use strdupa() on a path

The path may have unbounded length, for example through a fuse mount.

CVE-2021-33910: attacked controlled alloca() leads to 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. A local attacker who is able to mount a
filesystem with a very long path can crash systemd and the whole system.

https://bugzilla.redhat.com/show_bug.cgi?id=1970887

The resulting string length is bounded by UNIT_NAME_MAX, which is 256. But we
can't easily check the length after simplification before doing the
simplification, which in turns uses a copy of the string we can write to.
So we can't reject paths that are too long before doing the duplication.
Hence the most obvious solution is to switch back to strdup(), as before
7410616cd9dbbec97cf98d75324da5cda2b2f7a2.

Gbp-Pq: Name basic-unit-name-do-not-use-strdupa-on-a-path.patch
src/basic/unit-name.c