Bound attacker-controlled block lengths in LightPcapNg (OOM/OOB in EPB parsing)#2182
Draft
vsaraikin wants to merge 1 commit into
Draft
Bound attacker-controlled block lengths in LightPcapNg (OOM/OOB in EPB parsing)#2182vsaraikin wants to merge 1 commit into
vsaraikin wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2180.
The vendored LightPcapNg parser trusts several length fields read straight from the input, which lets a malformed pcapng drive an attacker-controlled
calloc()/memcpy():parse_by_block_type(), theLIGHT_ENHANCED_PACKET_BLOCKhandler readscaptured_packet_lengthfrom the block body, pads it, and uses it directly to size acalloc()and thenmemcpy()— before validating it against the block. A block can keepblock_total_lengthsmall while settingcaptured_packet_lengthhuge, causing a multi-gigabyte allocation and an out-of-bounds read past the input buffer.LIGHT_CUSTOM_DATA_BLOCKhas the same pattern with itslenfield.__parse_mem_copy()use theDCHECK_*macros, which are no-ops in release builds (light_stopexpands to(void)0), soblock_total_lengthitself is never bounded against the remaining buffer.The fix adds real (release-active) bounds:
__parse_mem_copy(), reject a block whoseblock_total_lengthis smaller than the mandatory framing or larger than the bytes left in the buffer, before dispatching to the per-block parser.captured_packet_length/lento the space the block can actually hold (mirroring howLIGHT_SIMPLE_PACKET_BLOCKalready derives its length fromblock_total_length), so a bogus length can't over-size thecalloc()/memcpy().Testing (AddressSanitizer)
Verified against the parser (
light_read_from_memory) directly, since the DCHECK-based checks are compiled out in release:block_total_length = 32,captured_packet_length = 0x10000): before the fix ASan reportsstack-buffer-overflow READ of size 65536inparse_by_block_type(light_pcapng.c:172, thememcpy); after the fix it is bounded and clean.captured_packet_length = 8, correctly framed): parses unchanged —captured_packet_lengthis preserved (not clamped) and the packet bytes are copied correctly, so well-formed captures are unaffected.The bug originates from OSS-Fuzz (
FuzzTargetNg); the project's fuzzers exercise this path going forward. Happy to also add a regression sample toTests/Fuzzers/RegressionTestsif you'd like one in the corpus.Note
3rdParty/LightPcapNgis vendored, so the change follows the surrounding vendored style and is marked with// PCPP Patch (GH #2180)comments consistent with the existing patches in this file.