]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
start: make us dumpable
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 22 Dec 2017 16:11:45 +0000 (17:11 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 2 Jan 2018 00:02:13 +0000 (01:02 +0100)
When set set{u,g}id() the kernel will make us undumpable. This is unnecessary
since we can guarantee that whatever is running inside the child process at
this point this is fully trusted by the parent. Making us dumpable let's users
use debuggers on the child process before the exec as well and also allows us
to open /proc/<child-pid> files in lieu of the child.
Note, that we only need to perform the prctl(PR_SET_DUMPABLE, ...) if our
effective uid on the host is not 0. If our effective uid on the host is 0 then
we will keep all capabilities in the child user namespace across set{g,u}id().

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/start.c

index 0814cacc72c36afe5a369f908c9ce7bf262a18f4..a89e750c56cc6913b4565c7cced128a757f54c03 100644 (file)
@@ -961,14 +961,22 @@ static int do_start(void *data)
         * privilege over our namespace.
         */
        if (!lxc_list_empty(&handler->conf->id_map)) {
-               if (lxc_switch_uid_gid(0, 0) < 0)
+               ret = lxc_switch_uid_gid(0, 0);
+               if (ret < 0)
                        goto out_warn_father;
 
                /* Drop groups only after we switched to a valid gid in the new
                 * user namespace.
                 */
-               if (lxc_setgroups(0, NULL) < 0)
+               ret = lxc_setgroups(0, NULL);
+               if (ret < 0)
                        goto out_warn_father;
+
+               if (!handler->am_root) {
+                       ret = prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
+                       if (ret < 0)
+                               goto out_warn_father;
+               }
        }
 
        if (access(handler->lxcpath, X_OK)) {