diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 42512da604..9de612c1d6 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -2238,6 +2238,9 @@ static int copy_files(Context *c, Item *i) { return log_error_errno(errno, "Failed to openat(%s): %m", i->path); } + if (r < 0 && !IN_SET(r, -EEXIST, -EROFS)) + return log_error_errno(r, "Failed to copy files to %s: %m", i->path); + if (fstat(fd, &st) < 0) return log_error_errno(errno, "Failed to fstat(%s): %m", i->path); diff --git a/test/units/TEST-22-TMPFILES.03.sh b/test/units/TEST-22-TMPFILES.03.sh index d75294207a..c36f8f8790 100755 --- a/test/units/TEST-22-TMPFILES.03.sh +++ b/test/units/TEST-22-TMPFILES.03.sh @@ -5,6 +5,9 @@ set -eux set -o pipefail +# shellcheck source=test/units/util.sh +. "$(dirname "$0")"/util.sh + rm -fr /tmp/{f,F,w} mkdir /tmp/{f,F,w} touch /tmp/file-owned-by-root @@ -190,6 +193,22 @@ F /tmp/F/daemon/unsafe-symlink/exploit 0644 daemon daemon - - EOF test ! -e /tmp/F/daemon/unsafe-symlink/exploit +# +# 'C' +# +rm -rf /tmp/C-copy-failure-src /tmp/C-copy-failure-dst +mkdir /tmp/C-copy-failure-src /tmp/C-copy-failure-dst +printf payload >/tmp/C-copy-failure-src/file +chmod 555 /tmp/C-copy-failure-dst + +(! runas nobody systemd-tmpfiles --create - <