Skip to content

Commit cfe243c

Browse files
committed
upstream: reap preauth net child if it hangs up during privsep message
send, not just message receive OpenBSD-Commit-ID: 02a093f4ab4f8f83f0cd1ea2bb35b9ca420448f0
1 parent b0a711c commit cfe243c

File tree

1 file changed

+24
-37
lines changed

1 file changed

+24
-37
lines changed

monitor_wrap.c

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: monitor_wrap.c,v 1.134 2024/06/11 02:00:30 djm Exp $ */
1+
/* $OpenBSD: monitor_wrap.c,v 1.135 2024/06/11 02:54:51 djm Exp $ */
22
/*
33
* Copyright 2002 Niels Provos <[email protected]>
44
* Copyright 2002 Markus Friedl <[email protected]>
@@ -121,6 +121,24 @@ mm_is_monitor(void)
121121
return (pmonitor && pmonitor->m_pid > 0);
122122
}
123123

124+
void
125+
mm_request_send(int sock, enum monitor_reqtype type, struct sshbuf *m)
126+
{
127+
size_t mlen = sshbuf_len(m);
128+
u_char buf[5];
129+
130+
debug3_f("entering, type %d", type);
131+
132+
if (mlen >= 0xffffffff)
133+
fatal_f("bad length %zu", mlen);
134+
POKE_U32(buf, mlen + 1);
135+
buf[4] = (u_char) type; /* 1st byte of payload is mesg-type */
136+
if (atomicio(vwrite, sock, buf, sizeof(buf)) != sizeof(buf))
137+
fatal_f("write: %s", strerror(errno));
138+
if (atomicio(vwrite, sock, sshbuf_mutable_ptr(m), mlen) != mlen)
139+
fatal_f("write: %s", strerror(errno));
140+
}
141+
124142
static void
125143
mm_reap(void)
126144
{
@@ -152,42 +170,12 @@ mm_reap(void)
152170
}
153171
}
154172

155-
void
156-
mm_request_send(int sock, enum monitor_reqtype type, struct sshbuf *m)
157-
{
158-
size_t mlen = sshbuf_len(m);
159-
u_char buf[5];
160-
161-
debug3_f("entering, type %d", type);
162-
163-
if (mlen >= 0xffffffff)
164-
fatal_f("bad length %zu", mlen);
165-
POKE_U32(buf, mlen + 1);
166-
buf[4] = (u_char) type; /* 1st byte of payload is mesg-type */
167-
if (atomicio(vwrite, sock, buf, sizeof(buf)) != sizeof(buf)) {
168-
if (errno == EPIPE) {
169-
debug3_f("monitor fd closed (header)");
170-
mm_reap();
171-
cleanup_exit(255);
172-
}
173-
fatal_f("write: %s", strerror(errno));
174-
}
175-
if (atomicio(vwrite, sock, sshbuf_mutable_ptr(m), mlen) != mlen) {
176-
if (errno == EPIPE) {
177-
debug3_f("monitor fd closed (body)");
178-
mm_reap();
179-
cleanup_exit(255);
180-
}
181-
fatal_f("write: %s", strerror(errno));
182-
}
183-
}
184-
185173
void
186174
mm_request_receive(int sock, struct sshbuf *m)
187175
{
188176
u_char buf[4], *p = NULL;
189177
u_int msg_len;
190-
int r;
178+
int oerrno, r;
191179

192180
debug3_f("entering");
193181

@@ -206,12 +194,11 @@ mm_request_receive(int sock, struct sshbuf *m)
206194
if ((r = sshbuf_reserve(m, msg_len, &p)) != 0)
207195
fatal_fr(r, "reserve");
208196
if (atomicio(read, sock, p, msg_len) != msg_len) {
209-
if (errno == EPIPE) {
210-
debug3_f("monitor fd closed");
197+
oerrno = errno;
198+
error_f("read: %s", strerror(errno));
199+
if (oerrno == EPIPE)
211200
mm_reap();
212-
cleanup_exit(255);
213-
}
214-
fatal_f("read: %s", strerror(errno));
201+
cleanup_exit(255);
215202
}
216203
}
217204

0 commit comments

Comments
 (0)