|
Jakub Jelen |
44fc97 |
diff --git a/monitor_wrap.c b/monitor_wrap.c
|
|
Jakub Jelen |
44fc97 |
index 89a1762..fe98e08 100644
|
|
Jakub Jelen |
44fc97 |
--- a/monitor_wrap.c
|
|
Jakub Jelen |
44fc97 |
+++ b/monitor_wrap.c
|
|
Jakub Jelen |
44fc97 |
@@ -1251,4 +1251,48 @@ mm_audit_destroy_sensitive_data(const char *fp, pid_t pid, uid_t uid)
|
|
Jakub Jelen |
44fc97 |
mm_request_send(pmonitor->m_recvfd, MONITOR_REQ_AUDIT_SERVER_KEY_FREE, &m);
|
|
Jakub Jelen |
44fc97 |
buffer_free(&m);
|
|
Jakub Jelen |
44fc97 |
}
|
|
Jakub Jelen |
44fc97 |
+
|
|
Jakub Jelen |
44fc97 |
+int mm_forward_audit_messages(int fdin)
|
|
Jakub Jelen |
44fc97 |
+{
|
|
Jakub Jelen |
44fc97 |
+ u_char buf[4];
|
|
Jakub Jelen |
44fc97 |
+ u_int blen, msg_len;
|
|
Jakub Jelen |
44fc97 |
+ Buffer m;
|
|
Jakub Jelen |
44fc97 |
+ int ret = 0;
|
|
Jakub Jelen |
44fc97 |
+
|
|
Jakub Jelen |
44fc97 |
+ debug3("%s: entering", __func__);
|
|
Jakub Jelen |
44fc97 |
+ buffer_init(&m);
|
|
Jakub Jelen |
44fc97 |
+ do {
|
|
Jakub Jelen |
44fc97 |
+ blen = atomicio(read, fdin, buf, sizeof(buf));
|
|
Jakub Jelen |
44fc97 |
+ if (blen == 0) /* closed pipe */
|
|
Jakub Jelen |
44fc97 |
+ break;
|
|
Jakub Jelen |
44fc97 |
+ if (blen != sizeof(buf)) {
|
|
Jakub Jelen |
44fc97 |
+ error("%s: Failed to read the buffer from child", __func__);
|
|
Jakub Jelen |
44fc97 |
+ ret = -1;
|
|
Jakub Jelen |
44fc97 |
+ break;
|
|
Jakub Jelen |
44fc97 |
+ }
|
|
Jakub Jelen |
44fc97 |
+
|
|
Jakub Jelen |
44fc97 |
+ msg_len = get_u32(buf);
|
|
Jakub Jelen |
44fc97 |
+ if (msg_len > 256 * 1024)
|
|
Jakub Jelen |
44fc97 |
+ fatal("%s: read: bad msg_len %d", __func__, msg_len);
|
|
Jakub Jelen |
44fc97 |
+ buffer_clear(&m);
|
|
Jakub Jelen |
44fc97 |
+ buffer_append_space(&m, msg_len);
|
|
Jakub Jelen |
44fc97 |
+ if (atomicio(read, fdin, buffer_ptr(&m), msg_len) != msg_len) {
|
|
Jakub Jelen |
44fc97 |
+ error("%s: Failed to read the the buffer conent from the child", __func__);
|
|
Jakub Jelen |
44fc97 |
+ ret = -1;
|
|
Jakub Jelen |
44fc97 |
+ break;
|
|
Jakub Jelen |
44fc97 |
+ }
|
|
Jakub Jelen |
44fc97 |
+ if (atomicio(vwrite, pmonitor->m_recvfd, buf, blen) != blen ||
|
|
Jakub Jelen |
44fc97 |
+ atomicio(vwrite, pmonitor->m_recvfd, buffer_ptr(&m), msg_len) != msg_len) {
|
|
Jakub Jelen |
44fc97 |
+ error("%s: Failed to write the messag to the monitor", __func__);
|
|
Jakub Jelen |
44fc97 |
+ ret = -1;
|
|
Jakub Jelen |
44fc97 |
+ break;
|
|
Jakub Jelen |
44fc97 |
+ }
|
|
Jakub Jelen |
44fc97 |
+ } while (1);
|
|
Jakub Jelen |
44fc97 |
+ buffer_free(&m);
|
|
Jakub Jelen |
44fc97 |
+ return ret;
|
|
Jakub Jelen |
44fc97 |
+}
|
|
Jakub Jelen |
44fc97 |
+void mm_set_monitor_pipe(int fd)
|
|
Jakub Jelen |
44fc97 |
+{
|
|
Jakub Jelen |
44fc97 |
+ pmonitor->m_recvfd = fd;
|
|
Jakub Jelen |
44fc97 |
+}
|
|
Jakub Jelen |
44fc97 |
#endif /* SSH_AUDIT_EVENTS */
|
|
Jakub Jelen |
44fc97 |
diff --git a/monitor_wrap.h b/monitor_wrap.h
|
|
Jakub Jelen |
44fc97 |
index e73134e..fbfe395 100644
|
|
Jakub Jelen |
44fc97 |
--- a/monitor_wrap.h
|
|
Jakub Jelen |
44fc97 |
+++ b/monitor_wrap.h
|
|
Jakub Jelen |
44fc97 |
@@ -86,6 +86,8 @@ void mm_audit_unsupported_body(int);
|
|
Jakub Jelen |
44fc97 |
void mm_audit_kex_body(int, char *, char *, char *, char *, pid_t, uid_t);
|
|
Jakub Jelen |
44fc97 |
void mm_audit_session_key_free_body(int, pid_t, uid_t);
|
|
Jakub Jelen |
44fc97 |
void mm_audit_destroy_sensitive_data(const char *, pid_t, uid_t);
|
|
Jakub Jelen |
44fc97 |
+int mm_forward_audit_messages(int);
|
|
Jakub Jelen |
44fc97 |
+void mm_set_monitor_pipe(int);
|
|
Jakub Jelen |
44fc97 |
#endif
|
|
Jakub Jelen |
44fc97 |
|
|
Jakub Jelen |
44fc97 |
struct Session;
|
|
Jakub Jelen |
44fc97 |
diff --git a/session.c b/session.c
|
|
Jakub Jelen |
44fc97 |
index 8949fd1..9afb764 100644
|
|
Jakub Jelen |
44fc97 |
--- a/session.c
|
|
Jakub Jelen |
44fc97 |
+++ b/session.c
|
|
Jakub Jelen |
44fc97 |
@@ -159,6 +159,10 @@ static Session *sessions = NULL;
|
|
Jakub Jelen |
44fc97 |
login_cap_t *lc;
|
|
Jakub Jelen |
44fc97 |
#endif
|
|
Jakub Jelen |
44fc97 |
|
|
Jakub Jelen |
44fc97 |
+#ifdef SSH_AUDIT_EVENTS
|
|
Jakub Jelen |
44fc97 |
+int paudit[2];
|
|
Jakub Jelen |
44fc97 |
+#endif
|
|
Jakub Jelen |
44fc97 |
+
|
|
Jakub Jelen |
44fc97 |
static int is_child = 0;
|
|
Jakub Jelen |
13073f |
static int in_chroot = 0;
|
|
Jakub Jelen |
44fc97 |
static int have_dev_log = 1;
|
|
Jakub Jelen |
44fc97 |
@@ -875,6 +879,8 @@ do_exec(Session *s, const char *command)
|
|
Jakub Jelen |
44fc97 |
}
|
|
Jakub Jelen |
44fc97 |
if (s->command != NULL && s->ptyfd == -1)
|
|
Jakub Jelen |
44fc97 |
s->command_handle = PRIVSEP(audit_run_command(s->command));
|
|
Jakub Jelen |
44fc97 |
+ if (pipe(paudit) < 0)
|
|
Jakub Jelen |
44fc97 |
+ fatal("pipe: %s", strerror(errno));
|
|
Jakub Jelen |
44fc97 |
#endif
|
|
Jakub Jelen |
44fc97 |
if (s->ttyfd != -1)
|
|
Jakub Jelen |
44fc97 |
ret = do_exec_pty(s, command);
|
|
Jakub Jelen |
44fc97 |
@@ -890,6 +896,20 @@ do_exec(Session *s, const char *command)
|
|
Jakub Jelen |
44fc97 |
*/
|
|
Jakub Jelen |
44fc97 |
buffer_clear(&loginmsg);
|
|
Jakub Jelen |
44fc97 |
|
|
Jakub Jelen |
44fc97 |
+#ifdef SSH_AUDIT_EVENTS
|
|
Jakub Jelen |
44fc97 |
+ close(paudit[1]);
|
|
Jakub Jelen |
44fc97 |
+ if (use_privsep && ret == 0) {
|
|
Jakub Jelen |
44fc97 |
+ /*
|
|
Jakub Jelen |
44fc97 |
+ * Read the audit messages from forked child and send them
|
|
Jakub Jelen |
44fc97 |
+ * back to monitor. We don't want to communicate directly,
|
|
Jakub Jelen |
44fc97 |
+ * because the messages might get mixed up.
|
|
Jakub Jelen |
44fc97 |
+ * Continue after the pipe gets closed (all messages sent).
|
|
Jakub Jelen |
44fc97 |
+ */
|
|
Jakub Jelen |
44fc97 |
+ ret = mm_forward_audit_messages(paudit[0]);
|
|
Jakub Jelen |
44fc97 |
+ }
|
|
Jakub Jelen |
44fc97 |
+ close(paudit[0]);
|
|
Jakub Jelen |
44fc97 |
+#endif /* SSH_AUDIT_EVENTS */
|
|
Jakub Jelen |
44fc97 |
+
|
|
Jakub Jelen |
44fc97 |
return ret;
|
|
Jakub Jelen |
44fc97 |
}
|
|
Jakub Jelen |
44fc97 |
|
|
Jakub Jelen |
44fc97 |
@@ -1707,12 +1727,28 @@ do_child(Session *s, const char *command)
|
|
Jakub Jelen |
44fc97 |
struct passwd *pw = s->pw;
|
|
Jakub Jelen |
44fc97 |
int r = 0;
|
|
Jakub Jelen |
44fc97 |
|
|
Jakub Jelen |
44fc97 |
+#ifdef SSH_AUDIT_EVENTS
|
|
Jakub Jelen |
44fc97 |
+ int pparent = paudit[1];
|
|
Jakub Jelen |
44fc97 |
+ close(paudit[0]);
|
|
Jakub Jelen |
44fc97 |
+ /* Hack the monitor pipe to avoid race condition with parent */
|
|
Jakub Jelen |
44fc97 |
+ if (use_privsep)
|
|
Jakub Jelen |
44fc97 |
+ mm_set_monitor_pipe(pparent);
|
|
Jakub Jelen |
44fc97 |
+#endif
|
|
Jakub Jelen |
44fc97 |
+
|
|
Jakub Jelen |
44fc97 |
/* remove hostkey from the child's memory */
|
|
Jakub Jelen |
44fc97 |
- destroy_sensitive_data(1);
|
|
Jakub Jelen |
44fc97 |
- /* Don't audit this - both us and the parent would be talking to the
|
|
Jakub Jelen |
44fc97 |
- monitor over a single socket, with no synchronization. */
|
|
Jakub Jelen |
44fc97 |
+ destroy_sensitive_data(use_privsep);
|
|
Jakub Jelen |
44fc97 |
+ /*
|
|
Jakub Jelen |
44fc97 |
+ * We can audit this, because wer hacked the pipe to direct the
|
|
Jakub Jelen |
44fc97 |
+ * messages over postauth child. But this message requires answer
|
|
Jakub Jelen |
44fc97 |
+ * which we can't do using one-way pipe.
|
|
Jakub Jelen |
44fc97 |
+ */
|
|
Jakub Jelen |
44fc97 |
packet_destroy_all(0, 1);
|
|
Jakub Jelen |
44fc97 |
|
|
Jakub Jelen |
44fc97 |
+#ifdef SSH_AUDIT_EVENTS
|
|
Jakub Jelen |
44fc97 |
+ /* Notify parent that we are done */
|
|
Jakub Jelen |
44fc97 |
+ close(pparent);
|
|
Jakub Jelen |
44fc97 |
+#endif
|
|
Jakub Jelen |
44fc97 |
+
|
|
Jakub Jelen |
44fc97 |
/* Force a password change */
|
|
Jakub Jelen |
44fc97 |
if (s->authctxt->force_pwchange) {
|
|
Jakub Jelen |
44fc97 |
do_setusercontext(pw);
|