discovery: fix panic in DNS fallback SRV lookup#10914
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses potential stability issues in the DNS fallback SRV lookup mechanism. By replacing unconditional type assertions with safe checks and adding validation for empty lookup results, the changes prevent the daemon from panicking when receiving malformed or unexpected DNS responses. Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
a29264c to
98f5645
Compare
There was a problem hiding this comment.
Code Review
This pull request fixes potential panics in the DNS fallback SRV lookup by handling empty address results and safely skipping non-SRV records using a comma-ok type assertion. It also adds corresponding unit tests and updates the release notes. The reviewer recommended improving the unit tests by verifying that the type assertions on the bootstrapper interface succeed using require.True instead of ignoring the boolean result, which could lead to nil pointer dereferences.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
PR Severity: HIGH (severity-high)
High (1 file):
Low (1 file):
AnalysisThe primary change is in The test file ( No severity bump was triggered: only 2 non-test files changed (threshold: >20) and 21 non-test lines changed (threshold: >500). To override, add a |
gijswijs
left a comment
There was a problem hiding this comment.
Only two things I could find, one pre-existing. I made inline-comments that you can address individually.
One other pre-existing thing that caught my eye is the return nil, err inside SampleNodeAddrs. One attacker-supplied malformed target would kill the whole round. It happens at 4 sites:
- bootstrapper.go:514: LookupHost(bechNodeHost) failure
- bootstrapper.go:539: bech32.Decode failure
- bootstrapper.go:550: bech32.ConvertBits failure
- bootstrapper.go:554: btcec.ParsePubKey failure
This fix could be applied at each of those four sites, e.g. line 537-540:
_, nodeBytes5Bits, err := bech32.Decode(bechNode[0])
if err != nil {
log.Tracef("Skipping node %v: %v", bechNodeHost, err)
continue
}But you could also make the case that failing at those point is the right call, especially at LookupHost. So it's more of a judgement call left to the creator.
I'm confident @erickcestari will fix the issues, so I'm approving upfront.
8c5bb1c to
fbea4dc
Compare
yyforyongyu
left a comment
There was a problem hiding this comment.
Looking good, just a few nits
fbea4dc to
527f654
Compare
The fallback SRV lookup type-asserted each DNS Answer record to *dns.SRV unconditionally. If the response contains a non-SRV record (e.g. an A or CNAME), the type assertion panics and crashes the daemon. Use the comma-ok form to skip non-SRV records instead. Also guard against an empty LookupHost result for the shim, which would otherwise panic on an out-of-bounds index into addrs. This is safe to discuss and fix in public. The bug is very unlikely to be exploitable: triggering it requires either a DNS seeder to serve a malformed response, or an on-path MITM injecting one (the fallback response is unauthenticated). A malicious seeder already has far more direct ways to disrupt a node, and a MITM attack is hard to mount, so the panic does not meaningfully widen the attack surface.
527f654 to
2ee4969
Compare
|
Thanks for the review @yyforyongyu @gijswijs . Your comments should be addressed! |
|
Created backport PR for
Please cherry-pick the changes locally and resolve any conflicts. git fetch origin backport-10914-to-v0.21.x-branch
git worktree add --checkout .worktree/backport-10914-to-v0.21.x-branch backport-10914-to-v0.21.x-branch
cd .worktree/backport-10914-to-v0.21.x-branch
git reset --hard HEAD^
git cherry-pick -x 2ee49698afa74373fa51acc61edd5620cb623f61
git push --force-with-lease |
The fallback SRV lookup type-asserted each DNS Answer record to
*dns.SRVunconditionally. If the response contains a non-SRV record (e.g. an A or
CNAME), the type assertion panics and crashes the daemon. Use the
comma-ok form to skip non-SRV records instead.
Also guard against an empty
LookupHostresult for the shim, which wouldotherwise panic on an out-of-bounds index into addrs.
This is safe to discuss and fix in public. The bug is very unlikely to be
exploitable: triggering it requires either a DNS seeder to serve a
malformed response, or an on-path MITM injecting one (the fallback
response is unauthenticated). A malicious seeder already has far more
direct ways to disrupt a node, and a MITM attack is hard to mount, so the
panic does not meaningfully widen the attack surface.