The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/1424

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Prevent an endless loop while executing lxc-attach in the background:

The kernel might fire SIGTTOU while an ioctl() in tcsetattr()
is executed. When the ioctl() is resumed and retries,
the signal handler interrupts it again.

We can't configure the TTY to stop sending
the signals in the first place since that
is a modification/write to the TTY already.

Still we clear the TOSTOP flag to prevent further signals.

Command to reproduce the hang:
----------------------------
cat > lxc_hang.sh << EOF
/usr/bin/timeout 5s /usr/bin/lxc-attach -n SOMECONTAINER -- /bin/true
EOF
sh lxc_hang.sh    # hangs
----------------------------

Signed-off-by: Thomas Jarosch <thomas.jaro...@intra2net.com>
From 4dc96430afec0669228e541935640710dffaa9bd Mon Sep 17 00:00:00 2001
From: Thomas Jarosch <thomas.jaro...@intra2net.com>
Date: Thu, 2 Feb 2017 12:48:35 +0100
Subject: [PATCH] lxc_setup_tios(): Ignore SIGTTOU and SIGTTIN signals

Prevent an endless loop while executing lxc-attach in the background:

The kernel might fire SIGTTOU while an ioctl() in tcsetattr()
is executed. When the ioctl() is resumed and retries,
the signal handler interrupts it again.

We can't configure the TTY to stop sending
the signals in the first place since that
is a modification/write to the TTY already.

Still we clear the TOSTOP flag to prevent further signals.

Command to reproduce the hang:
----------------------------
cat > lxc_hang.sh << EOF
/usr/bin/timeout 5s /usr/bin/lxc-attach -n SOMECONTAINER -- /bin/true
EOF
sh lxc_hang.sh    # hangs
----------------------------

Signed-off-by: Thomas Jarosch <thomas.jaro...@intra2net.com>
---
 src/lxc/console.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/lxc/console.c b/src/lxc/console.c
index 908ead0..0cfc9ab 100644
--- a/src/lxc/console.c
+++ b/src/lxc/console.c
@@ -257,6 +257,14 @@ int lxc_setup_tios(int fd, struct termios *oldtios)
                return -1;
        }
 
+       /* ensure we don't end up in an endless loop:
+        * The kernel might fire SIGTTOU while an
+        * ioctl() in tcsetattr() is executed. When the ioctl()
+        * is resumed and retries, the signal handler interrupts it again.
+        */
+       signal (SIGTTIN, SIG_IGN);
+       signal (SIGTTOU, SIG_IGN);
+
        newtios = *oldtios;
 
        /* We use the same settings that ssh does. */
@@ -265,7 +273,7 @@ int lxc_setup_tios(int fd, struct termios *oldtios)
 #ifdef IUCLC
        newtios.c_iflag &= ~IUCLC;
 #endif
-       newtios.c_lflag &= ~(ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHONL);
+       newtios.c_lflag &= ~(TOSTOP | ISIG | ICANON | ECHO | ECHOE | ECHOK | 
ECHONL);
 #ifdef IEXTEN
        newtios.c_lflag &= ~IEXTEN;
 #endif
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to