Repository navigation
Fix IPv6 extension header bounds validation - #1379
pamirmundt wants to merge 1 commit into
Conversation
htibosch
left a comment
There was a problem hiding this comment.
@pamirmundt , thanks for taking the afford to present these findings.
If I may ask, why did you start digging into the extension headers? Did you see a problem?
I tested the proposed changes in real silicon (STM32H7), connected with a switch to my laptop.
What we did is send extension headers of all sorts to trigger the various traps.
If you want I can send you the PY script.
I'm approving this PR.
While working on IPv6 UDP support on our STM32H7, one of our coding agents flagged the extension header parsing during a code review. We hadn’t encountered any runtime issues, but decided to investigate and validate the finding. |
Check extension header lengths before accessing their fields to prevent out-of-bounds reads on truncated packets. Validate lengths against the declared IPv6 payload and add regression tests for malformed and valid extension chains.
826ae68 to
3b2c9fc
Compare
Description
xCheckIPv6SizeFields()could read beyond the received packet when processing a truncated IPv6 extension-header chain withipconfigDRIVER_INCLUDED_RX_IP_CHECKSUM == 1.The parser accessed the extension header's fields before checking whether enough bytes remained. For example, if a packet contained only the first byte of the next extension header, the parser could read past the buffer while accessing its length field.
This change validates the available bytes before reading each extension header and ensures that the declared header length fits within the IPv6 payload.
It also uses remaining-length checks for the IPv6 payload and upper-layer protocol headers, avoiding unnecessary arithmetic on absolute offsets.
Testing
Added regression tests covering:
The truncation regression reproduces a one-byte out-of-bounds read with AddressSanitizer against the original implementation and passes with this fix.
Verification results:
The changes are limited to packet-length validation and preserve the existing handling of valid IPv6 packets.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.