]> granicus.if.org Git - sudo/commitdiff
Prevent sudo from receiving SIGTTOU when it tries to restore the
authorTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 6 Mar 2017 20:05:17 +0000 (13:05 -0700)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Mon, 6 Mar 2017 20:05:17 +0000 (13:05 -0700)
controlling terminal.  There appears to be a race with the shell
(bash) which we may lose.

src/exec_nopty.c

index c72eb31597653929d250e2a31dc7e8b2e61edc6b..b6826ef70e9d0ec463c30b086a278a21e0e403ab 100644 (file)
@@ -391,11 +391,21 @@ dispatch_signal(struct exec_closure_nopty *ec, int signo, char *signame)
                }
                if (saved_pgrp != -1) {
                    /*
-                    * Restore command's process group if different.
-                    * Otherwise, we cannot resume some shells.
+                    * Restore foreground process group, if different.
+                    * Otherwise, we cannot resume some shells (pdksh).
+                    *
+                    * There appears to be a race with shells that do restore
+                    * the controlling group.  Sudo can receive SIGTTOU
+                    * if the shell has already changed the controlling tty.
                     */
-                   if (saved_pgrp != ppgrp)
+                   if (saved_pgrp != ppgrp) {
+                       sigset_t set, oset;
+                       sigemptyset(&set);
+                       sigaddset(&set, SIGTTOU);
+                       sigprocmask(SIG_BLOCK, &set, &oset);
                        (void)tcsetpgrp(fd, saved_pgrp);
+                       sigprocmask(SIG_SETMASK, &oset, NULL);
+                   }
                    close(fd);
                }
            } else {