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

Add elfIsPie to check for position-independent executables #47

Merged
merged 1 commit into from
Jan 7, 2025

Conversation

RyanGlScott
Copy link
Contributor

@RyanGlScott RyanGlScott commented Jan 7, 2025

This adds elfIsPie, a function which returns True if the supplied ElfHeaderInfo corresponds to a position-independent executable (PIE). The logic for elfIsPie is adapted from the source code for the file binutils program, which was in turn summarized here: https://unix.stackexchange.com/a/435038

This adds a directory dependency to elf-edit, as directory is used to check file permissions as a fallback. This dependency should be cheap, as directory is a GHC boot library.

Fixes #46.

This adds `elfIsPie, a function which returns `True` if the supplied
`ElfHeaderInfo` corresponds to a position-independent executable (PIE). The
logic for `elfIsPie` is adapted from the source code for the `file` binutils
program, which was in turn summarized here:
https://unix.stackexchange.com/a/435038

This adds a `directory` dependency to `elf-edit`, as `directory` is used to
check file permissions as a fallback. This dependency should be cheap, as
`directory` is a GHC boot library.

Fixes #46.
Copy link
Contributor

@langston-barrett langston-barrett left a comment

Choose a reason for hiding this comment

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

Love it!

@RyanGlScott RyanGlScott merged commit 872f89f into main Jan 7, 2025
3 checks passed
@RyanGlScott RyanGlScott deleted the T46-elf-pie-detection branch January 7, 2025 20:44
@kquick
Copy link
Member

kquick commented Jan 7, 2025

Minor quibble: PIE is an acronym (like ELF), so I would have preferred the name elfIsPIE. I know we aren't consistent on this, just quibbling.

It would be good to document the "is the file executable" fallback in the haddocks themselves. I'm not sure what percentage of the time the fallback is needed, but it would probably be surprising for people to know that file metadata and not ELF data can control the PIE result. I can easily see a scenario where an ELF file is copied for analysis without maintaining executable privileges...

@RyanGlScott
Copy link
Contributor Author

PIE is an acronym (like ELF), so I would have preferred the name elfIsPIE.

Right... I am increasingly finding myself on the side of not capitalizing all of the letters in acronyms when converting them to lowerCamelCase Haskell names, as it leads to strangeness like dynPLTRel. (Is the acronym PLT or PLTR?) That being said, I don't feel strongly about this—I can change this if you want.

It would be good to document the "is the file executable" fallback in the haddocks themselves.

Sure thing. I've opened #48 for this.

@kquick
Copy link
Member

kquick commented Jan 7, 2025

But is dynPltRel checking dynamically that P is less-than Rel? :-) I don't feel strongly enough to cause PR churn though.

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.

Add position-independent executable (PIE) detection capabilities to Data.ElfEdit.Dynamic
3 participants