From c06a0555e9cea7984eb1584c82ba310c2924956f Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Sat, 17 Feb 2018 00:04:30 +0100 Subject: [PATCH] console: ensure that fd is marked EBADF 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 --- src/lxc/console.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lxc/console.c b/src/lxc/console.c index a16466ba3..9168cdf9d 100644 --- a/src/lxc/console.c +++ b/src/lxc/console.c @@ -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; } -- 2.47.2