Skip to content

Fix out-of-bounds reads in IcmpLayer getters on truncated packets - #2240

Open
Mrmaxmeier wants to merge 1 commit into
seladb:devfrom
Mrmaxmeier:fix/icmp-truncated-layer-oob
Open

Fix out-of-bounds reads in IcmpLayer getters on truncated packets#2240
Mrmaxmeier wants to merge 1 commit into
seladb:devfrom
Mrmaxmeier:fix/icmp-truncated-layer-oob

Conversation

@Mrmaxmeier

Copy link
Copy Markdown

Hi,

we ran into an out-of-bounds read ASAN report with the FuzzTarget.cpp harness:

==18==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7b90f7df0539 at pc 0x561cdbc3ca9f bp 0x7ffd35723b70 sp 0x7ffd35723b68
READ of size 2 at 0x7b90f7df0539 thread T0
SCARINESS: 14 (2-byte-read-heap-buffer-overflow)
    #0 0x561cdbc3ca9e in readParsedPacket(pcpp::Packet, pcpp::Layer*) /src/PcapPlusPlus/Tests/Fuzzers/ReadParsedPacket.h:357:61
    #1 0x561cdbc3691c in LLVMFuzzerTestOneInput /src/PcapPlusPlus/Tests/Fuzzers/FuzzTarget.cpp:66:5

DEDUP_TOKEN: readParsedPacket(pcpp::Packet, pcpp::Layer*)--LLVMFuzzerTestOneInput--fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long)
0x7b90f7df0539 is located 0 bytes after 41-byte region [0x7b90f7df0510,0x7b90f7df0539)
allocated by thread T0 here:
    #0 0x561cdbc3461d in operator new[](unsigned long) /src/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:111:37
    #1 0x561cdbc4f820 in make_unique<unsigned char[], 0> /usr/local/bin/../include/c++/v1/__memory/unique_ptr.h:765:55
    #2 0x561cdbc4f820 in pcpp::PcapFileReaderDevice::getNextPacket(pcpp::RawPacket&) /src/PcapPlusPlus/Pcap++/src/PcapFileDevice.cpp:780:23
    #3 0x561cdbc36a14 in LLVMFuzzerTestOneInput /src/PcapPlusPlus/Tests/Fuzzers/FuzzTarget.cpp:71:19

The input is included in this PR under Tests/Fuzzers/RegressionTests/regression_samples/crash-icmp-info-request-truncated.

The getX() methods in IcmpLayer.h currently only check the type field, and return a casted struct without verifying that the underlying buffer has enough data. This PR adjusts these getters to return nullptr in the case of packets without enough data. It also adds a test that verifies this behaviour for various ICMP message types.

Thanks!


Found by the CISPA Fandango team while triaging findings in oss-fuzz harnesses.

@Mrmaxmeier
Mrmaxmeier requested a review from seladb as a code owner August 27, 2026 14:41
@Mrmaxmeier Mrmaxmeier changed the title Fix out-of-bounds reads in IcmpLayer message getters on truncated pac… Fix out-of-bounds reads in IcmpLayer getters on truncated packets Aug 27, 2026
@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.81%. Comparing base (7f99131) to head (71f0a41).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #2240      +/-   ##
==========================================
+ Coverage   82.71%   82.81%   +0.09%     
==========================================
  Files         333      333              
  Lines       60367    60337      -30     
  Branches    12879    12509     -370     
==========================================
+ Hits        49933    49967      +34     
- Misses       9021     9498     +477     
+ Partials     1413      872     -541     
Flag Coverage Δ
23.11.6 7.24% <1.25%> (-0.03%) ⬇️
24.11.5 7.23% <1.25%> (-0.06%) ⬇️
25.11.1 7.27% <1.25%> (-0.02%) ⬇️
alpine320 76.96% <94.00%> (+0.05%) ⬆️
fedora42 76.52% <96.00%> (+0.03%) ⬆️
macos-15 82.36% <97.75%> (+0.05%) ⬆️
macos-26 82.37% <97.75%> (+0.05%) ⬆️
macos-26-intel 82.28% <97.75%> (+0.05%) ⬆️
mingw32 ?
mingw64 ?
npcap ?
rhel94 76.35% <94.23%> (+0.05%) ⬆️
ubuntu2204 76.37% <94.23%> (+0.02%) ⬆️
ubuntu2404 76.65% <94.00%> (+0.02%) ⬆️
ubuntu2604 76.62% <96.00%> (+0.05%) ⬆️
ubuntu2604-arm64 76.44% <95.91%> (+0.03%) ⬆️
ubuntu2604-icpx 59.20% <95.12%> (+0.04%) ⬆️
unittest 82.81% <100.00%> (+0.09%) ⬆️
windows-2022 85.88% <100.00%> (+0.15%) ⬆️
windows-2025 85.61% <100.00%> (+0.16%) ⬆️
winpcap 85.91% <100.00%> (+0.25%) ⬆️
xdp 53.02% <94.23%> (+0.06%) ⬆️

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.

Every get*Data() method checked only the ICMP message type before casting
the layer buffer to the fixed-size structure that type implies, so a
truncated capture produced an IcmpLayer shorter than the structure it
claims to be and reading any field past the layer was out of bounds.

Route those getters through a castMessageData() helper that requires the
whole structure to be present, and tighten isDataValid() accordingly.

Assisted-By: Claude Opus 5 <noreply@anthropic.com>
@Mrmaxmeier
Mrmaxmeier force-pushed the fix/icmp-truncated-layer-oob branch from 71f0a41 to 1316e19 Compare August 27, 2026 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants