From: Christian Brauner Date: Tue, 2 Jan 2018 23:11:38 +0000 (+0100) Subject: conf: detect if devpts can be mounted with gid=5 X-Git-Tag: lxc-3.0.0.beta1~89^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F2066%2Fhead;p=thirdparty%2Flxc.git conf: detect if devpts can be mounted with gid=5 Closes #2033. Signed-off-by: Christian Brauner --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index f7500511d..9a0360907 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -1416,20 +1416,46 @@ static int setup_pivot_root(const struct lxc_rootfs *rootfs) return 0; } -static int lxc_setup_devpts(int num_pts) +static struct id_map *find_mapped_nsid_entry(struct lxc_conf *conf, unsigned id, + enum idtype idtype) +{ + struct lxc_list *it; + struct id_map *map; + struct id_map *retmap = NULL; + + lxc_list_for_each(it, &conf->id_map) { + map = it->elem; + if (map->idtype != idtype) + continue; + + if (id >= map->nsid && id < map->nsid + map->range) { + retmap = map; + break; + } + } + + return retmap; +} + +static int lxc_setup_devpts(struct lxc_conf *conf) { int ret; - const char *default_devpts_mntopts = "newinstance,ptmxmode=0666,mode=0620,gid=5"; + const char *default_devpts_mntopts; char devpts_mntopts[256]; - if (!num_pts) { + if (conf->pts <= 0) { DEBUG("no new devpts instance will be mounted since no pts " "devices are requested"); return 0; } + if (!find_mapped_nsid_entry(conf, 5, ID_TYPE_GID)) + default_devpts_mntopts = "newinstance,ptmxmode=0666,mode=0620"; + else + default_devpts_mntopts = "newinstance,ptmxmode=0666,mode=0620,gid=5"; + ret = snprintf(devpts_mntopts, sizeof(devpts_mntopts), "%s,max=%d", - default_devpts_mntopts, num_pts); + default_devpts_mntopts, conf->pts); if (ret < 0 || (size_t)ret >= sizeof(devpts_mntopts)) return -1; @@ -1452,7 +1478,7 @@ static int lxc_setup_devpts(int num_pts) } /* Mount new devpts instance. */ - ret = mount("devpts", "/dev/pts", "devpts", MS_MGC_VAL, devpts_mntopts); + ret = mount("devpts", "/dev/pts", "devpts", MS_NOSUID | MS_NOEXEC, devpts_mntopts); if (ret < 0) { SYSERROR("failed to mount new devpts instance"); return -1; @@ -3323,7 +3349,7 @@ int lxc_setup(struct lxc_handler *handler) return -1; } - if (lxc_setup_devpts(lxc_conf->pts)) { + if (lxc_setup_devpts(lxc_conf)) { ERROR("failed to setup the new pts instance"); return -1; } @@ -3731,27 +3757,6 @@ static int run_userns_fn(void *data) return d->fn(d->arg); } -static struct id_map *find_mapped_nsid_entry(struct lxc_conf *conf, unsigned id, - enum idtype idtype) -{ - struct lxc_list *it; - struct id_map *map; - struct id_map *retmap = NULL; - - lxc_list_for_each(it, &conf->id_map) { - map = it->elem; - if (map->idtype != idtype) - continue; - - if (id >= map->nsid && id < map->nsid + map->range) { - retmap = map; - break; - } - } - - return retmap; -} - static struct id_map *mapped_nsid_add(struct lxc_conf *conf, unsigned id, enum idtype idtype) {