This is an archive of the discontinued LLVM Phabricator instance.

Added phdr upper bound checks to ElfObject
ClosedPublic

Authored by mothran on Oct 3 2017, 12:52 PM.

Details

Reviewers
davide
rafael
Summary

Ensure the program_headers call will fail correctly if the program
headers are larger than the underlying buffer. New test to ensure
llvm-objdump can safely process a invalid phdr in a elf file.

Diff Detail

Event Timeline

mothran created this revision.Oct 3 2017, 12:52 PM
davide edited edge metadata.Oct 3 2017, 5:36 PM

You need to add a testcase, probably.

I am unable to construct a correctly malformed file with yaml2obj, but was able to create a test with hexedit.
This is my first time committing a patch to LLVM and was wondering, do I have to use arc to submit a patch with a binary file? And should I do that as a follow up commit or a whole new review and one patch?

I am unable to construct a correctly malformed file with yaml2obj, but was able to create a test with hexedit.

I'm surprised you can't craft with yaml2obj. What's the problem? If it's a limitation in yaml2obj we might consider fixing it.

This is my first time committing a patch to LLVM and was wondering, do I have to use arc to submit a patch with a binary file? And should I do that as a follow up commit or a whole new review and one patch?

You should attach your test (whatever it is) to the same patch, so it's grouped logically (and it' easier to bisect, revert, doing archeology, etc..)

The simplest way to trigger this issue is by adjusting the phoff in the elf header and that did not appear to be controllable from my read of the yaml2obj code at: https://github.com/llvm-mirror/llvm/blob/master/tools/yaml2obj/yaml2elf.cpp#L180

mothran updated this revision to Diff 117723.Oct 4 2017, 1:15 PM
mothran edited the summary of this revision. (Show Details)
davide added a comment.Oct 4 2017, 1:17 PM

Almost there. Do you have commit access or you want me to commit on your behalf?

include/llvm/Object/ELF.h
147

is this clang formatted?

test/Object/elf-invalid-phdr.test
2

Please add a comment on how to generate the test in case we want to reproduce in future.

mothran updated this revision to Diff 117850.Oct 5 2017, 10:48 AM

I updated the diff to correctly use FileCheck with the llvm-objdump output and clang-formated the code in ELF.h. I don't have commit access so if you could commit on my behalf that would be great.

include/llvm/Object/ELF.h
147

Is there a way to cleanly run clang-format across the build to double check for myself?

davide accepted this revision.Oct 17 2017, 9:07 AM

LGTM, do you need somebody to commit this on your behalf?

This revision is now accepted and ready to land.Oct 17 2017, 9:07 AM
davide closed this revision.Nov 15 2017, 9:59 AM