]> git.proxmox.com Git - mirror_lxc.git/commitdiff
console: ensure that fd is marked EBADF
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 16 Feb 2018 23:04:30 +0000 (00:04 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 16 Feb 2018 23:13:10 +0000 (00:13 +0100)
If the handler closes the file descriptor for the peer or master fd it is
crucial that we mark it as -EBADF. This will prevent lxc_console_delete()
from calling close() on an already closed file descriptor again. I've
observed the double close in the attach code.

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

index a16466ba3e2394dcc4c5692cd5e1d04a94724b0d..9168cdf9d721a3b040705ad94d861e1426168e28 100644 (file)
@@ -215,16 +215,20 @@ int lxc_console_cb_con(int fd, uint32_t events, void *data,
        if (r <= 0) {
                INFO("Console client on fd %d has exited", fd);
                lxc_mainloop_del_handler(descr, fd);
-               if (fd == console->peer) {
+
+               if (fd == console->master) {
+                       console->master = -EBADF;
+               } else if (fd == console->peer) {
                        if (console->tty_state) {
                                lxc_console_signal_fini(console->tty_state);
                                console->tty_state = NULL;
                        }
-                       console->peer = -1;
-                       close(fd);
-                       return 0;
+                       console->peer = -EBADF;
+               } else {
+                       ERROR("Handler received unexpected file descriptor");
                }
                close(fd);
+
                return LXC_MAINLOOP_CLOSE;
        }