From: Roy Marples Date: Wed, 10 Jun 2020 15:32:04 +0000 (+0100) Subject: privsep: Fix a shutdown race X-Git-Tag: v9.1.2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=536f64cabf24ea7ada1fa0c0fd5e59b5960391f3;p=thirdparty%2Fdhcpcd.git privsep: Fix a shutdown race Only test a successful stop IPC command. By the time we shutdown the socket to be extra nice, the process we sent stop to could have already exited, therefore we can discard any error. --- diff --git a/src/privsep-root.c b/src/privsep-root.c index efafc20a..46daeb07 100644 --- a/src/privsep-root.c +++ b/src/privsep-root.c @@ -480,7 +480,6 @@ ps_root_recvmsgcb(void *arg, struct ps_msghdr *psm, struct msghdr *msg) shutdown(psp->psp_fd, SHUT_RDWR); close(psp->psp_fd); psp->psp_fd = -1; - ps_dostop(ctx, &psp->psp_pid, &psp->psp_fd); ps_freeprocess(psp); } return 0; diff --git a/src/privsep.c b/src/privsep.c index b2f3b309..d05681aa 100644 --- a/src/privsep.c +++ b/src/privsep.c @@ -401,17 +401,16 @@ ps_dostop(struct dhcpcd_ctx *ctx, pid_t *pid, int *fd) int err = 0; #ifdef PRIVSEP_DEBUG - logdebugx("%s: pid %d fd %d", __func__, *pid, *fd); + logdebugx("%s: pid=%d fd=%d", __func__, *pid, *fd); #endif if (*fd != -1) { eloop_event_delete(ctx->eloop, *fd); - if (ps_sendcmd(ctx, *fd, PS_STOP, 0, NULL, 0) == -1 || - shutdown(*fd, SHUT_RDWR) == -1) - { + if (ps_sendcmd(ctx, *fd, PS_STOP, 0, NULL, 0) == -1) { logerr(__func__); err = -1; } + (void)shutdown(*fd, SHUT_RDWR); close(*fd); *fd = -1; }