Skip to content

Commit

Permalink
nspawn: refuse to bind mount device node from host when --private-use…
Browse files Browse the repository at this point in the history
…rs= is specified

Also do not chown if a device node is bind-mounted.

Fixes #34243.

(cherry picked from commit efedb6b0f3cff37950112fd37cb750c16d599bc7)
(cherry picked from commit a23591891b9e85107f39d103eabbb5bc9a6ced6f)
  • Loading branch information
yuwata authored and bluca committed Sep 10, 2024
1 parent a3872e6 commit bc72d95
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/nspawn/nspawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -2185,7 +2185,7 @@ static int copy_devnodes(const char *dest) {
/* Explicitly warn the user when /dev is already populated. */
if (errno == EEXIST)
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);
if (errno != EPERM)
if (errno != EPERM || arg_uid_shift != 0)
return log_error_errno(errno, "mknod(%s) failed: %m", to);

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

r = userns_lchown(to, 0, 0);
if (r < 0)
return log_error_errno(r, "chown() of device node %s failed: %m", to);

dn = path_join("/dev", S_ISCHR(st.st_mode) ? "char" : "block");
if (!dn)
return log_oom();
Expand Down

0 comments on commit bc72d95

Please sign in to comment.