Skip to content

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

Open
vsaraikin wants to merge 2 commits into
seladb:devfrom
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 2 commits into
seladb:devfrom
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

@Dimi1010 Dimi1010 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Dimi1010
Dimi1010 changed the base branch from master to dev July 18, 2026 17:30
@Dimi1010

Copy link
Copy Markdown
Collaborator

Closing and reopen to run CI after base branch change.

@Dimi1010 Dimi1010 closed this Jul 18, 2026
@Dimi1010 Dimi1010 reopened this Jul 18, 2026
@codecov

codecov Bot commented Jul 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.81%. Comparing base (3aae85b) to head (346fb54).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #2181      +/-   ##
==========================================
+ Coverage   82.66%   82.81%   +0.14%     
==========================================
  Files         332      332              
  Lines       60155    60011     -144     
  Branches    12768    11799     -969     
==========================================
- Hits        49727    49697      -30     
- Misses       9019     9463     +444     
+ Partials     1409      851     -558     
Flag Coverage Δ
23.11.6 7.26% <0.00%> (-0.03%) ⬇️
24.11.5 7.26% <0.00%> (-0.04%) ⬇️
25.11.1 7.26% <0.00%> (-0.04%) ⬇️
alpine320 76.87% <100.00%> (+<0.01%) ⬆️
fedora42 76.43% <100.00%> (-0.02%) ⬇️
macos-15 82.27% <100.00%> (+<0.01%) ⬆️
macos-26 82.27% <100.00%> (+<0.01%) ⬆️
macos-26-intel 82.20% <100.00%> (+<0.01%) ⬆️
mingw32 70.98% <50.00%> (-0.02%) ⬇️
mingw64 70.94% <50.00%> (+0.06%) ⬆️
npcap ?
rhel94 76.24% <100.00%> (+<0.01%) ⬆️
ubuntu2204 76.28% <100.00%> (+<0.01%) ⬆️
ubuntu2404 76.57% <100.00%> (-0.02%) ⬇️
ubuntu2604 76.54% <100.00%> (+0.02%) ⬆️
ubuntu2604-arm64 76.35% <100.00%> (-0.02%) ⬇️
ubuntu2604-icpx ?
unittest 82.81% <100.00%> (+0.14%) ⬆️
windows-2022 85.80% <100.00%> (+0.10%) ⬆️
windows-2025 85.55% <100.00%> (+0.12%) ⬆️
winpcap 85.84% <100.00%> (+0.20%) ⬆️
xdp 52.90% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

2 participants