X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fcore%2Fmount-setup.c;h=23a66d2e957a5fc5d4f50870791a082ea7108cd8;hp=7845e88644be85e6e48d65084aaadd9b0b489c49;hb=d5099efc47d4e6ac60816b5381a5f607ab03f06e;hpb=d407c9402064d8b9d1b12dca6ca1ddb2688e5454 diff --git a/src/core/mount-setup.c b/src/core/mount-setup.c index 7845e8864..23a66d2e9 100644 --- a/src/core/mount-setup.c +++ b/src/core/mount-setup.c @@ -42,10 +42,8 @@ #include "missing.h" #include "virt.h" #include "efivars.h" - -#ifndef TTY_GID -#define TTY_GID 5 -#endif +#include "smack-util.h" +#include "def.h" typedef enum MountMode { MNT_NONE = 0, @@ -65,23 +63,28 @@ typedef struct MountPoint { /* The first three entries we might need before SELinux is up. The * fourth (securityfs) is needed by IMA to load a custom policy. The - * other ones we can delay until SELinux and IMA are loaded. */ + * other ones we can delay until SELinux and IMA are loaded. When + * SMACK is enabled we need smackfs, too, so it's a fifth one. */ +#ifdef HAVE_SMACK #define N_EARLY_MOUNT 5 +#else +#define N_EARLY_MOUNT 4 +#endif static const MountPoint mount_table[] = { - { "proc", "/proc", "proc", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV, - NULL, MNT_FATAL|MNT_IN_CONTAINER }, { "sysfs", "/sys", "sysfs", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV, NULL, MNT_FATAL|MNT_IN_CONTAINER }, + { "proc", "/proc", "proc", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV, + NULL, MNT_FATAL|MNT_IN_CONTAINER }, { "devtmpfs", "/dev", "devtmpfs", "mode=755", MS_NOSUID|MS_STRICTATIME, NULL, MNT_FATAL|MNT_IN_CONTAINER }, { "securityfs", "/sys/kernel/security", "securityfs", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV, NULL, MNT_NONE }, - { "smackfs", "/sys/fs/smackfs", "smackfs", "smackfsdef=*", MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_STRICTATIME, - NULL, MNT_NONE }, #ifdef HAVE_SMACK + { "smackfs", "/sys/fs/smackfs", "smackfs", "smackfsdef=*", MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_STRICTATIME, + use_smack, MNT_FATAL }, { "tmpfs", "/dev/shm", "tmpfs", "mode=1777,smackfsroot=*", MS_NOSUID|MS_NODEV|MS_STRICTATIME, - NULL, MNT_IN_CONTAINER }, + use_smack, MNT_FATAL }, #endif { "tmpfs", "/dev/shm", "tmpfs", "mode=1777", MS_NOSUID|MS_NODEV|MS_STRICTATIME, NULL, MNT_FATAL|MNT_IN_CONTAINER }, @@ -89,18 +92,16 @@ static const MountPoint mount_table[] = { NULL, MNT_IN_CONTAINER }, #ifdef HAVE_SMACK { "tmpfs", "/run", "tmpfs", "mode=755,smackfsroot=*", MS_NOSUID|MS_NODEV|MS_STRICTATIME, - NULL, MNT_IN_CONTAINER }, + use_smack, MNT_FATAL }, #endif { "tmpfs", "/run", "tmpfs", "mode=755", MS_NOSUID|MS_NODEV|MS_STRICTATIME, NULL, MNT_FATAL|MNT_IN_CONTAINER }, { "tmpfs", "/sys/fs/cgroup", "tmpfs", "mode=755", MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_STRICTATIME, - NULL, MNT_IN_CONTAINER }, -#ifdef HAVE_XATTR + NULL, MNT_FATAL|MNT_IN_CONTAINER }, { "cgroup", "/sys/fs/cgroup/systemd", "cgroup", "none,name=systemd,xattr", MS_NOSUID|MS_NOEXEC|MS_NODEV, NULL, MNT_IN_CONTAINER }, -#endif { "cgroup", "/sys/fs/cgroup/systemd", "cgroup", "none,name=systemd", MS_NOSUID|MS_NOEXEC|MS_NODEV, - NULL, MNT_IN_CONTAINER }, + NULL, MNT_FATAL|MNT_IN_CONTAINER }, { "pstore", "/sys/fs/pstore", "pstore", NULL, MS_NOSUID|MS_NOEXEC|MS_NODEV, NULL, MNT_NONE }, #ifdef ENABLE_EFI @@ -174,7 +175,10 @@ static int mount_one(const MountPoint *p, bool relabel) { /* The access mode here doesn't really matter too much, since * the mounted file system will take precedence anyway. */ - mkdir_p_label(p->where, 0755); + if (relabel) + mkdir_p_label(p->where, 0755); + else + mkdir_p(p->where, 0755); log_debug("Mounting %s to %s of type %s with options %s.", p->what, @@ -187,7 +191,7 @@ static int mount_one(const MountPoint *p, bool relabel) { p->type, p->flags, p->options) < 0) { - log_full((p->mode & MNT_FATAL) ? LOG_ERR : LOG_DEBUG, "Failed to mount %s: %s", p->where, strerror(errno)); + log_full((p->mode & MNT_FATAL) ? LOG_ERR : LOG_DEBUG, "Failed to mount %s at %s: %m", p->type, p->where); return (p->mode & MNT_FATAL) ? -errno : 0; } @@ -218,10 +222,10 @@ int mount_setup_early(void) { } int mount_cgroup_controllers(char ***join_controllers) { - int r; - char buf[LINE_MAX]; _cleanup_set_free_free_ Set *controllers = NULL; _cleanup_fclose_ FILE *f; + char buf[LINE_MAX]; + int r; /* Mount all available cgroup controllers that are built into the kernel. */ @@ -231,7 +235,7 @@ int mount_cgroup_controllers(char ***join_controllers) { return 0; } - controllers = set_new(string_hash_func, string_compare_func); + controllers = set_new(&string_hash_ops); if (!controllers) return log_oom(); @@ -264,6 +268,7 @@ int mount_cgroup_controllers(char ***join_controllers) { } for (;;) { + _cleanup_free_ char *options = NULL, *controller = NULL, *where = NULL; MountPoint p = { .what = "cgroup", .type = "cgroup", @@ -271,7 +276,6 @@ int mount_cgroup_controllers(char ***join_controllers) { .mode = MNT_IN_CONTAINER, }; char ***k = NULL; - _cleanup_free_ char *options = NULL, *controller; controller = set_steal_first(controllers); if (!controller) @@ -288,7 +292,7 @@ int mount_cgroup_controllers(char ***join_controllers) { for (i = *k, j = *k; *i; i++) { if (!streq(*i, controller)) { - char _cleanup_free_ *t; + _cleanup_free_ char *t; t = set_remove(controllers, *i); if (!t) { @@ -310,7 +314,11 @@ int mount_cgroup_controllers(char ***join_controllers) { controller = NULL; } - p.where = strappenda("/sys/fs/cgroup/", options); + where = strappend("/sys/fs/cgroup/", options); + if (!where) + return log_oom(); + + p.where = where; p.options = options; r = mount_one(&p, true); @@ -321,7 +329,11 @@ int mount_cgroup_controllers(char ***join_controllers) { char **i; for (i = *k; *i; i++) { - char *t = strappenda("/sys/fs/cgroup/", *i); + _cleanup_free_ char *t = NULL; + + t = strappend("/sys/fs/cgroup/", *i); + if (!t) + return log_oom(); r = symlink(options, t); if (r < 0 && errno != EEXIST) { @@ -332,6 +344,10 @@ int mount_cgroup_controllers(char ***join_controllers) { } } + /* Now that we mounted everything, let's make the tmpfs the + * cgroup file systems are mounted into read-only. */ + mount("tmpfs", "/sys/fs/cgroup", "tmpfs", MS_REMOUNT|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_STRICTATIME|MS_RDONLY, "mode=755"); + return 0; }