This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Do not hang when parsing a malformed .debug_pub* section.
ClosedPublic

Authored by ikudrin on Jul 2 2020, 7:10 AM.

Details

Summary

The parsing method did not check reading errors and might easily fall into an infinite loop on an invalid input because of that.

Diff Detail

Event Timeline

ikudrin created this revision.Jul 2 2020, 7:10 AM
jhenderson added inline comments.Jul 3 2020, 12:27 AM
lld/ELF/DWARF.h
59

Why did the types here need to change?

lld/ELF/SyntheticSections.cpp
2713

Could you put a comment here saying what the 0 means (i.e. /*Something=*/0), please?

lld/test/ELF/gdb-index-invalid-pubnames.s
6

It might make sense to extend this test to show that LLD doesn't use the warned-for pubnames section, if there's a way for that to make sense.

llvm/test/DebugInfo/X86/dwarfdump-debug-pubnames-invalid.s
1 ↗(On Diff #275105)

I guess the pubnames section is fairly straightforward, but I personally feel like it would be best to write the testing for this and D83050 as gtest unit tests. That being said, a single test that shows how llvm-dwarfdump handles errors for malformed pubnames sections might make sense, although in that case I'd put it alongside the debug_line_invalid.test in the llvm-dwarfdump directory.

I would probably add basic coverage for the .debug_pubtypes and the GNU variant sections too, since they go through different code paths to get there.

ikudrin updated this revision to Diff 275403.Jul 3 2020, 8:33 AM
ikudrin marked 5 inline comments as done.
ikudrin added inline comments.Jul 3 2020, 8:33 AM
lld/ELF/DWARF.h
59

This helps to have access to the sec field without casing. That is used in readPubNamesAndTypes().

lld/ELF/SyntheticSections.cpp
2713

OK, changed to config->wordsize to avoid uncertainties.

lld/test/ELF/gdb-index-invalid-pubnames.s
6

This test is solely about avoiding hanging in LLD; it should be as short and simple as possible. There are other tests for LLD to check that the information from .debug_gnu_pub* sections is passed to the index. And there are (or will be) tests for llvm-dwarfdump to check what is read from valid or malformed sections.

llvm/test/DebugInfo/X86/dwarfdump-debug-pubnames-invalid.s
1 ↗(On Diff #275105)

I usually prefer lit tests, because they are much handier and easier to maintain, especially in cases like that, with just two line of source code and a few RUN/CHECK commands.

I'll move the test to the directory of llvm-dwarfdump tests and extend it to cover all four tables.

This revision is now accepted and ready to land.Jul 5 2020, 11:53 PM
dblaikie added inline comments.Jul 6 2020, 6:24 PM
llvm/test/tools/llvm-dwarfdump/X86/debug_pub_tables_invalid.s
3–8

Might be nice if you could test all these in one go? (so it's one invocation of llvm-dwarfdump rather than 4 - save on process overhead, etc)

ikudrin updated this revision to Diff 276024.Jul 7 2020, 5:53 AM
ikudrin marked an inline comment as done.
  • Updated the test to check everything in one run.
This revision was automatically updated to reflect the committed changes.