Skip to content

Commit bc72d95

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)
1 parent a3872e6 commit bc72d95

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
@@ -2185,7 +2185,7 @@ static int copy_devnodes(const char *dest) {
21852185
/* Explicitly warn the user when /dev is already populated. */
21862186
if (errno == EEXIST)
21872187
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);
2188-
if (errno != EPERM)
2188+
if (errno != EPERM || arg_uid_shift != 0)
21892189
return log_error_errno(errno, "mknod(%s) failed: %m", to);
21902190

21912191
/* Some systems abusively restrict mknod but allow bind mounts. */
@@ -2195,12 +2195,12 @@ static int copy_devnodes(const char *dest) {
21952195
r = mount_nofollow_verbose(LOG_DEBUG, from, to, NULL, MS_BIND, NULL);
21962196
if (r < 0)
21972197
return log_error_errno(r, "Both mknod and bind mount (%s) failed: %m", to);
2198+
} else {
2199+
r = userns_lchown(to, 0, 0);
2200+
if (r < 0)
2201+
return log_error_errno(r, "chown() of device node %s failed: %m", to);
21982202
}
21992203

2200-
r = userns_lchown(to, 0, 0);
2201-
if (r < 0)
2202-
return log_error_errno(r, "chown() of device node %s failed: %m", to);
2203-
22042204
dn = path_join("/dev", S_ISCHR(st.st_mode) ? "char" : "block");
22052205
if (!dn)
22062206
return log_oom();

0 commit comments

Comments
 (0)