upstream: reap the pre-auth [net] child if it hangs up during privsep
message sending, not just receiving OpenBSD-Commit-ID: f7341605bf08c4c15830910446e6775323f2f8cb
This commit is contained in:
parent
ef878d5879
commit
90fb801e2d
|
@ -1,4 +1,4 @@
|
||||||
/* $OpenBSD: monitor_wrap.c,v 1.133 2024/06/11 00:44:52 djm Exp $ */
|
/* $OpenBSD: monitor_wrap.c,v 1.134 2024/06/11 02:00:30 djm Exp $ */
|
||||||
/*
|
/*
|
||||||
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
|
* Copyright 2002 Niels Provos <provos@citi.umich.edu>
|
||||||
* Copyright 2002 Markus Friedl <markus@openbsd.org>
|
* Copyright 2002 Markus Friedl <markus@openbsd.org>
|
||||||
|
@ -121,24 +121,6 @@ mm_is_monitor(void)
|
||||||
return (pmonitor && pmonitor->m_pid > 0);
|
return (pmonitor && pmonitor->m_pid > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
mm_request_send(int sock, enum monitor_reqtype type, struct sshbuf *m)
|
|
||||||
{
|
|
||||||
size_t mlen = sshbuf_len(m);
|
|
||||||
u_char buf[5];
|
|
||||||
|
|
||||||
debug3_f("entering, type %d", type);
|
|
||||||
|
|
||||||
if (mlen >= 0xffffffff)
|
|
||||||
fatal_f("bad length %zu", mlen);
|
|
||||||
POKE_U32(buf, mlen + 1);
|
|
||||||
buf[4] = (u_char) type; /* 1st byte of payload is mesg-type */
|
|
||||||
if (atomicio(vwrite, sock, buf, sizeof(buf)) != sizeof(buf))
|
|
||||||
fatal_f("write: %s", strerror(errno));
|
|
||||||
if (atomicio(vwrite, sock, sshbuf_mutable_ptr(m), mlen) != mlen)
|
|
||||||
fatal_f("write: %s", strerror(errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mm_reap(void)
|
mm_reap(void)
|
||||||
{
|
{
|
||||||
|
@ -170,12 +152,42 @@ mm_reap(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mm_request_send(int sock, enum monitor_reqtype type, struct sshbuf *m)
|
||||||
|
{
|
||||||
|
size_t mlen = sshbuf_len(m);
|
||||||
|
u_char buf[5];
|
||||||
|
|
||||||
|
debug3_f("entering, type %d", type);
|
||||||
|
|
||||||
|
if (mlen >= 0xffffffff)
|
||||||
|
fatal_f("bad length %zu", mlen);
|
||||||
|
POKE_U32(buf, mlen + 1);
|
||||||
|
buf[4] = (u_char) type; /* 1st byte of payload is mesg-type */
|
||||||
|
if (atomicio(vwrite, sock, buf, sizeof(buf)) != sizeof(buf)) {
|
||||||
|
if (errno == EPIPE) {
|
||||||
|
debug3_f("monitor fd closed (header)");
|
||||||
|
mm_reap();
|
||||||
|
cleanup_exit(255);
|
||||||
|
}
|
||||||
|
fatal_f("write: %s", strerror(errno));
|
||||||
|
}
|
||||||
|
if (atomicio(vwrite, sock, sshbuf_mutable_ptr(m), mlen) != mlen) {
|
||||||
|
if (errno == EPIPE) {
|
||||||
|
debug3_f("monitor fd closed (body)");
|
||||||
|
mm_reap();
|
||||||
|
cleanup_exit(255);
|
||||||
|
}
|
||||||
|
fatal_f("write: %s", strerror(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mm_request_receive(int sock, struct sshbuf *m)
|
mm_request_receive(int sock, struct sshbuf *m)
|
||||||
{
|
{
|
||||||
u_char buf[4], *p = NULL;
|
u_char buf[4], *p = NULL;
|
||||||
u_int msg_len;
|
u_int msg_len;
|
||||||
int oerrno, r;
|
int r;
|
||||||
|
|
||||||
debug3_f("entering");
|
debug3_f("entering");
|
||||||
|
|
||||||
|
@ -194,12 +206,13 @@ mm_request_receive(int sock, struct sshbuf *m)
|
||||||
if ((r = sshbuf_reserve(m, msg_len, &p)) != 0)
|
if ((r = sshbuf_reserve(m, msg_len, &p)) != 0)
|
||||||
fatal_fr(r, "reserve");
|
fatal_fr(r, "reserve");
|
||||||
if (atomicio(read, sock, p, msg_len) != msg_len) {
|
if (atomicio(read, sock, p, msg_len) != msg_len) {
|
||||||
oerrno = errno;
|
if (errno == EPIPE) {
|
||||||
error_f("read: %s", strerror(errno));
|
debug3_f("monitor fd closed");
|
||||||
if (oerrno == EPIPE)
|
|
||||||
mm_reap();
|
mm_reap();
|
||||||
cleanup_exit(255);
|
cleanup_exit(255);
|
||||||
}
|
}
|
||||||
|
fatal_f("read: %s", strerror(errno));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in New Issue