Skip to content

avoid out-of-bounds read on empty ELF note name - #502

Open
fr-manvi wants to merge 1 commit into
google:mainfrom
fr-manvi:elf-note-empty-name
Open

avoid out-of-bounds read on empty ELF note name#502
fr-manvi wants to merge 1 commit into
google:mainfrom
fr-manvi:elf-note-empty-name

Conversation

@fr-manvi

Copy link
Copy Markdown

GetBuildId walks the notes in every SHT_NOTE section, and each note's name comes from NoteIter::Next as name_ = StrictSubstr(remaining_, 0, note.n_namesz). The n_namesz field is read straight out of the note header, so it is attacker-controlled just like the rest of the object. When a note carries n_namesz == 0 the name_ view is empty, and the very next line checks name_[name_.size() - 1] to trim a trailing NUL, so name_.size() - 1 wraps to SIZE_MAX and the operator[] reads outside the view. I hit it feeding a crafted ET_DYN with a single empty-name note; a build with libc++ hardening traps in NoteIter::Next, and it is on the default path since GetBuildId runs for every non-object input. Guarding the trim with !name_.empty() closes it while leaving the normal case (a name ending in NUL) unchanged. Added a yaml2obj regression alongside the other elf tests.

@fr-manvi

Copy link
Copy Markdown
Author

any update?

1 similar comment
@fr-manvi

Copy link
Copy Markdown
Author

any update?

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.

1 participant