]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf: fix devpts mounting when fully unprivileged 2560/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 21 Aug 2018 12:16:09 +0000 (14:16 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 21 Aug 2018 14:16:36 +0000 (16:16 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c

index 9ce6689df6193a9a04580358dda75c9878f6fdec..dfca5923acea570ef8bfd48ebfd91383b607dc2f 100644 (file)
@@ -1625,8 +1625,10 @@ static const struct id_map *find_mapped_nsid_entry(struct lxc_conf *conf,
 static int lxc_setup_devpts(struct lxc_conf *conf)
 {
        int ret;
-       char default_devpts_mntopts[] = "gid=5,newinstance,ptmxmode=0666,mode=0620";
+       char **opts;
        char devpts_mntopts[256];
+       char *mntopt_sets[5];
+       char default_devpts_mntopts[256] = "gid=5,newinstance,ptmxmode=0666,mode=0620";
 
        if (conf->pty_max <= 0) {
                DEBUG("No new devpts instance will be mounted since no pts "
@@ -1652,29 +1654,33 @@ static int lxc_setup_devpts(struct lxc_conf *conf)
                return -1;
        }
 
-       /* mount new devpts instance */
-       ret = mount("devpts", "/dev/pts", "devpts", MS_NOSUID | MS_NOEXEC, devpts_mntopts);
-       if (ret < 0) {
-               /* try mounting without "max" */
-               if (errno == EINVAL) {
-                       devpts_mntopts[sizeof(default_devpts_mntopts) - 1] = '\0';
-                       ret = mount("devpts", "/dev/pts", "devpts",
-                                   MS_NOSUID | MS_NOEXEC, devpts_mntopts);
-                       if (ret < 0) {
-                               SYSERROR("Failed to mount new devpts instance");
-                               return -1;
-                       }
-               }
+       /* gid=5 && max= */
+       mntopt_sets[0] = devpts_mntopts;
 
-               /* try mounting without gid=5 */
-               ret = mount("devpts", "/dev/pts", "devpts", MS_NOSUID | MS_NOEXEC,
-                           devpts_mntopts + sizeof("gid=5"));
-               if (ret < 0) {
-                       SYSERROR("Failed to mount new devpts instance");
-                       return -1;
-               }
+       /* !gid=5 && max= */
+       mntopt_sets[1] = devpts_mntopts + sizeof("gid=5");
+
+       /* gid=5 && !max= */
+       mntopt_sets[2] = default_devpts_mntopts;
+
+       /* !gid=5 && !max= */
+       mntopt_sets[3] = default_devpts_mntopts + sizeof("gid=5");
+
+       /* end */
+       mntopt_sets[4] = NULL;
+
+       for (ret = -1, opts = mntopt_sets; opts && *opts; opts++) {
+               /* mount new devpts instance */
+               ret = mount("devpts", "/dev/pts", "devpts", MS_NOSUID | MS_NOEXEC, *opts);
+               if (ret == 0)
+                       break;
+       }
+
+       if (ret < 0) {
+               SYSERROR("Failed to mount new devpts instance");
+               return -1;
        }
-       DEBUG("Mount new devpts instance with options \"%s\"", devpts_mntopts);
+       DEBUG("Mount new devpts instance with options \"%s\"", *opts);
 
        /* Remove any pre-existing /dev/ptmx file. */
        ret = remove("/dev/ptmx");