Repository navigation
Description
Authenticated reserved-bits validation is missing
Summary
- This is a real issue.
quichedoes not validate Reserved Bits after packet authentication, so it accepts packets that should triggerPROTOCOL_VIOLATION.- The root cause is not error-code mapping;
Error::InvalidPacketalready maps toPROTOCOL_VIOLATION. - I verified two authenticated paths at runtime: short-header
1-RTTand long-headerInitial. - The affected scope is packets with protected payloads:
Initial,0-RTT,Handshake, and1-RTT.Retryand Version Negotiation are outside this finding.
Standard Requirement
- RFC 9000 Section 17.2: Long Header Packets
- RFC 9000 Section 17.3: Short Header Packets
- RFC 9001 Section 5.4: Header Protection
- RFC 9001 Section 9.5: Header Protection Timing Side Channels
For long headers, RFC 9000 requires the 0x0c Reserved Bits to be zero before protection and requires an endpoint to treat non-zero values after removing both packet and header protection as PROTOCOL_VIOLATION.
For short headers, RFC 9000 applies the same rule to the 0x18 Reserved Bits after both protections are removed.
RFC 9001 further explains that Reserved Bits are header-protected fields and that header protection removal, packet number recovery, and packet protection removal must be applied together for authentication. The correct time to check is therefore after both header protection and packet protection are removed, not immediately after header protection alone. Retry is not covered by this rule: RFC 9001 excludes Retry and Version Negotiation, and RFC 9000 defines Retry's four bits as Unused (4), not these Reserved Bits.
Relevant Source Code
implementions/quiche/quiche/src/packet.rs:577-629
if Header::is_long(first) {
first ^= mask[0] & 0x0f;
} else {
first ^= mask[0] & 0x1f;
}
// Write decrypted first byte back into the input buffer.
let (mut first_buf, _) = b.split_at(1)?;
first_buf.as_mut()[0] = first;decrypt_hdr() removes header protection and writes the decrypted first byte back to the input buffer, but it does not check first & 0x0c or first & 0x18.
implementions/quiche/quiche/src/lib.rs:3250-3330
packet::decrypt_hdr(&mut b, &mut hdr, aead)?;
let pn = packet::decode_pkt_num(
self.pkt_num_spaces[epoch].largest_rx_pkt_num,
hdr.pkt_num,
hdr.pkt_num_len,
);
let mut payload = packet::decrypt_pkt(
&mut b,
pn,
pn_len,
payload_len,
aead,
)?;
if self.pkt_num_spaces[epoch].recv_pkt_num.contains(pn) {
return Err(Error::Done);
}
if payload.cap() == 0 {
return Err(Error::InvalidPacket);
}After decrypt_pkt() succeeds, recv_single() proceeds to duplicate checks, payload checks, and frame processing without validating Reserved Bits.
implementions/quiche/quiche/src/error.rs:184-200
_ => WireErrorCode::ProtocolViolation as u64,If this path returned Error::InvalidPacket, the existing mapping would already produce PROTOCOL_VIOLATION.
Implementation Behavior
The receive path is decrypt_hdr() -> decode_pkt_num() -> decrypt_pkt() -> duplicate check -> payload/frame processing. The missing check is immediately after decrypt_pkt() succeeds: the implementation never validates the post-protection first byte for the long-header 0x0c bits or the short-header 0x18 bits.
implementions/quiche/quiche/src/lib.rs:3786-3792 shows that normally received packets increment recv_count. implementions/quiche/quiche/src/lib.rs:9338-9352 shows that drop_pkt_on_err() swallows unauthenticated invalid packets, but that does not replace the required authenticated post-decryption validation.
Inconsistency Reason
The standards require Reserved Bits to be checked after both header protection and packet protection are removed. quiche removes the header, decrypts the payload, and continues parsing without checking those bits. As a result, authenticated packets with non-zero Reserved Bits can be processed as normal packets.
The real defect is the missing authenticated Reserved Bits validation.
Runtime Evidence
I ran:
cargo test reserved_bits_probe_short_authenticated -- --nocapture
cargo test reserved_bits_probe_initial_authenticated -- --nocapture
The tests observed:
case=short reserved_bits=0x18 recv_res=Ok(38) recv_delta=1 server_closed=false local_error=None ack_len=Some(39)
case=initial reserved_bits=0x0c first_pkt_len=304 datagram_len=1200 frames=1 recv_res=Ok(1200) recv_delta=1 server_closed=false local_error=None send_after=Some(1200)
The short-header 1-RTT packet with non-zero 0x18 Reserved Bits was accepted, incremented receive state, and produced an ACK. The long-header Initial packet with non-zero 0x0c Reserved Bits was also accepted, incremented receive state, and produced a follow-up handshake response. Both paths showed server_closed=false and local_error=None, so PROTOCOL_VIOLATION was not triggered.
Impact
A peer with current connection keys, or with the known Initial protection material, can construct authenticated QUIC packets with non-zero Reserved Bits. quiche continues processing them instead of closing the connection. Runtime tests confirmed the issue for Initial and 1-RTT; the same receive path also covers 0-RTT and Handshake.
Fix Direction
In implementions/quiche/quiche/src/lib.rs, immediately after packet::decrypt_pkt() succeeds and before duplicate or frame processing, read the first byte written back by decrypt_hdr() and check:
- short header:
first & 0x18 != 0 - long header:
first & 0x0c != 0
Return Error::InvalidPacket on a match. The existing Error::to_wire() mapping will turn that into PROTOCOL_VIOLATION.
Activity
ghedo commentedon Nov 25, 2026
Closing as a duplicate of #2526, which covers the same missing reserved-bits validation after header protection is removed. #2575 proposes the fix.