Skip to content

Commit 675c577

Browse files
yuwatabluca
authored andcommitted
nspawn: refuse to bind mount device node from host when --private-users= is specified
Also do not chown if a device node is bind-mounted. Fixes #34243. (cherry picked from commit efedb6b) (cherry picked from commit a235918) (cherry picked from commit bc72d95) (cherry picked from commit b431088)
1 parent 6dadc4e commit 675c577

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/nspawn/nspawn.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,7 +2264,7 @@ static int copy_devnodes(const char *dest) {
22642264
/* Explicitly warn the user when /dev is already populated. */
22652265
if (errno == EEXIST)
22662266
log_notice("%s/dev is pre-mounted and pre-populated. If a pre-mounted /dev is provided it needs to be an unpopulated file system.", dest);
2267-
if (errno != EPERM)
2267+
if (errno != EPERM || arg_uid_shift != 0)
22682268
return log_error_errno(errno, "mknod(%s) failed: %m", to);
22692269

22702270
/* Some systems abusively restrict mknod but allow bind mounts. */
@@ -2274,12 +2274,12 @@ static int copy_devnodes(const char *dest) {
22742274
r = mount_nofollow_verbose(LOG_DEBUG, from, to, NULL, MS_BIND, NULL);
22752275
if (r < 0)
22762276
return log_error_errno(r, "Both mknod and bind mount (%s) failed: %m", to);
2277+
} else {
2278+
r = userns_lchown(to, 0, 0);
2279+
if (r < 0)
2280+
return log_error_errno(r, "chown() of device node %s failed: %m", to);
22772281
}
22782282

2279-
r = userns_lchown(to, 0, 0);
2280-
if (r < 0)
2281-
return log_error_errno(r, "chown() of device node %s failed: %m", to);
2282-
22832283
dn = path_join("/dev", S_ISCHR(st.st_mode) ? "char" : "block");
22842284
if (!dn)
22852285
return log_oom();

0 commit comments

Comments
 (0)