Fix heap-buffer-overflow in DWARF v5 line info parser#493
Merged
EricRahm merged 2 commits intogoogle:mainfrom Apr 24, 2026
Merged
Fix heap-buffer-overflow in DWARF v5 line info parser#493EricRahm merged 2 commits intogoogle:mainfrom
EricRahm merged 2 commits intogoogle:mainfrom
Conversation
Add bounds check for directory_index in the DWARF v5 file name parsing path, matching the existing validation in the DWARF v4 path. Without this check, a crafted ELF with an out-of-range directory_index causes an out-of-bounds read in GetExpandedFilename().
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Contributor
Author
|
@EricRahm Could you review this security fix when you get a chance? It adds a missing bounds check in the DWARF v5 line info parser that allows a heap-buffer-overflow via crafted ELF files. |
Collaborator
|
Thanks @sharadboni! Sorry for the delay, lets get this landed. If possible it'd be great to get a follow up adding a lit test for this. |
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.
Summary
The DWARF v5 file name parsing path in
LineInfoReader(src/dwarf/line_info.cc) does not validate thatdirectory_indexis within the bounds ofinclude_directories_before pushing the file name entry. The DWARF v4 code path already has this check (line 149), but the v5 path is missing it.When
GetExpandedFilename()later uses the uncheckeddirectory_indexto look upinclude_directories_[directory_index], a crafted ELF file with an out-of-rangedirectory_indextriggers a heap-buffer-overflow read.Fix
Add the same bounds check that exists in the v4 path:
This is inserted right before
filenames_.push_back(file_name)in the v5 parsing loop (after all entry format fields have been read), so the index is fully resolved before validation.Reproduction
A minimal crafted ELF with a DWARF v5
.debug_linesection containing adirectory_indexlarger than the directory count triggers the bug. Under AddressSanitizer:Test plan
"directory index out of range"instead of crashing