Skip to content

fix(connlib): clear pending sockets on DNS server re-creation - #9093

Merged
thomaseizinger merged 2 commits into
mainfrom
fix/out-of-bounds-error
May 12, 2025
Merged

thomaseizinger merged 2 commits into
mainfrom
fix/out-of-bounds-error

Conversation

@thomaseizinger

@thomaseizinger thomaseizinger commented May 12, 2025 •

Copy link
Copy Markdown
Member

Our DNS over TCP implementation uses smoltcp which requires us to manage sockets individually, i.e. there is no such thing as a listening socket. Instead, we have to create multiple sockets and rotate through them.

Whenever we receive new DNS servers from the host app, we throw away all of those sockets and create new ones.

The way we refer to these sockets internally is via smoltcp's SocketHandle. These are just indices into a Vec and this access can panic when it is out of range. Normally that doesn't happen because such a SocketHandle is only created when the socket is created and therefore, each SocketHandle in existence should be valid.

What we overlooked is that these sockets get destroyed and re-created when we call set_listen_addresses which happens when the host app tells us about new DNS servers. In that case, sockets that we had just received a query on and are waiting for a response have their handles stored in a temporary HashMap. Attempting to send back a response for one of those queries will then either fail with an error that the socket is not in the right state or - worse - panic with an out of bounds error if the previously had more listen addresses than we have now.

To fix this, we need to clear this map of pending queries every time we call set_listen_addresses.

@thomaseizinger
thomaseizinger requested review from Copilot and jamilbk May 12, 2025 09:34
@vercel

vercel Bot commented May 12, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
firezone ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 12, 2025 9:34am

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an issue in the DNS over TCP implementation where stale socket handles can cause panics after DNS server re-creation by clearing pending sockets when new listen addresses are set.

  • Introduces a new test to verify no panic occurs after calling set_listen_addresses with a different address set.
  • Clears the pending sockets in the Server implementation to avoid referencing outdated SocketHandles.
  • Adds conditions in the progress loop to check packet acceptance before processing.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
rust/connlib/dns-over-tcp/tests/client_and_server.rs Added test for verifying no panic on listen address changes and updated progress logic to check packet acceptance
rust/connlib/dns-over-tcp/src/server.rs Clears pending socket mappings upon listen address re-creation

Comment thread rust/connlib/dns-over-tcp/src/server.rs
@sentry

sentry Bot commented May 12, 2025

Copy link
Copy Markdown

Sentry Issue: APPLE-CLIENT-53

@sentry

sentry Bot commented May 12, 2025

Copy link
Copy Markdown

Sentry Issue: APPLE-CLIENT-52

@sentry

sentry Bot commented May 12, 2025

Copy link
Copy Markdown

Sentry Issue: GUI-CLIENT-4Y

@thomaseizinger
thomaseizinger enabled auto-merge May 12, 2025 09:37
@thomaseizinger
thomaseizinger added this pull request to the merge queue May 12, 2025
Merged via the queue into main with commit f01fd4d May 12, 2025
@thomaseizinger
thomaseizinger deleted the fix/out-of-bounds-error branch May 12, 2025 11:49

This branch was successfully deployed

1 active deployment
Preview — 23317eb0 Deployed May 12, 2025 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants