mirror of
https://github.com/systemd/systemd.git
synced 2025-08-05 16:22:27 +03:00
nspawn: be more careful with creating/chowning directories to overmount
We should never re-chown selinuxfs. Fixes: #15475
This commit is contained in:
committed by
Zbigniew Jędrzejewski-Szmek
parent
c98fef264b
commit
dcff2fa5d1
@ -569,7 +569,7 @@ int mount_all(const char *dest,
|
|||||||
static const MountPoint mount_table[] = {
|
static const MountPoint mount_table[] = {
|
||||||
/* First we list inner child mounts (i.e. mounts applied *after* entering user namespacing) */
|
/* First we list inner child mounts (i.e. mounts applied *after* entering user namespacing) */
|
||||||
{ "proc", "/proc", "proc", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV,
|
{ "proc", "/proc", "proc", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV,
|
||||||
MOUNT_FATAL|MOUNT_IN_USERNS },
|
MOUNT_FATAL|MOUNT_IN_USERNS|MOUNT_MKDIR },
|
||||||
|
|
||||||
{ "/proc/sys", "/proc/sys", NULL, NULL, MS_BIND,
|
{ "/proc/sys", "/proc/sys", NULL, NULL, MS_BIND,
|
||||||
MOUNT_FATAL|MOUNT_IN_USERNS|MOUNT_APPLY_APIVFS_RO }, /* Bind mount first ... */
|
MOUNT_FATAL|MOUNT_IN_USERNS|MOUNT_APPLY_APIVFS_RO }, /* Bind mount first ... */
|
||||||
@ -599,23 +599,23 @@ int mount_all(const char *dest,
|
|||||||
PROC_READ_ONLY("/proc/scsi"),
|
PROC_READ_ONLY("/proc/scsi"),
|
||||||
|
|
||||||
{ "mqueue", "/dev/mqueue", "mqueue", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV,
|
{ "mqueue", "/dev/mqueue", "mqueue", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV,
|
||||||
MOUNT_IN_USERNS },
|
MOUNT_IN_USERNS|MOUNT_MKDIR },
|
||||||
|
|
||||||
/* Then we list outer child mounts (i.e. mounts applied *before* entering user namespacing) */
|
/* Then we list outer child mounts (i.e. mounts applied *before* entering user namespacing) */
|
||||||
{ "tmpfs", "/tmp", "tmpfs", "mode=1777", MS_NOSUID|MS_NODEV|MS_STRICTATIME,
|
{ "tmpfs", "/tmp", "tmpfs", "mode=1777", MS_NOSUID|MS_NODEV|MS_STRICTATIME,
|
||||||
MOUNT_FATAL|MOUNT_APPLY_TMPFS_TMP },
|
MOUNT_FATAL|MOUNT_APPLY_TMPFS_TMP|MOUNT_MKDIR },
|
||||||
{ "tmpfs", "/sys", "tmpfs", "mode=555", MS_NOSUID|MS_NOEXEC|MS_NODEV,
|
{ "tmpfs", "/sys", "tmpfs", "mode=555", MS_NOSUID|MS_NOEXEC|MS_NODEV,
|
||||||
MOUNT_FATAL|MOUNT_APPLY_APIVFS_NETNS },
|
MOUNT_FATAL|MOUNT_APPLY_APIVFS_NETNS|MOUNT_MKDIR },
|
||||||
{ "sysfs", "/sys", "sysfs", NULL, MS_RDONLY|MS_NOSUID|MS_NOEXEC|MS_NODEV,
|
{ "sysfs", "/sys", "sysfs", NULL, MS_RDONLY|MS_NOSUID|MS_NOEXEC|MS_NODEV,
|
||||||
MOUNT_FATAL|MOUNT_APPLY_APIVFS_RO }, /* skipped if above was mounted */
|
MOUNT_FATAL|MOUNT_APPLY_APIVFS_RO|MOUNT_MKDIR }, /* skipped if above was mounted */
|
||||||
{ "sysfs", "/sys", "sysfs", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV,
|
{ "sysfs", "/sys", "sysfs", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV,
|
||||||
MOUNT_FATAL }, /* skipped if above was mounted */
|
MOUNT_FATAL|MOUNT_MKDIR }, /* skipped if above was mounted */
|
||||||
{ "tmpfs", "/dev", "tmpfs", "mode=755", MS_NOSUID|MS_STRICTATIME,
|
{ "tmpfs", "/dev", "tmpfs", "mode=755", MS_NOSUID|MS_STRICTATIME,
|
||||||
MOUNT_FATAL },
|
MOUNT_FATAL|MOUNT_MKDIR },
|
||||||
{ "tmpfs", "/dev/shm", "tmpfs", "mode=1777", MS_NOSUID|MS_NODEV|MS_STRICTATIME,
|
{ "tmpfs", "/dev/shm", "tmpfs", "mode=1777", MS_NOSUID|MS_NODEV|MS_STRICTATIME,
|
||||||
MOUNT_FATAL },
|
MOUNT_FATAL|MOUNT_MKDIR },
|
||||||
{ "tmpfs", "/run", "tmpfs", "mode=755", MS_NOSUID|MS_NODEV|MS_STRICTATIME,
|
{ "tmpfs", "/run", "tmpfs", "mode=755", MS_NOSUID|MS_NODEV|MS_STRICTATIME,
|
||||||
MOUNT_FATAL },
|
MOUNT_FATAL|MOUNT_MKDIR },
|
||||||
|
|
||||||
#if HAVE_SELINUX
|
#if HAVE_SELINUX
|
||||||
{ "/sys/fs/selinux", "/sys/fs/selinux", NULL, NULL, MS_BIND,
|
{ "/sys/fs/selinux", "/sys/fs/selinux", NULL, NULL, MS_BIND,
|
||||||
@ -663,18 +663,20 @@ int mount_all(const char *dest,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (FLAGS_SET(mount_table[k].mount_settings, MOUNT_MKDIR)) {
|
||||||
r = mkdir_userns_p(dest, where, 0755, (use_userns && !in_userns) ? uid_shift : UID_INVALID);
|
r = mkdir_userns_p(dest, where, 0755, (use_userns && !in_userns) ? uid_shift : UID_INVALID);
|
||||||
if (r < 0 && r != -EEXIST) {
|
if (r < 0 && r != -EEXIST) {
|
||||||
if (fatal && r != -EROFS)
|
if (fatal && r != -EROFS)
|
||||||
return log_error_errno(r, "Failed to create directory %s: %m", where);
|
return log_error_errno(r, "Failed to create directory %s: %m", where);
|
||||||
|
|
||||||
log_debug_errno(r, "Failed to create directory %s: %m", where);
|
log_debug_errno(r, "Failed to create directory %s: %m", where);
|
||||||
/* If we failed mkdir() or chown() due to the root
|
|
||||||
* directory being read only, attempt to mount this fs
|
/* If we failed mkdir() or chown() due to the root directory being read only,
|
||||||
* anyway and let mount_verbose log any errors */
|
* attempt to mount this fs anyway and let mount_verbose log any errors */
|
||||||
if (r != -EROFS)
|
if (r != -EROFS)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
o = mount_table[k].options;
|
o = mount_table[k].options;
|
||||||
if (streq_ptr(mount_table[k].type, "tmpfs")) {
|
if (streq_ptr(mount_table[k].type, "tmpfs")) {
|
||||||
|
@ -16,6 +16,7 @@ typedef enum MountSettingsMask {
|
|||||||
MOUNT_APPLY_TMPFS_TMP = 1 << 5, /* if set, /tmp will be mounted as tmpfs */
|
MOUNT_APPLY_TMPFS_TMP = 1 << 5, /* if set, /tmp will be mounted as tmpfs */
|
||||||
MOUNT_ROOT_ONLY = 1 << 6, /* if set, only root mounts are mounted */
|
MOUNT_ROOT_ONLY = 1 << 6, /* if set, only root mounts are mounted */
|
||||||
MOUNT_NON_ROOT_ONLY = 1 << 7, /* if set, only non-root mounts are mounted */
|
MOUNT_NON_ROOT_ONLY = 1 << 7, /* if set, only non-root mounts are mounted */
|
||||||
|
MOUNT_MKDIR = 1 << 8, /* if set, make directory to mount over first */
|
||||||
} MountSettingsMask;
|
} MountSettingsMask;
|
||||||
|
|
||||||
typedef enum CustomMountType {
|
typedef enum CustomMountType {
|
||||||
|
Reference in New Issue
Block a user