]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: make sure to chown() implicit source dirs for --bind= to container root UID
authorLennart Poettering <lennart@poettering.net>
Thu, 28 Oct 2021 13:10:42 +0000 (15:10 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 29 Oct 2021 07:16:34 +0000 (09:16 +0200)
This makes sure that a switch like --bind=:/foo does the right thing if
user namespacing is one: the backing dir should be owned by the
container's root UID not the host's. Thus, whenever the source path is
left empty and we automatically generate a source dir as temporary
directory, ensure it's owned by the right UID.

Fixes: #20869
src/nspawn/nspawn-mount.c

index 751e270c6cf980c48b295ec8770f3dbba8f4c161..2bfff79cde573b4a505ad84c4273f4c81fadfbf5 100644 (file)
@@ -726,6 +726,11 @@ static int mount_bind(const char *dest, CustomMount *m, uid_t uid_shift, uid_t u
                         return r;
         }
 
+        /* If this is a bind mount from a temporary sources change ownership of the source to the container's
+         * root UID. Otherwise it would always show up as "nobody" if user namespacing is used. */
+        if (m->rm_rf_tmpdir && chown(m->source, uid_shift, uid_shift) < 0)
+                return log_error_errno(errno, "Failed to chown %s: %m", m->source);
+
         if (stat(m->source, &source_st) < 0)
                 return log_error_errno(errno, "Failed to stat %s: %m", m->source);