2017-01-02 14:42:13 +00:00
|
|
|
diff -up openssh-7.4p1/monitor_wrap.c.audit-race openssh-7.4p1/monitor_wrap.c
|
|
|
|
--- openssh-7.4p1/monitor_wrap.c.audit-race 2016-12-23 16:35:52.694685771 +0100
|
|
|
|
+++ openssh-7.4p1/monitor_wrap.c 2016-12-23 16:35:52.697685772 +0100
|
2018-08-24 20:40:20 +00:00
|
|
|
@@ -1107,4 +1107,50 @@ mm_audit_destroy_sensitive_data(const ch
|
|
|
|
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_SERVER_KEY_FREE, m);
|
|
|
|
sshbuf_free(m);
|
2016-02-22 10:47:20 +00:00
|
|
|
}
|
|
|
|
+
|
|
|
|
+int mm_forward_audit_messages(int fdin)
|
|
|
|
+{
|
|
|
|
+ u_char buf[4];
|
|
|
|
+ u_int blen, msg_len;
|
2018-08-24 20:40:20 +00:00
|
|
|
+ struct sshbuf *m;
|
|
|
|
+ int r, ret = 0;
|
2016-02-22 10:47:20 +00:00
|
|
|
+
|
|
|
|
+ debug3("%s: entering", __func__);
|
2018-08-24 20:40:20 +00:00
|
|
|
+ if ((m = sshbuf_new()) == NULL)
|
|
|
|
+ fatal("%s: sshbuf_new failed", __func__);
|
2016-02-22 10:47:20 +00:00
|
|
|
+ do {
|
|
|
|
+ blen = atomicio(read, fdin, buf, sizeof(buf));
|
|
|
|
+ if (blen == 0) /* closed pipe */
|
|
|
|
+ break;
|
|
|
|
+ if (blen != sizeof(buf)) {
|
|
|
|
+ error("%s: Failed to read the buffer from child", __func__);
|
|
|
|
+ ret = -1;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ msg_len = get_u32(buf);
|
|
|
|
+ if (msg_len > 256 * 1024)
|
|
|
|
+ fatal("%s: read: bad msg_len %d", __func__, msg_len);
|
2018-08-24 20:40:20 +00:00
|
|
|
+ sshbuf_reset(m);
|
|
|
|
+ if ((r = sshbuf_reserve(m, msg_len, NULL)) != 0)
|
|
|
|
+ fatal("%s: buffer error: %s", __func__, ssh_err(r));
|
|
|
|
+ if (atomicio(read, fdin, sshbuf_mutable_ptr(m), msg_len) != msg_len) {
|
2016-12-15 13:29:36 +00:00
|
|
|
+ error("%s: Failed to read the the buffer content from the child", __func__);
|
2016-02-22 10:47:20 +00:00
|
|
|
+ ret = -1;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ if (atomicio(vwrite, pmonitor->m_recvfd, buf, blen) != blen ||
|
2018-08-24 20:40:20 +00:00
|
|
|
+ atomicio(vwrite, pmonitor->m_recvfd, sshbuf_mutable_ptr(m), msg_len) != msg_len) {
|
2016-12-15 13:29:36 +00:00
|
|
|
+ error("%s: Failed to write the message to the monitor", __func__);
|
2016-02-22 10:47:20 +00:00
|
|
|
+ ret = -1;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ } while (1);
|
2018-08-24 20:40:20 +00:00
|
|
|
+ sshbuf_free(m);
|
2016-02-22 10:47:20 +00:00
|
|
|
+ return ret;
|
|
|
|
+}
|
|
|
|
+void mm_set_monitor_pipe(int fd)
|
|
|
|
+{
|
|
|
|
+ pmonitor->m_recvfd = fd;
|
|
|
|
+}
|
|
|
|
#endif /* SSH_AUDIT_EVENTS */
|
2017-01-02 14:42:13 +00:00
|
|
|
diff -up openssh-7.4p1/monitor_wrap.h.audit-race openssh-7.4p1/monitor_wrap.h
|
|
|
|
--- openssh-7.4p1/monitor_wrap.h.audit-race 2016-12-23 16:35:52.694685771 +0100
|
|
|
|
+++ openssh-7.4p1/monitor_wrap.h 2016-12-23 16:35:52.698685772 +0100
|
|
|
|
@@ -83,6 +83,8 @@ void mm_audit_unsupported_body(int);
|
2016-02-22 10:47:20 +00:00
|
|
|
void mm_audit_kex_body(int, char *, char *, char *, char *, pid_t, uid_t);
|
|
|
|
void mm_audit_session_key_free_body(int, pid_t, uid_t);
|
|
|
|
void mm_audit_destroy_sensitive_data(const char *, pid_t, uid_t);
|
|
|
|
+int mm_forward_audit_messages(int);
|
|
|
|
+void mm_set_monitor_pipe(int);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct Session;
|
2017-01-02 14:42:13 +00:00
|
|
|
diff -up openssh-7.4p1/session.c.audit-race openssh-7.4p1/session.c
|
|
|
|
--- openssh-7.4p1/session.c.audit-race 2016-12-23 16:35:52.695685771 +0100
|
|
|
|
+++ openssh-7.4p1/session.c 2016-12-23 16:37:26.339730596 +0100
|
|
|
|
@@ -162,6 +162,10 @@ static Session *sessions = NULL;
|
2016-02-22 10:47:20 +00:00
|
|
|
login_cap_t *lc;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
+#ifdef SSH_AUDIT_EVENTS
|
|
|
|
+int paudit[2];
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
static int is_child = 0;
|
2016-02-19 13:42:33 +00:00
|
|
|
static int in_chroot = 0;
|
2016-02-22 10:47:20 +00:00
|
|
|
static int have_dev_log = 1;
|
2017-01-02 14:42:13 +00:00
|
|
|
@@ -289,6 +293,8 @@ xauth_valid_string(const char *s)
|
|
|
|
return 1;
|
2016-12-15 13:29:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+void child_destory_sensitive_data();
|
|
|
|
+
|
|
|
|
#define USE_PIPES 1
|
|
|
|
/*
|
|
|
|
* This is called to fork and execute a command when we have no tty. This
|
2017-01-02 14:42:13 +00:00
|
|
|
@@ -424,6 +430,8 @@ do_exec_no_pty(Session *s, const char *c
|
2018-03-27 14:52:07 +00:00
|
|
|
close(err[0]);
|
2016-12-15 13:29:36 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
+ child_destory_sensitive_data();
|
|
|
|
+
|
|
|
|
/* Do processing for the child (exec command etc). */
|
2017-09-26 12:04:45 +00:00
|
|
|
do_child(ssh, s, command);
|
2016-12-15 13:29:36 +00:00
|
|
|
/* NOTREACHED */
|
2017-01-02 14:42:13 +00:00
|
|
|
@@ -547,6 +555,9 @@ do_exec_pty(Session *s, const char *comm
|
2016-12-15 13:29:36 +00:00
|
|
|
/* Close the extra descriptor for the pseudo tty. */
|
|
|
|
close(ttyfd);
|
|
|
|
|
|
|
|
+ /* Do this early, so we will not block large MOTDs */
|
|
|
|
+ child_destory_sensitive_data();
|
|
|
|
+
|
|
|
|
/* record login, etc. similar to login(1) */
|
2018-03-27 14:52:07 +00:00
|
|
|
#ifndef HAVE_OSF_SIA
|
|
|
|
do_login(ssh, s, command);
|
2017-01-02 14:42:13 +00:00
|
|
|
@@ -717,6 +728,8 @@ do_exec(Session *s, const char *command)
|
2016-02-22 10:47:20 +00:00
|
|
|
}
|
|
|
|
if (s->command != NULL && s->ptyfd == -1)
|
|
|
|
s->command_handle = PRIVSEP(audit_run_command(s->command));
|
|
|
|
+ if (pipe(paudit) < 0)
|
|
|
|
+ fatal("pipe: %s", strerror(errno));
|
|
|
|
#endif
|
|
|
|
if (s->ttyfd != -1)
|
2017-09-26 12:04:45 +00:00
|
|
|
ret = do_exec_pty(ssh, s, command);
|
2017-01-02 14:42:13 +00:00
|
|
|
@@ -732,6 +745,20 @@ do_exec(Session *s, const char *command)
|
2016-02-22 10:47:20 +00:00
|
|
|
*/
|
2018-08-24 20:40:20 +00:00
|
|
|
sshbuf_reset(loginmsg);
|
2016-02-22 10:47:20 +00:00
|
|
|
|
|
|
|
+#ifdef SSH_AUDIT_EVENTS
|
|
|
|
+ close(paudit[1]);
|
|
|
|
+ if (use_privsep && ret == 0) {
|
|
|
|
+ /*
|
|
|
|
+ * Read the audit messages from forked child and send them
|
|
|
|
+ * back to monitor. We don't want to communicate directly,
|
|
|
|
+ * because the messages might get mixed up.
|
|
|
|
+ * Continue after the pipe gets closed (all messages sent).
|
|
|
|
+ */
|
|
|
|
+ ret = mm_forward_audit_messages(paudit[0]);
|
|
|
|
+ }
|
|
|
|
+ close(paudit[0]);
|
|
|
|
+#endif /* SSH_AUDIT_EVENTS */
|
|
|
|
+
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-09-26 12:04:45 +00:00
|
|
|
@@ -1538,6 +1565,34 @@ child_close_fds(void)
|
2016-12-15 13:29:36 +00:00
|
|
|
endpwent();
|
|
|
|
}
|
2016-02-22 10:47:20 +00:00
|
|
|
|
2016-12-15 13:29:36 +00:00
|
|
|
+void
|
|
|
|
+child_destory_sensitive_data()
|
|
|
|
+{
|
2016-02-22 10:47:20 +00:00
|
|
|
+#ifdef SSH_AUDIT_EVENTS
|
|
|
|
+ int pparent = paudit[1];
|
|
|
|
+ close(paudit[0]);
|
|
|
|
+ /* Hack the monitor pipe to avoid race condition with parent */
|
|
|
|
+ if (use_privsep)
|
|
|
|
+ mm_set_monitor_pipe(pparent);
|
|
|
|
+#endif
|
|
|
|
+
|
2016-12-15 13:29:36 +00:00
|
|
|
+ /* remove hostkey from the child's memory */
|
2016-02-22 10:47:20 +00:00
|
|
|
+ destroy_sensitive_data(use_privsep);
|
|
|
|
+ /*
|
2016-12-15 13:29:36 +00:00
|
|
|
+ * We can audit this, because we hacked the pipe to direct the
|
2016-02-22 10:47:20 +00:00
|
|
|
+ * messages over postauth child. But this message requires answer
|
|
|
|
+ * which we can't do using one-way pipe.
|
|
|
|
+ */
|
2016-12-15 13:29:36 +00:00
|
|
|
+ packet_destroy_all(0, 1);
|
2017-09-26 12:04:45 +00:00
|
|
|
+ /* XXX this will clean the rest but should not audit anymore */
|
|
|
|
+ /* packet_clear_keys(); */
|
2016-12-15 13:29:36 +00:00
|
|
|
+
|
2016-02-22 10:47:20 +00:00
|
|
|
+#ifdef SSH_AUDIT_EVENTS
|
|
|
|
+ /* Notify parent that we are done */
|
|
|
|
+ close(pparent);
|
|
|
|
+#endif
|
2016-12-15 13:29:36 +00:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
/*
|
|
|
|
* Performs common processing for the child, such as setting up the
|
|
|
|
* environment, closing extra file descriptors, setting the user and group
|
2017-09-26 12:04:45 +00:00
|
|
|
@@ -1554,13 +1608,6 @@ do_child(Session *s, const char *command
|
2016-12-15 13:29:36 +00:00
|
|
|
struct passwd *pw = s->pw;
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
- /* remove hostkey from the child's memory */
|
|
|
|
- destroy_sensitive_data(1);
|
2017-09-26 12:04:45 +00:00
|
|
|
- packet_clear_keys();
|
2016-12-15 13:29:36 +00:00
|
|
|
- /* Don't audit this - both us and the parent would be talking to the
|
|
|
|
- monitor over a single socket, with no synchronization. */
|
|
|
|
- packet_destroy_all(0, 1);
|
|
|
|
-
|
2016-02-22 10:47:20 +00:00
|
|
|
/* Force a password change */
|
|
|
|
if (s->authctxt->force_pwchange) {
|
|
|
|
do_setusercontext(pw);
|