This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Don't crash when parsing a file with external version definition references
ClosedPublic

Authored by arichardson on Sep 29 2017, 4:05 AM.

Details

Summary

We were crashing when linking telnetd in FreeBSD because lld was emitting
corrupted output files for --norosegment. In this file the version index of some symbols
was set to 9 but lld only found 8 version definitions.

I am not sure how to create a minimal .so file that also exposes this behaviour so I just added the one that initially caused the error to Inputs/

This partially addresses https://bugs.llvm.org/show_bug.cgi?id=34705

Diff Detail

Repository
rL LLVM

Event Timeline

arichardson created this revision.Sep 29 2017, 4:05 AM
ruiu edited edge metadata.Oct 1 2017, 6:57 PM

Even with this patch, you cannot link telnetd in FreeBSD because this patch is to just prevent lld from crashing, right? I wonder why you don't add a feature so that you can link telnetd.

I was able to link telnetd with these changes, possibly it doesn't use any of the symbols with the external version reference.

I don't really know anything about ELF versions so I thought as a first step not crashing would be useful. Also I don't think LLD should crash when reading an invalid input file but rather reject it.

arichardson edited the summary of this revision. (Show Details)
arichardson added a reviewer: grimar.

The issue that caused the corrupted input file appears to be fixed by https://reviews.llvm.org/D38579 and https://reviews.llvm.org/D38580. However we should still never access out-of-bounds memory, so turned this into a hard error

fix typos in test case

ruiu accepted this revision.Oct 5 2017, 11:58 AM

LGTM

ELF/InputFiles.cpp
782–784 ↗(On Diff #117825)

Since this is presumably a rare error (we wouldn't have noticed it without a bug of lld itself), I'd make it slightly shorter.

error: corrupt input file: version definition index 10 for symbol bar is out of range
>>> defined in foo.so
This revision is now accepted and ready to land.Oct 5 2017, 11:58 AM
This revision was automatically updated to reflect the committed changes.