]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
attach: close lsm label file descriptor 1347/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 8 Dec 2016 22:18:35 +0000 (23:18 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 8 Dec 2016 22:20:08 +0000 (23:20 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/attach.c

index 253415242b5cdf925890ed8f8aab1ed3c992bc14..f44be85c36356fbe9da0ce142e425cff22af427a 100644 (file)
@@ -932,7 +932,8 @@ int lxc_attach(const char* name, const char* lxcpath, lxc_attach_exec_t exec_fun
 
                /* Open LSM fd and send it to child. */
                if ((options->namespaces & CLONE_NEWNS) && (options->attach_flags & LXC_ATTACH_LSM) && init_ctx->lsm_label) {
-                       int on_exec, labelfd;
+                       int on_exec;
+                       int labelfd = -1;
                        on_exec = options->attach_flags & LXC_ATTACH_LSM_EXEC ? 1 : 0;
                        /* Open fd for the LSM security module. */
                        labelfd = lsm_openat(procfd, attached_pid, on_exec);
@@ -941,12 +942,15 @@ int lxc_attach(const char* name, const char* lxcpath, lxc_attach_exec_t exec_fun
 
                        /* Send child fd of the LSM security module to write to. */
                        ret = lxc_abstract_unix_send_fd(ipc_sockets[0], labelfd, NULL, 0);
+                       close(labelfd);
                        if (ret <= 0) {
                                ERROR("Intended to send file descriptor %d: %s.", labelfd, strerror(errno));
                                goto on_error;
                        }
                }
 
+               if (procfd >= 0)
+                       close(procfd);
                /* Now shut down communication with child, we're done. */
                shutdown(ipc_sockets[0], SHUT_RDWR);
                close(ipc_sockets[0]);