fix(packet): read_qname doesn't reject label length > 63, swallows malformed upstream packets #142
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
buffer::read_qnamedoesn't validate that a label-length byte is ≤ 63 (RFC 1035 §2.3.1). If an upstream emits a malformed compression pointer landing inside a label body (rather than at a label-length boundary, violating RFC 1035 §4.1.4),read_qnamereads an arbitrary byte as the length and consumes up to 63+ bytes of garbage as a single "label".write_qnamethen rejects the result,ctx::resolve_queryhits the generic error path, and the client gets a TC-flagged empty response.Found during #137 field check against Tailscale MagicDNS (
100.100.100.100:53).Reproduction
MagicDNS responds with a mostly-uncompressed 219-byte packet whose SOA mname pointer
c0 5alands at offset 90, which falls inside theadobeaemcloudlabel body — not at a label-length boundary.Why it matters
Current failure mode is silent: TC fallback with empty answers, clients fall back to TCP or just fail. The internal log line ("response too large") is also misleading — the buffer wasn't full, write_qname just rejected a bogus label.
Orthogonal to #137: on
main, opaque-UNKNOWN re-emits the bad bytes and clients see "malformed reply packet" (the original #128 symptom). Post-#137, the SOA is parsed natively so the bad pointer is followed and the break shifts to the write side. Numa should refuse to propagate upstream malformedness either way.Suggested fix
src/buffer.rs::read_qname: after reading a length byte withlen & 0xC0 == 0x00, requirelen <= 63. Return a parse error otherwise. The 5-jump pointer limit stays.src/ctx.rs: distinguish "wire buffer full" (genuine TC) from "parse/serialize error" (upstream malformed → SERVFAIL + fail over), instead of collapsing both into TC.Test plan
read_qnamereturnsErr.read_qnamereturnsErr.