fix(clientinfo): nil-guard the dhcp table in SetSelfIP to stop the netmon panic loop#306
Open
SAY-5 wants to merge 1 commit intoControl-D-Inc:mainfrom
Open
fix(clientinfo): nil-guard the dhcp table in SetSelfIP to stop the netmon panic loop#306SAY-5 wants to merge 1 commit intoControl-D-Inc:mainfrom
SAY-5 wants to merge 1 commit intoControl-D-Inc:mainfrom
Conversation
…tmon panic loop Table.SetSelfIP unconditionally dereferenced t.dhcp: t.dhcp.selfIP = t.selfIP t.dhcp.addSelf() but Table.init() only assigns t.dhcp when DHCP discovery is on AND there is no custom client ID (the custom-ID path takes initSelfDiscover() and allocates its own dhcp; disabling DHCP and supplying no custom ID leaves t.dhcp as nil). Any config with discover_dhcp = "false" and no cd_uid therefore panics the first time SetSelfIP is called, which is from monitorNetworkChanges on every netmon event: panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0xd0 ...] internal/clientinfo.(*Table).SetSelfIP(...) internal/clientinfo/client_info.go:176 +0x94 cmd/cli.(*prog).monitorNetworkChanges.func2(...) cmd/cli/dns_proxy.go:1577 +0xfe0 Because monitorNetworkChanges fires on every carrier/address change, real deployments see a crash per DHCP acquisition, WiFi reconnect, or VPN up/down. The reporter of Control-D-Inc#305 recorded 96 crashes across 28 days on one ARM64 box with discover_dhcp = "false". When t.dhcp is nil we have nothing to do: the selfIP cache on t itself has already been updated above, and addSelf() exists only to push that into the dhcp resolver's self-mapping. Return early so clients with DHCP discovery disabled simply use the selfIP we just recorded instead of tripping SIGSEGV. Fixes Control-D-Inc#305 Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>
Collaborator
|
Thanks for sending over this fix! Because our current development workflow is tied closely to an internal issue tracker, we aren't able to merge external pull requests directly at this time. However, we’ve noted the issue and will implement a fix in an upcoming release. We appreciate the contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Table.SetSelfIPininternal/clientinfo/client_info.gounconditionally dereferencest.dhcp:But
Table.init()only allocatest.dhcpon two paths:initSelfDiscover()and builds a fresh&dhcp{...}.if t.discoverDHCP()branch farther down.Any config that disables DHCP discovery (
discover_dhcp = "false") and does not set a custom client ID never assignst.dhcp, so it stays nil for the lifetime of the process. The first timemonitorNetworkChangessees a carrier/address event and callsSetSelfIP, the netmon goroutine panics:Because
monitorNetworkChangesfires on every carrier/address transition (WiFi reconnect, DHCP renewal, VPN up/down), this is not a one-off crash — #305 documents 96 panics on a single ARM64 system over 28 days, all withdiscover_dhcp = "false". Every boot and every WiFi reconnect reliably reproduces it.Fix
Early-return from
SetSelfIPwhent.dhcpis nil:t.selfIPis the single source of truth forSelfIP()(RLock'd reader), and has already been updated above.addSelf()only exists to mirror that into the DHCP resolver's self-entry table — when we have no DHCP resolver, there is nothing to mirror into.Configs with DHCP discovery on, or with a custom client ID, are unaffected:
t.dhcpis non-nil throughinit(), the new branch skips, and the rest of the method runs exactly as before.Why here and not at the init site
Allocating an empty
&dhcp{}ininit()even when DHCP discovery is disabled would pull the zero-value DHCP resolver intot.ipResolvers/t.macResolvers/t.hostnameResolversand change the resolver set for configs that explicitly opted out. A guard at the write site is the narrowest fix that matches the existing "don't do DHCP if discover_dhcp is false" semantics.Test plan
mainwith a config that setsdiscover_dhcp = "false",discover_arp = "false", etc., and nocd_uid. Trigger a carrier change (e.g.ip link set <iface> down && ip link set <iface> up) —ctrldpanics with the stack trace above.SetSelfIPreturns cleanly,SelfIP()returns the latest IP, carrier changes no longer crash the binary.Fixes #305