tmpfiles: skip a C entry with a relative path to copy from

The argument of a C entry was used as it is, so a relative one was
copied from the directory tmpfiles happened to be started in.  With
--root that directory is outside the new root, and

    C /etc/copy - - - - ../../../etc/shadow

in a file below the root copied a file of the running system into it.

systemd skips a C line when the path to copy from is not absolute.
Do the same, with a warning.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-11-21 19:23:51 +01:00
1 parent 225b2594b7
commit a629c8add3
3 files changed
+9

No files matched your search

+2
View File
@@ -34,6 +34,7 @@ z /var/lib/root-test/other 0644
L /link - - - - /var/lib/root-test
f /link/through 0640
C /etc/issue
C /etc/outside - - - - ../../../etc/passwd
d /skipped 0700 daemon
CONF
run "echo 'd /from/cmdline 0711' > $CONF"
@@ -55,6 +56,7 @@ say 'So are the paths, also what a link points to'
assert_stat /var/lib/root-test/other "644 0 0"
assert_stat /var/lib/root-test/through "640 0 0"
assert "Copied from its factory" "$(texec cat $ROOT/etc/issue)" = "factory"
assert "No copy from outside it" "$(texec sh -c "ls $ROOT/etc | grep -c outside")" = "0"
assert "Nothing outside it" "$(texec sh -c "ls /var/lib | grep -c root-test")" = "0"
sep