components/openssh/patches/047-login_grace_time_watchdog.patch
author Tomas Kuthan <tomas.kuthan@oracle.com>
Wed, 11 Jan 2017 12:12:15 -0800
changeset 7562 2adf9e2cdc69
parent 7059 f2f4b9922ef9
child 7649 69d7508f0d66
permissions -rw-r--r--
25044066 sshd error: session_by_pid: unknown pid when root ssh session exits
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7059
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     1
#
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     2
# Implements watchdog process, which backs up login_grace_time alarm.
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     3
#
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     4
# If the main process is hung in a syscall, SIGALRM is queued but not
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     5
# delivered and the connection stays unauthenticated for too long.
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     6
#
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     7
# Function start_grace_watchdog forks of a watchdog process, that sends the
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     8
# main process a SIGTERM, if it does neither authenticate nor exit before
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
     9
# (login_grace_time + GRACE_WATCHDOG_THRESHOLD).
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    10
# If the main process does not react to SIGTERM, SIGKILL is sent after
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    11
# additional GRACE_WATCHDOG_THRESHOLD seconds.
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    12
#
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    13
# Patch source: in-house
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    14
# Reported to [email protected] as security issue.
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    15
#
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    16
# Per agreement with upstream developers, filed:
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    17
#    https://bugzilla.mindrot.org/show_bug.cgi?id=2615
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    18
#
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    19
diff -pur old/sshd.c new/sshd.c
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    20
--- old/sshd.c
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    21
+++ new/sshd.c
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    22
@@ -252,9 +252,16 @@ Buffer loginmsg;
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    23
 /* Unprivileged user */
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    24
 struct passwd *privsep_pw = NULL;
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    25
 
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    26
+/* Pid of process backing up login_grace_time alarm. */
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    27
+pid_t grace_watchdog_pid = -1;
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    28
+
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    29
+/* Time in seconds */
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    30
+#define	GRACE_WATCHDOG_THRESHOLD 10
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    31
+
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    32
 /* Prototypes for various functions defined later in this file. */
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    33
 void destroy_sensitive_data(void);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    34
 void demote_sensitive_data(void);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    35
+static void stop_grace_watchdog(void);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    36
 
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    37
 #ifdef WITH_SSH1
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    38
 static void do_ssh1_kex(void);
7562
2adf9e2cdc69 25044066 sshd error: session_by_pid: unknown pid when root ssh session exits
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 7059
diff changeset
    39
@@ -369,12 +376,102 @@ grace_alarm_handler(int sig)
7059
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    40
 		signal(SIGTERM, SIG_IGN);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    41
 		kill(0, SIGTERM);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    42
 	}
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    43
+	stop_grace_watchdog();
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    44
 
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    45
 	/* Log error and exit. */
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    46
 	sigdie("Timeout before authentication for %s port %d",
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    47
 	    ssh_remote_ipaddr(active_state), ssh_remote_port(active_state));
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    48
 }
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    49
 
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    50
+static inline void
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    51
+sleep_reliably(unsigned int seconds)
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    52
+{
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    53
+	while (seconds > 0)
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    54
+		seconds = sleep(seconds);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    55
+}
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    56
+
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    57
+/*
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    58
+ * Implements watchdog process, which backs up login_grace_time alarm.
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    59
+ *
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    60
+ * If the main process is hung in a syscall, SIGALRM is queued but not
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    61
+ * delivered and the connection stays unauthenticated for too long.
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    62
+ *
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    63
+ * This function forks off a watchdog process, which sends the main process
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    64
+ * a SIGTERM, if it does neither authenticate nor exit before
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    65
+ * (login_grace_time + GRACE_WATCHDOG_THRESHOLD).
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    66
+ * If the main process does not react to SIGTERM, SIGKILL is sent after
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    67
+ * additional GRACE_WATCHDOG_THRESHOLD seconds.
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    68
+ */
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    69
+static void
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    70
+start_grace_watchdog(int login_grace_time)
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    71
+{
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    72
+	pid_t ppid = getpid();
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    73
+
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    74
+	if (login_grace_time == 0)
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    75
+		return;
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    76
+
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    77
+	if (grace_watchdog_pid != -1) {
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    78
+		error("login_grace_time watchdog process already running");
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    79
+		return;
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    80
+	}
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    81
+
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    82
+	grace_watchdog_pid = fork();
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    83
+	if (grace_watchdog_pid == -1)
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    84
+		fatal("fork of login_grace_time watchdog process failed");
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    85
+	else if (grace_watchdog_pid > 0)
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    86
+		return;
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    87
+
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    88
+	/* child */
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    89
+
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    90
+	/* close open fds, including client socket and startup_pipe */
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    91
+	closefrom(3);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    92
+
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    93
+	/* kill the monitor with SIGTERM after timeout + threshold */
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    94
+	sleep_reliably(login_grace_time + GRACE_WATCHDOG_THRESHOLD);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    95
+	if (getppid() != ppid) {
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    96
+		debug("login_grace_time watchdog still active, "
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    97
+		    "but watched process %d already exited.", (int)ppid);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    98
+		exit(0);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
    99
+	}
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   100
+	error("Timeout before authentication for %s. Killing process %d "
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   101
+	    "with SIGTERM.", ssh_remote_ipaddr(active_state), (int)ppid);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   102
+	kill(ppid, SIGTERM);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   103
+
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   104
+	/* if neccessary, kill it with SIGKILL */
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   105
+	sleep_reliably(GRACE_WATCHDOG_THRESHOLD);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   106
+	if (getppid() != ppid)
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   107
+		exit(0);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   108
+	error("Watched process %d did not respond to SIGTERM. "
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   109
+	    "Killing it with SIGKILL.", (int)ppid);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   110
+	kill(ppid, SIGKILL);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   111
+
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   112
+	/* give up */
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   113
+	sleep_reliably(GRACE_WATCHDOG_THRESHOLD);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   114
+	if (getppid() == ppid) {
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   115
+		error("login_grace_time watchdog failed to kill %d", (int)ppid);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   116
+		exit(255);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   117
+	}
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   118
+	exit(0);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   119
+}
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   120
+
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   121
+/* kill grace watchdog process */
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   122
+static void
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   123
+stop_grace_watchdog()
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   124
+{
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   125
+	if (grace_watchdog_pid == -1) {
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   126
+		debug3("login_grace_time watchdog process not running");
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   127
+		return;
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   128
+	}
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   129
+
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   130
+	kill(grace_watchdog_pid, SIGTERM);
7562
2adf9e2cdc69 25044066 sshd error: session_by_pid: unknown pid when root ssh session exits
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 7059
diff changeset
   131
+	while (waitpid(grace_watchdog_pid, NULL, 0) < 0) {
2adf9e2cdc69 25044066 sshd error: session_by_pid: unknown pid when root ssh session exits
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 7059
diff changeset
   132
+		if (errno == EINTR)
2adf9e2cdc69 25044066 sshd error: session_by_pid: unknown pid when root ssh session exits
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 7059
diff changeset
   133
+			continue;
2adf9e2cdc69 25044066 sshd error: session_by_pid: unknown pid when root ssh session exits
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 7059
diff changeset
   134
+	}
7059
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   135
+	grace_watchdog_pid = -1;
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   136
+}
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   137
+
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   138
+
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   139
 /*
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   140
  * Signal handler for the key regeneration alarm.  Note that this
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   141
  * alarm only occurs in the daemon waiting for connections, and it does not
7562
2adf9e2cdc69 25044066 sshd error: session_by_pid: unknown pid when root ssh session exits
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 7059
diff changeset
   142
@@ -723,6 +820,7 @@ privsep_preauth(Authctxt *authctxt)
7059
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   143
 		/* child */
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   144
 		close(pmonitor->m_sendfd);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   145
 		close(pmonitor->m_log_recvfd);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   146
+		grace_watchdog_pid = -1;
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   147
 
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   148
 		/* Arrange for logging to be sent to the monitor */
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   149
 		set_log_handler(mm_log_handler, pmonitor);
7562
2adf9e2cdc69 25044066 sshd error: session_by_pid: unknown pid when root ssh session exits
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 7059
diff changeset
   150
@@ -2235,8 +2333,10 @@ main(int ac, char **av)
7059
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   151
 	 * are about to discover the bug.
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   152
 	 */
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   153
 	signal(SIGALRM, grace_alarm_handler);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   154
-	if (!debug_flag)
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   155
+	if (!debug_flag) {
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   156
 		alarm(options.login_grace_time);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   157
+		start_grace_watchdog(options.login_grace_time);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   158
+	}
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   159
 
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   160
 	sshd_exchange_identification(ssh, sock_in, sock_out);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   161
 
7562
2adf9e2cdc69 25044066 sshd error: session_by_pid: unknown pid when root ssh session exits
Tomas Kuthan <tomas.kuthan@oracle.com>
parents: 7059
diff changeset
   162
@@ -2302,6 +2402,7 @@ main(int ac, char **av)
7059
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   163
 	 */
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   164
 	alarm(0);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   165
 	signal(SIGALRM, SIG_DFL);
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   166
+	stop_grace_watchdog();
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   167
 	authctxt->authenticated = 1;
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   168
 	if (startup_pipe != -1) {
f2f4b9922ef9 23223069 problem in UTILITY/OPENSSH
Tomas Kuthan <tomas.kuthan@oracle.com>
parents:
diff changeset
   169
 		close(startup_pipe);