From: Roy Marples Date: Fri, 29 Nov 2019 00:32:42 +0000 (+0000) Subject: privsep: Don't close BPF listeners when forked X-Git-Tag: v9.0.0~202 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1d9b8ed9e9639b89aa73bdfa763978246946a84;p=thirdparty%2Fdhcpcd.git privsep: Don't close BPF listeners when forked The normal flow is just to release resources for sanitisers. --- diff --git a/src/arp.c b/src/arp.c index a07ca09d..3c395035 100644 --- a/src/arp.c +++ b/src/arp.c @@ -272,13 +272,14 @@ arp_packet(struct interface *ifp, uint8_t *data, size_t len) static void arp_close(struct interface *ifp) { + struct dhcpcd_ctx *ctx = ifp->ctx; struct iarp_state *state; if ((state = ARP_STATE(ifp)) == NULL) return; #ifdef PRIVSEP - if (ifp->ctx->options & DHCPCD_PRIVSEP) { + if ((ctx->options & (DHCPCD_PRIVSEP|DHCPCD_FORKED)) == DHCPCD_PRIVSEP) { if (ps_bpf_closearp(ifp) == -1) logerr(__func__); } @@ -286,7 +287,7 @@ arp_close(struct interface *ifp) if (state->bpf_fd == -1) return; - eloop_event_delete(ifp->ctx->eloop, state->bpf_fd); + eloop_event_delete(ctx->eloop, state->bpf_fd); bpf_close(ifp, state->bpf_fd); state->bpf_fd = -1; state->bpf_flags |= BPF_EOF; diff --git a/src/dhcp.c b/src/dhcp.c index f3f8592c..d16c649f 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -1520,13 +1520,14 @@ again: void dhcp_close(struct interface *ifp) { + struct dhcpcd_ctx *ctx = ifp->ctx; struct dhcp_state *state = D_STATE(ifp); if (state == NULL) return; #ifdef PRIVSEP - if (ifp->ctx->options & DHCPCD_PRIVSEP) { + if ((ctx->options & (DHCPCD_PRIVSEP|DHCPCD_FORKED)) == DHCPCD_PRIVSEP) { ps_bpf_closebootp(ifp); if (state->addr != NULL) ps_inet_closebootp(state->addr); @@ -1534,13 +1535,13 @@ dhcp_close(struct interface *ifp) #endif if (state->bpf_fd != -1) { - eloop_event_delete(ifp->ctx->eloop, state->bpf_fd); + eloop_event_delete(ctx->eloop, state->bpf_fd); bpf_close(ifp, state->bpf_fd); state->bpf_fd = -1; state->bpf_flags |= BPF_EOF; } if (state->udp_fd != -1) { - eloop_event_delete(ifp->ctx->eloop, state->udp_fd); + eloop_event_delete(ctx->eloop, state->udp_fd); close(state->udp_fd); state->udp_fd = -1; }