}
/* Walk /proc/mounts and change any shared entries to dependent mounts. */
-void turn_into_dependent_mounts(void)
+static void turn_into_dependent_mounts(const struct lxc_rootfs *rootfs)
{
__do_free char *line = NULL;
__do_fclose FILE *f = NULL;
ssize_t copied;
int ret;
- mntinfo_fd = open("/proc/self/mountinfo", O_RDONLY | O_CLOEXEC);
+ mntinfo_fd = open_at(rootfs->dfd_host, "proc/self/mountinfo", PROTECT_OPEN,
+ (PROTECT_LOOKUP_BENEATH_XDEV & ~RESOLVE_NO_SYMLINKS), 0);
if (mntinfo_fd < 0) {
- SYSERROR("Failed to open \"/proc/self/mountinfo\"");
+ SYSERROR("Failed to open %d/proc/self/mountinfo", rootfs->dfd_host);
return;
}
SYSERROR("Failed to recursively turn old root mount tree into dependent mount. Continuing...");
continue;
}
- TRACE("Recursively turned old root mount tree into dependent mount");
}
TRACE("Turned all mount table entries into dependent mount");
}
if (conf->rootfs.dfd_host < 0)
return log_error_errno(-errno, errno, "Failed to open \"/\"");
+ turn_into_dependent_mounts(&conf->rootfs);
+
if (conf->rootfs_setup) {
const char *path = conf->rootfs.mount;
- /* The rootfs was set up in another namespace. bind-mount it to
+ /*
+ * The rootfs was set up in another namespace. bind-mount it to
* give us a mount in our own ns so we can pivot_root to it
*/
ret = mount(path, path, "rootfs", MS_BIND, NULL);
return log_trace(0, "Bind mounted container / onto itself");
}
- turn_into_dependent_mounts();
-
ret = run_lxc_hooks(name, "pre-mount", conf, NULL);
if (ret < 0)
return log_error(-1, "Failed to run pre-mount hooks");
__hidden extern int parse_mntopts(const char *mntopts, unsigned long *mntflags, char **mntdata);
__hidden extern int parse_propagationopts(const char *mntopts, unsigned long *pflags);
__hidden extern void tmp_proc_unmount(struct lxc_conf *lxc_conf);
-__hidden extern void turn_into_dependent_mounts(void);
__hidden extern void suggest_default_idmap(void);
__hidden extern FILE *make_anonymous_mount_file(struct lxc_list *mount, bool include_nesting_helpers);
__hidden extern struct lxc_list *sort_cgroup_settings(struct lxc_list *cgroup_settings);