Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libcdb: Load debug info and unstrip libc binary #1828

Merged
merged 13 commits into from
Oct 3, 2021

Conversation

peace-maker
Copy link
Member

The debug info is obtained from a debuginfod server maintained by systemtap.org. elfutils is used to unstrip the binary and merge the debug info back.

Try to unstrip every libc binary downloaded by the libcdb module by default and add a new unstrip_libc(filename) function to handle other libc binaries.

Closes #1818

The debug info is obtained from a debuginfod server maintained by systemtap.org. elfutils is used to unstrip the binary and merge the debug info back.

Try to unstrip every libc binary downloaded by the libcdb module by default. Gallopsled#1818
@peace-maker
Copy link
Member Author

Hmm, I'm not sure what GHA is doing to the filesystem. Sometimes it appears to be fine e.g. here.
Those are tests against an external service again, so maybe just not run them?

@peace-maker
Copy link
Member Author

It appears to be a problem with the elfutils version installed. The version installed on focal 0.176-1.1build1 failed on the last run. The bionic version 0.170-0.4ubuntu0.1 is fine and my local version 0.182 as well.

Copy link
Collaborator

@heapcrash heapcrash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like CI is failing, and I've got a few suggestions for doctests

log.info_once("Using cached data from %r", cache)
return cache, True

def unstrip_libc(filename):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs doctests for a few examples

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"A few examples" = unstripping more than just one libc?
I've added a few more tests, is this what you had in mind?

@heapcrash
Copy link
Collaborator

Any chance for updates to address the requested changes?

@peace-maker
Copy link
Member Author

Since the tests seem to fail on certain buggy elfutils versions installed on the CI workers, I'm not sure how to persue with this.

@Arusekk
Copy link
Member

Arusekk commented May 26, 2021

please try to print the full error message in case of failure, so that we can debug the buggy CI

This will hopefully get logged during doctests.
@Arusekk
Copy link
Member

Arusekk commented May 28, 2021

So it says invalid section alignment... whatever that means..

@peace-maker
Copy link
Member Author

:( should we build elfutils from source in CI to work around this? It appears to be fixed in later versions like the one in 20.10.

@heapcrash
Copy link
Collaborator

:( should we build elfutils from source in CI to work around this? It appears to be fixed in later versions like the one in 20.10.

I don't think we want to include functionality that requires bespoke builds / anything non-standard on 18.04 / 20.04

@Arusekk?

@peace-maker
Copy link
Member Author

I think only the version packaged on 20.04 is buggy with the libc we fetch in the test. 18.04 and 20.10+ is fine. I'll try to switch to a different libc binary that works on 20.04 too for the doctests. It'd be a shame to strip this feature just because a buggy package version is being used atm.

@heapcrash
Copy link
Collaborator

heapcrash commented Jun 11, 2021 via email

Use APT Pinning to select the newer elfutils version from groovy instead of the buggy 0.176 version available in focal.
@peace-maker
Copy link
Member Author

I've fixed the CI by installing a newer elfutils package version from Ubuntu groovy explicitly now while the worker is still on focal.

@Arusekk Arusekk requested a review from heapcrash July 23, 2021 16:13
@Arusekk Arusekk merged commit 92911cb into Gallopsled:dev Oct 3, 2021
@peace-maker peace-maker deleted the libcdb_unstrip branch October 3, 2021 18:50
@Arusekk
Copy link
Member

Arusekk commented Jan 4, 2022

The CI introduced by this now breaks. I don't know why yet.

@peace-maker
Copy link
Member Author

Since ubuntu groovy 20.10 is EOL the repository was removed and we can't fetch the elfutils package from a newer ubuntu version anymore. The runners use 20.04 which uses an older libc than the newer ubuntu versions 21.04 and 21.10, so we can't use the same trick to just grab the newer elfutils package from those distributions.

I guess we'll have to resort to building elfutils and eu-unstrip ourselves or disable those tests until the runners are updated to some newer base image.
I started working on building elfutils in CI, but got stuck and didn't had time to investigate further yet. Building the newer version manually in CI causes the tests to fail in the same way as if we'd be using the old binary in the official package. It might be due to the binary still using the old libelf libary instead of the newer one.

gogo2464 pushed a commit to gogo2464/pwntools that referenced this pull request Sep 10, 2023
* libcdb: Load debug info and unstrip libc binary

The debug info is obtained from a debuginfod server maintained by systemtap.org. elfutils is used to unstrip the binary and merge the debug info back.

Try to unstrip every libc binary downloaded by the libcdb module by default. Gallopsled#1818

* Install elfutils on CI

* Update CHANGELOG.md

* Add more tests

* Fix negative test

* Raise an exception when eu-unstrip fails

This will hopefully get logged during doctests.

* Install elfutils 0.181 from groovy

Use APT Pinning to select the newer elfutils version from groovy instead of the buggy 0.176 version available in focal.

* Fix missing import of requests

pylint?

Co-authored-by: Arusekk <[email protected]>
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.

Unstrip ELF files fetched with libcdb
3 participants