teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0189-shared-install-do-not-try-to-resolve-symlinks-outsid.patch

594167
From 64fa6f059ae0b491fdb52c7375d59774ff9c237a Mon Sep 17 00:00:00 2001
594167
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
594167
Date: Tue, 15 Mar 2022 16:35:47 +0100
594167
Subject: [PATCH] shared/install: do not try to resolve symlinks outside of
594167
 root directory
594167
MIME-Version: 1.0
594167
Content-Type: text/plain; charset=UTF-8
594167
Content-Transfer-Encoding: 8bit
594167
594167
I linked a file as root, so I had a symlink /root/test.service ← /etc/systemd/system/test.service.
594167
To my surpise, when running test-systemctl-enable, it failed with a cryptic EACCES.
594167
The previous commit made the logs a bit better. Strace shows that we
594167
were trying to follow the symlink without taking --root into account.
594167
594167
It seems that this bug was introduced in 66a19d85a533b15ed32f4066ec880b5a8c06babd:
594167
before it, we'd do readlink_malloc(), which returned a path relative to root. But
594167
we only used that path for checking if the path is in remove_symlinks_to set, which
594167
contains relative paths. So if the path was relative, we'd get a false-negative
594167
answer, but we didn't go outside of the root. (We need to canonicalize the symlink
594167
to get a consistent answer.) But after 66a19 we use chase_symlinks(), without taking
594167
root into account which is completely bogus.
594167
594167
(cherry picked from commit 40276314afc4fb5c35c6b3da3e6185af6ed3886b)
594167
594167
Related: #2082131
594167
---
594167
 src/shared/install.c | 2 +-
594167
 1 file changed, 1 insertion(+), 1 deletion(-)
594167
594167
diff --git a/src/shared/install.c b/src/shared/install.c
594167
index ce045d02be..ad0238ab50 100644
594167
--- a/src/shared/install.c
594167
+++ b/src/shared/install.c
594167
@@ -612,7 +612,7 @@ static int remove_marked_symlinks_fd(
594167
                                 return -ENOMEM;
594167
                         path_simplify(p);
594167
 
594167
-                        q = chase_symlinks(p, NULL, CHASE_NONEXISTENT, &dest, NULL);
594167
+                        q = chase_symlinks(p, lp->root_dir, CHASE_NONEXISTENT, &dest, NULL);
594167
                         if (q == -ENOENT)
594167
                                 continue;
594167
                         if (q < 0) {