Repository navigation
Conversation
RFC 6762 section 11 (Source Address Check) says a responder should not answer a query whose source is not on the local link. Multicast queries cannot cross a router, so such a query was sent to this host's unicast address from elsewhere; answering it, in particular with a legacy unicast response to an arbitrary address and port, makes the host a reflector for spoofed queries when it has a routed address. handle_query now drops a query unless its source lies in a subnet of one of the receiving interface's addresses, or is a link-local address (169.254.0.0/16, fe80::/10), which is on-link by definition.
A responder on mdns-sd, on both inits, answers <hostname>.local on every interface but loopback, the container links, WireGuard and CAN, and publishes _mica._tcp (TXT txtvers, product, hostname), the console while apid serves the network, and SSH while it is on. A query from off the link is not answered: mdns-sd is pinned to the micaoss fork carrying the on-link source check and a cap on legacy-unicast answers (keepsimple1/mdns-sd#532) until upstream releases it. access.mdns.enabled switches it, else the product's MDNS= line; off is no socket. The resolved drop-in now says MulticastDNS=no, so resolved never becomes a second responder on 5353.
keepsimple1
left a comment
There was a problem hiding this comment.
Thank you for the PR! The intention is valid. Comments inline.
| fn is_on_link(addr: &IpAddr, intf: &MyIntf) -> bool { | ||
| let link_local = match addr { | ||
| IpAddr::V4(v4) => v4.is_link_local(), | ||
| IpAddr::V6(v6) => (v6.segments()[0] & 0xffc0) == 0xfe80, |
There was a problem hiding this comment.
nitpick: add a comment:
// Same as Ipv6Addr::is_unicast_link_local(), which needs Rust 1.84 (MSRV is 1.71).
| /// addresses, or a link-local address, which is on-link by definition. | ||
| fn is_on_link(addr: &IpAddr, intf: &MyIntf) -> bool { | ||
| let link_local = match addr { | ||
| IpAddr::V4(v4) => v4.is_link_local(), |
There was a problem hiding this comment.
A note: the RFC 6762 section 11 checks IPv4 local addresses in the same way as valid_ip_on_intf , not blindly accepts source address 169.254/16 if the local interface does not have 169.254/16 address:
An IPv4 source address
is determined to be on a local subnet if, for (one of) the
address(es) configured on the interface receiving the packet, (I
& M) == (P & M), where I and M are the interface address and
subnet mask respectively, P is the source IP address from the
packet, '&' represents the bitwise logical 'and' operation, and
'==' represents a bitwise equality test.
i.e. but I think either way is fine, i.e. keeping the 169.254/16 exemption is defensible, so we can keep it .
| // cannot cross a router, so such a query was sent to this host's | ||
| // unicast address from elsewhere, possibly with a spoofed source, and | ||
| // a reply would make this host a reflector. | ||
| if !is_on_link(&querier_ip, intf) { |
There was a problem hiding this comment.
We should only check the source address when the incoming packet destination address is not multicast address. In RFC 6762 section 11:
All responses received with a destination address in the IP
header that is the mDNS IPv4 link-local multicast address
224.0.0.251 or the mDNS IPv6 link-local multicast address
FF02::FB are necessarily deemed to have originated on the local
link, regardless of source IP address.
Also it's mentioned in RFC 6762 section 5.5
sock.pktinfo.recv() returns a PktInfo with addr_dst so we could pass the destination into handle_query.
RFC 6762 section 11 (Source Address Check): a responder should not answer a query whose source is not on the local link.
Multicast queries cannot cross a router, so a query from an off-link source reached the host through its unicast address on port 5353. Today
handle_queryanswers it, and a legacy unicast query (source port other than 5353) is answered by unicast to that source address and port, whatever it is. A host with a routed address and no firewall then answers spoofed queries from anywhere, which makes it a small reflector.This change drops a query in
handle_queryunless one of these holds:valid_ip_on_intf);Tests:
test_query_from_off_link_source_is_not_answerednarrows the loopback interface to 127.0.0.1/32, then checks that a querier at 127.0.0.1 is answered and one at 127.0.0.2 is not. It fails without the check.test_link_local_sources_are_on_linkcovers the link-local cases.cargo test --libpasses.Happy to put this behind an option if you prefer a default that keeps today's behaviour.