Skip to content

fix: ignore unicast queries from off-link sources (RFC 6762 section 5.5) - #559

Merged
keepsimple1 merged 2 commits into
keepsimple1:mainfrom
AlixANNERAUD:fix/ignore-off-link-unicast-queries
Nov 30, 2026
Merged

keepsimple1 merged 2 commits into
keepsimple1:mainfrom
AlixANNERAUD:fix/ignore-off-link-unicast-queries

Conversation

@AlixANNERAUD

@AlixANNERAUD AlixANNERAUD commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #558.

A query sent to one of the daemon's unicast addresses can come from outside the local link, with any source address. The daemon answers it (by unicast to a legacy querier), so a small spoofed query sends PTR, SRV, TXT and address records, many times its size, to whatever address it claims.

RFC 6762 section 5.5 asks responders to check that the source of a unicast query is on the local subnet (for IPv6, has an on-link prefix) and to silently ignore it otherwise. Avahi does the same (avahi-core/server.c, "Received non-local unicast query").

Change

handle_read now drops a query when:

  • its destination is not the mDNS group (224.0.0.251 or ff02::fb): packets sent to the group are on-link whatever their source (section 11), so nothing changes for them;
  • and its source is not on a subnet of the receiving interface (valid_ip_on_intf, as send_response already uses to pick a source address) and is not an IPv6 link-local address.

Responses are not touched by this change.

Tests

test_off_link_unicast_queries_are_ignored covers on-link and off-link IPv4 and IPv6 sources, IPv6 link-local sources, and queries sent to the group from off-link sources. test_handle_read_ignores_off_link_unicast_queries covers the path in handle_read: it sends the same unicast query to the daemon on 127.0.0.1 from 127.0.0.1 (answered) and from the address of another interface (ignored, since the datagram arrives on the loopback interface). It fails when the check in handle_read is removed. It does not run on Windows, which refuses to send from a non-loopback address to 127.0.0.1. Clippy (all features and none) and rustdoc are clean. On my machine the network tests that need multicast (such as test_legacy_unicast_response) fail with and without this change, so CI is the check for those.

AlixANNERAUD added a commit to AlixANNERAUD/recto that referenced this pull request Nov 23, 2026
mdns-sd 0.22 answers a query sent to the host's own address from any source address, with an
answer about twenty times its size, so a spoofed query from the internet could make recto
flood someone else (keepsimple1/mdns-sd#558). Build with the fix, keepsimple1/mdns-sd#559,
pinned by commit from the owner's fork until a release includes it, and allow that git source
in cargo-deny.

The discovery guide, the security model and the configuration reference no longer describe
the amplification, and still advise firewalling UDP 5353 and naming the LAN interface.

@keepsimple1 keepsimple1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for your PR! The changes look good.

One nit is: if possible, add another test to cover the actual path in handle_read, it will be great. That's not blocking.

Also, we actually have a pending PR #532 that overlaps with this one, waiting on the author. This is FYI, will not block this PR.

I should be able to approve once the conflict with the latest main branch is resolved.

A query sent to one of our unicast addresses can come from outside the local link, with any
source address. Answering it sends our records, many times the size of the query, to that
address. Drop such a query unless its source is on a subnet of the receiving interface or is
an IPv6 link-local address. Queries sent to the mDNS group are on-link whatever their source
(section 11) and are handled as before.

Fixes keepsimple1#558.
@AlixANNERAUD
AlixANNERAUD force-pushed the fix/ignore-off-link-unicast-queries branch from 2628df0 to 706df56 Compare November 25, 2026 09:35
@AlixANNERAUD

AlixANNERAUD commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the review!

  • Rebased on the latest main. The only conflict was the import list of the test module.
  • Added test_handle_read_ignores_off_link_unicast_queries, which goes through handle_read. A datagram sent to 127.0.0.1 arrives on the loopback interface, even when its source is the address of another interface. The test sends the same unicast query from 127.0.0.1 (it must be answered) and from a non-loopback address of the host (it must be ignored). It fails when the check in handle_read is removed. It uses its own port, because a unicast datagram to a port shared with SO_REUSEPORT reaches only one of the sockets. It does not run on Windows, which refuses to send a datagram from a non-loopback address to 127.0.0.1 (WSAEADDRNOTAVAIL).

Thanks for the pointer to #532. I am happy to adjust this PR if you prefer to combine the two.

The new test sends the same unicast query to the daemon on 127.0.0.1
from two sources. A datagram to 127.0.0.1 arrives on the loopback
interface, so 127.0.0.1 is an on-link source and the address of another
interface is an off-link source. The daemon must answer the first query
and ignore the second.

The test uses its own port: with SO_REUSEPORT, a unicast datagram
reaches only one of the sockets that share a port.

The test does not run on Windows, which refuses to send a datagram from
a non-loopback address to 127.0.0.1.
@AlixANNERAUD
AlixANNERAUD force-pushed the fix/ignore-off-link-unicast-queries branch from 706df56 to 32151b2 Compare November 25, 2026 09:39

@keepsimple1 keepsimple1 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

LGTM, thanks! I will handle PR #532 separately.

@keepsimple1
keepsimple1 merged commit 69153cb into keepsimple1:main Nov 30, 2026
6 checks passed
keepsimple1 added a commit that referenced this pull request Dec 2, 2026
`handle_query` decides whether and what to answer, so the RFC 6762
section 5.5 source check belongs there. It now takes the destination
address of the query and runs is_off_link_unicast (from #559) before
anything else, including probe tiebreaking. Queries sent to the mDNS
group are still answered whatever their source.

---------

Co-authored-by: roy <[email protected]>
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.

Unicast answers go to off-link source addresses (RFC 6762 section 5.5 source check)

2 participants