From cef74423e2db11aa49f3ae073b263f75479613d4 Mon Sep 17 00:00:00 2001 From: Simon Kelley Date: Mon, 1 Dec 2025 09:41:30 +0000 Subject: [PATCH] Log error if we try and use netlink in a child process. Child processes to handle TCP connections don't have an open netlink socket. If they call iface_enumerate() that's a bug. --- src/dnsmasq.c | 3 +-- src/netlink.c | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/dnsmasq.c b/src/dnsmasq.c index 0908858..9ac5217 100644 --- a/src/dnsmasq.c +++ b/src/dnsmasq.c @@ -127,6 +127,7 @@ int main (int argc, char **argv) This might be increased is EDNS packet size if greater than the minimum. */ daemon->packet_buff_sz = daemon->edns_pktsz + MAXDNAME + RRFIXEDSZ; daemon->packet = safe_malloc(daemon->packet_buff_sz); + daemon->pipe_to_parent = -1; if (option_bool(OPT_EXTRALOG)) daemon->addrbuff2 = safe_malloc(ADDRSTRLEN); @@ -1080,8 +1081,6 @@ int main (int argc, char **argv) pid = getpid(); - daemon->pipe_to_parent = -1; - #ifdef HAVE_INOTIFY /* Using inotify, have to select a resolv file at startup */ poll_resolv(1, 0, now); diff --git a/src/netlink.c b/src/netlink.c index 4c8e983..389325e 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -165,6 +165,13 @@ int iface_enumerate(int family, void *parm, callback_t callback) struct rtgenmsg g; } req; + /* The netlink socket is not available in child processes. */ + if (daemon->pipe_to_parent != -1) + { + my_syslog(LOG_ERR, _("BUG: called iface_enumerate() in child process")); + return 0; + } + memset(&req, 0, sizeof(req)); memset(&addr, 0, sizeof(addr));