eliben / pyelftools

Parsing ELF and DWARF in Python
Other
1.99k stars 507 forks source link

Add support for aarch64 PAC/BTI markers #526

Closed rossburton closed 9 months ago

rossburton commented 9 months ago

The .note.gnu.property segment will contain GNU_PROPERTY_AARCH64_FEATURE_1_BTI and GNU_PROPERTY_AARCH64_FEATURE_1_PAC markers if the code is compiled with BTI/PAC enabled.

readelf can dump these:

$ readelf -n .../libacl.so

Displaying notes found in: .note.gnu.property
  Owner                Data size    Description
  GNU                  0x00000010   NT_GNU_PROPERTY_TYPE_0
      Properties: AArch64 feature: BTI, PAC

But pyelftools doesn't know how to parse the data.

sevaa commented 9 months ago

Thanks for letting know. If you feel up to it, submit a PR. If not, please share a minimal binary with those properties, and someone will get to it (eventually).

rossburton commented 9 months ago

Here's a representative library:

libattr.so.1.1.2501.zip

I have most of a patch locally that I've been using and just needs a test case, but due to https://github.com/eliben/pyelftools/issues/524 I can't submit it.

sevaa commented 9 months ago

Didn't keep other contributors from submitting PRs, myself included. :) I might be missing something legally.

Is that a representative binary or a minimal one? For the autotest purposes, we'd prefer a minimal one, and one with no risk of having proprietary code in it.

rossburton commented 9 months ago

Is that a representative binary or a minimal one? For the autotest purposes, we'd prefer a minimal one, and one with no risk of having proprietary code in it.

Representative, because I had it to hand (it's from GNU attr).

Here's int main(void) { return 0;} compiled with PAC/BTI:

pac-bti-test.zip

sevaa commented 9 months ago

The PR has landed. Is this still an issue?

rossburton commented 9 months ago

So it looks like GitHub doesn't mail when issues are mentioned in PRs, so i didn't notice that PR at all!

$ python3 ./scripts/readelf.py  /yocto/ross/build/tmp/sysroots-components/cortexa57/libice/usr/lib/libICE.so -n

Displaying notes found in: .note.gnu.property
  Owner                Data size        Description
  GNU                  0x00000010   NT_GNU_PROPERTY_TYPE_0 (program properties)
      Properties: aarch64 feature: bti, pac

That will do nicely, thanks.