summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-06-23 11:46:41 +0200
committerMichal Bloch <m.bloch@samsung.com>2021-07-22 12:55:35 +0200
commit87ca945439e5cc5ef049a5a8af25d2fb9ac2b4f5 (patch)
treecbbeb254b554a4895acdd60c5ac38e8560dbdc93
parentcf950008b4816b1e7662c6fb69f3480f047d9549 (diff)
downloadsystemd-87ca945439e5cc5ef049a5a8af25d2fb9ac2b4f5.tar.gz
systemd-87ca945439e5cc5ef049a5a8af25d2fb9ac2b4f5.tar.bz2
systemd-87ca945439e5cc5ef049a5a8af25d2fb9ac2b4f5.zip
basic/unit-name: do not use strdupa() on a pathsubmit/tizen/20210726.050348accepted/tizen/unified/20210727.124539
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. Change-Id: I4e2d3a82bbc4f53845cca6186c62588d8894566e
-rw-r--r--src/basic/unit-name.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/basic/unit-name.c b/src/basic/unit-name.c
index 680e8eb4ab..f20cad22e3 100644
--- a/src/basic/unit-name.c
+++ b/src/basic/unit-name.c
@@ -369,12 +369,13 @@ int unit_name_unescape(const char *f, char **ret) {
}
int unit_name_path_escape(const char *f, char **ret) {
- char *p, *s;
+ _cleanup_free_ char *p = NULL;
+ char *s;
assert(f);
assert(ret);
- p = strdupa(f);
+ p = strdup(f);
if (!p)
return -ENOMEM;
@@ -386,13 +387,9 @@ int unit_name_path_escape(const char *f, char **ret) {
if (!path_is_normalized(p))
return -EINVAL;
- /* Truncate trailing slashes */
+ /* Truncate trailing slashes and skip leading slashes */
delete_trailing_chars(p, "/");
-
- /* Truncate leading slashes */
- p = skip_leading_chars(p, "/");
-
- s = unit_name_escape(p);
+ s = unit_name_escape(skip_leading_chars(p, "/"));
}
if (!s)
return -ENOMEM;