Skip to content

Fix out-of-bounds read in GtpV2Layer with truncated TEID-present header#2181

Open
vsaraikin wants to merge 1 commit into
seladb:masterfrom
vsaraikin:fix/gtpv2-teid-present-oob-read
Open

Fix out-of-bounds read in GtpV2Layer with truncated TEID-present header#2181
vsaraikin wants to merge 1 commit into
seladb:masterfrom
vsaraikin:fix/gtpv2-teid-present-oob-read

Conversation

@vsaraikin

Copy link
Copy Markdown

Fixes #2171.

GtpV2Layer::isDataValid only requires sizeof(gtpv2_basic_header) + sizeof(uint32_t) bytes (8 bytes). That is enough for the basic header plus the sequence-number word of a TEID-absent header, but when the TEID-present flag is set the fixed header additionally carries the 4-byte TEID before the sequence word:

  • TEID absent: [basic header (4)][seq word (4)] → 8 bytes
  • TEID present: [basic header (4)][TEID (4)][seq word (4)] → 12 bytes

So a TEID-present packet of only 8 bytes passes validation, and getSequenceNumber() (which advances an extra 4 bytes when teidPresent is set) then reads a 32-bit word past the buffer — the OOB read reported in the issue (PoC 48200008deadbeef, version 2 + TEID-present, 8 bytes).

The fix makes isDataValid require the extra 4 bytes when the TEID-present flag is set, so a truncated TEID-present header is rejected before any accessor can read past the buffer. The flag lives in the basic header, which is already covered by the existing minimum-length check, so reading it here is safe.

Testing

  • Added a regression case to GtpV2LayerParsingTest: the 8-byte TEID-present PoC is now rejected by isDataValid, while the same header with the sequence word present (12 bytes) is accepted.
  • Verified under AddressSanitizer: the new GtpV2 tests pass clean with the fix; without the fix isDataValid accepts the truncated packet (the assertion fails, and the underlying getSequenceNumber read is OOB).
  • Full Packet++Test suite passes (258/258).

@vsaraikin vsaraikin marked this pull request as ready for review July 10, 2026 10:17
@vsaraikin vsaraikin requested a review from seladb as a code owner July 10, 2026 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PcapPlusPlus GTPv2 short TEID-present header sequence over-read

1 participant