On Wed, 4 Nov 2026 at 03:42, Akihiko Odaki <[email protected]> wrote:
>
> On 2026/11/04 0:59, Peter Maydell wrote:
> > On Sun, 20 Sept 2026 at 11:52, Akihiko Odaki
> > <[email protected]> wrote:
> >>
> >> We already have some L4/L5 header bound checks but they were not
> >> comprehensive. Add the missing coverage.
> >>
> >> The IPv6 header parser incorrectly derives L4 offsets greater than
> >> actual values. Adding a bound check without fixing it would reject
> >> valid packets while fixing it without adding a bound check can result
> >> in an out-of-bounds access, so fix it along with the bound check
> >> addition.
> >>
> >> One fixed problem of the IPv6 header parser is that extension header
> >> size is not properly computed for the Fragment Header and the IP
> >> Authentication Header.
> >>
> >> RFC 8200 "Internet Protocol, Version 6 (IPv6) Specification" section
> >> 4.5. "Fragment Header" says the Fragment Header has a fixed size.
> >> The byte represented by ext_hdr.ip6r_len is reserved and "ignored on
> >> reception".
> >>
> >> RFC 4302 "IP Authentication Header" section 2.2. "Payload Length" says
> >> it specifies the length of AH in 32-bit words (4-byte units), minus "2".
> >>
> >> Another fixed problem is that the parser continues parsing extensions in
> >> noninitial fragments.
> >>
> >> RFC 8200 "Internet Protocol, Version 6 (IPv6) Specification" section
> >> 4.5 "Fragment Header" says the noninitial fragment packets have the
> >> Fragment Header containing "the Next Header value that identifies the
> >> first header after the Per-Fragment headers of the original packet"
> >> followed by "the fragment itself."
> >>
> >> Therefore, the data following the Fragment Header in the noninitial
> >> fragment packet must be treated as a fragment instead of another
> >> extension header, regardless of the Next Header value the Fragment
> >> Header contains.
> >> + case IP6_FRAGMENT:
> >> + bytes_read = iov_to_buf(pkt, pkt_frags,
> >> + ip6hdr_off + info->full_hdr_len + 2,
> >> + &buf, sizeof(buf));
> >> + if (bytes_read < sizeof(buf)) {
> >> + return false;
> >> + }
> >> +
> >> + info->full_hdr_len += 8;
> >> info->fragment = true;
> >> + subsequent = extract16(be16_to_cpu(buf), 3, 13);
> >
> > I don't understand what this is doing. I guess this is the
> > "don't parse extensions in fragments" change mentioned in the
> > commit message, but I don't see why this is the way to determine
> > that. This is testing the "fragment offset" field for being non-zero,
> > isn't it?
>
> Yes. A nonzero offset identifies a noninitial fragment. Its bytes are
> fragment data, so we must stop parsing extension headers there. For
> offset zero, we can continue parsing the headers present in the
> first fragment.
Ah, right. I should have scrolled further down in RFC8200, it
has some helpful diagrams of what the fragment packets end up
looking like. I understand what's going on now.
> > Otherwise the eth_parse_ipv6_hdr() changes look good to me, but I
> > think they're complex enough to be worth having in their own
> > patch separate from the eth_get_protocols() changes.
>
> That makes sense. The changes inside eth_parse_ipv6_hdr() need to be in
> one patch, but it can be still separate from the eth_get_protocols()
> changes.
>
> We can use your patch for the IPv4 change, as it also adds overflow
> safety and the additional sizeof(*iphdr) check.
>
> A separate patch should be written for the TCP bounds check and precede
> the IPv6 parser fixes. Correcting the AH length can make a TCP header
> reachable in cases where the old parser's incorrect offset caused the
> header copy to fail. Without the TCP bounds check, an oversized TCP data
> offset could then reach igb's header-splitting path as an out-of-range
> L5 offset. Keeping that ordering avoids an unsafe intermediate state.
>
> I plan to send a patch series featuring a patch for the TCP bounds check
> and another for the IPv6 parser fixes, while dropping the IPv4 change.
Thanks. Feel free to pick up whatever of my series makes sense
in that if that helps.
-- PMM