]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
privsep: Don't find processes we just asked to stop
authorRoy Marples <roy@marples.name>
Fri, 2 Sep 2022 11:54:25 +0000 (12:54 +0100)
committerRoy Marples <roy@marples.name>
Fri, 2 Sep 2022 11:54:25 +0000 (12:54 +0100)
We could rebind a lease, get a NAK and enter DISCOVER.
We need to restart the BPF in the middle as the BPF filter could
change.

As such, add a started flag to each privsep process and when
searching for a process by id only find started ones.
If we ask them to stop then the started flag is removed.

Fixes errors about writing to stopping processes an unknown
processes exiting.

src/privsep.c
src/privsep.h

index f08b4028c561db35270cae145a077e40274e4cc7..5a437ae3ae040e7969ddc1973c28be5237025cf3 100644 (file)
@@ -408,6 +408,7 @@ ps_startprocess(struct ps_process *psp,
                        return -1;
                }
 #endif
+               psp->psp_started = true;
                return pid;
        }
 
@@ -481,6 +482,7 @@ ps_startprocess(struct ps_process *psp,
        if (flags & PSF_DROPPRIVS)
                ps_dropprivs(ctx);
 
+       psp->psp_started = true;
        return 0;
 
 errexit:
@@ -509,6 +511,8 @@ ps_stopprocess(struct ps_process *psp)
        if (psp == NULL)
                return 0;
 
+       psp->psp_started = false;
+
 #ifdef PRIVSEP_DEBUG
        logdebugx("%s: me=%d pid=%d fd=%d %s", __func__,
            getpid(), psp->psp_pid, psp->psp_fd, psp->psp_name);
@@ -1164,6 +1168,8 @@ ps_findprocess(struct dhcpcd_ctx *ctx, struct ps_id *psid)
        struct ps_process *psp;
 
        TAILQ_FOREACH(psp, &ctx->ps_processes, next) {
+               if (!(psp->psp_started))
+                       continue;
                if (memcmp(&psp->psp_id, psid, sizeof(psp->psp_id)) == 0)
                        return psp;
        }
index 856848e0f79101f6a76215a6f3255aaeb6e3004b..2f0304a7bf74a850123ec56781e010656a27d4b8 100644 (file)
@@ -169,6 +169,7 @@ struct ps_msg {
 };
 
 struct bpf;
+
 struct ps_process {
        TAILQ_ENTRY(ps_process) next;
        struct dhcpcd_ctx *psp_ctx;
@@ -181,6 +182,7 @@ struct ps_process {
        char psp_name[PSP_NAMESIZE];
        uint16_t psp_proto;
        const char *psp_protostr;
+       bool psp_started;
 
 #ifdef INET
        int (*psp_filter)(const struct bpf *, const struct in_addr *);