Fix heap-buffer-overflow in legacy maps section parsing#1052
Fix heap-buffer-overflow in legacy maps section parsing#1052
Conversation
The map_count computation used ceiling division when the section size was not evenly divisible by map_record_size, which can produce a count whose last record extends past the section data buffer. This causes a heap-buffer-overflow when the platform's parse_maps_section callback iterates all records. Fix by using floor division, and add a pre-call bounds check as a safety invariant to prevent future regressions. Signed-off-by: Michael Agun <danielagun@microsoft.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughModified Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
parse_map_sections in elf_map_parser.cpp computes map_count using ceiling division when the section size isn't evenly
divisible by map_record_size:
map_count = (max_record_end + map_record_size - 1) / map_record_size;
This can produce a count where the last record's byte range exceeds the section buffer. The platform parse_maps_section
callback then performs an out-of-bounds read via memcpy.
Example: section=85 bytes, map_record_size=28 → ceiling gives 4 records (needs 112 bytes), but only 85 are available.
Fix
Two changes:
Validation
Impact
Both the Windows (_parse_maps_section_windows) and Linux (parse_maps_section_linux) callbacks are affected — neither receives the buffer size, so both rely on a correct map_count from the caller.
A follow-up PR will add a regression test fixture using the fuzzer crash input.
Fixes #1051
Summary by CodeRabbit
Bug Fixes