From 2028f49dabb94bd56a85a7be16141bee4853aae6 Mon Sep 17 00:00:00 2001 From: Geoffrey Thomas Date: Mon, 19 Oct 2015 19:33:28 +0530 Subject: pt_chown: Clear any signal mask inherited from the parent process. If grantpt() is called from a thread that is masking signals (for instance, from a program using signalfd or using a dedicated signal-handling thread), then that mask will get inherited to pt_chown. This means that signals like SIGINT will not interrup pt_chown, so if it hangs (e.g., because getgrnam("tty") hangs on a remote name service), Ctrl-C will terminate the parent process but leave pt_chown around. Since it's setuid, it's hard to kill any other way. It is safe for pt_chown to unmask all signals, because grantpt() can be (and usually is) called from an unprivileged process with all signals unmasked. --- login/programs/pt_chown.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'login/programs') diff --git a/login/programs/pt_chown.c b/login/programs/pt_chown.c index e8d4716996..4f67af7d37 100644 --- a/login/programs/pt_chown.c +++ b/login/programs/pt_chown.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -148,6 +149,11 @@ main (int argc, char *argv[]) uid_t euid = geteuid (); uid_t uid = getuid (); int remaining; + sigset_t signalset; + + /* Clear any signal mask from the parent process. */ + sigemptyset (&signalset); + sigprocmask (SIG_SETMASK, &signalset, NULL); if (argc == 1 && euid == 0) { -- cgit 1.4.1