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 basic support for simulating PLT stubs and shared libraries #320

Merged
merged 2 commits into from
Feb 23, 2023

Conversation

RyanGlScott
Copy link
Contributor

@RyanGlScott RyanGlScott commented Feb 20, 2023

This extends Data.Macaw.Symbolic.Testing in macaw-symbolic to be able to handle binaries that depend on shared libraries. This is fully functional for the x86-64 and AArch32 symbolic backends, and I have added test cases to the respective repos demonstrating that it works. (The PowerPC backend is not yet supported. At a minimum, this is blocked on GaloisInc/elf-edit#35.)

To implement this, I also needed to add some additional infrastructure to macaw-base (I put this infrastructure here as it doesn't depend on any Crucible-specific functionality):

  • Data.Macaw.Memory.ElfLoader.DynamicDependencies: a basic ELF dynamic loader that performs a breadth-first search over all DT_NEEDED entries that an ELF binary depends on (both directly and indirectly).
  • Data.Macaw.Memory.ElfLoader.PLTStubs: a collection of heuristics for detecting the addresses of PLT stubs in a dynamically linked binary.

It is worth noting that shared libraries are rife with nuance and subtlety, and the way macaw models shared libraries is not 100% accurate. I have written a length Note [Shared libraries] in Data.Macaw.Symbolic.Testing to describe where corners had to be cut.

Fixes #318.

Copy link
Contributor

@bboston7 bboston7 left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you for upstreaming this!

This:

* Bumps the `elf-edit` submodule to bring in the changes from
  GaloisInc/elf-edit#34.
* Updates `Data.Macaw.Memory.ElfLoader` to consolidate the symbol table logic
  with the corresponding functions from `elf-edit`.

Fixes #277.
This extends `Data.Macaw.Symbolic.Testing` in `macaw-symbolic` to be able to
handle binaries that depend on shared libraries. This is fully functional for
the x86-64 and AArch32 symbolic backends, and I have added test cases to the
respective repos demonstrating that it works. (The PowerPC backend is not yet
supported. At a minimum, this is blocked on GaloisInc/elf-edit#35.)

To implement this, I also needed to add some additional infrastructure to
`macaw-base` (I put this infrastructure here as it doesn't depend on any
Crucible-specific functionality):

* `Data.Macaw.Memory.ElfLoader.DynamicDependencies`: a basic ELF dynamic
  loader that performs a breadth-first search over all `DT_NEEDED` entries
  that an ELF binary depends on (both directly and indirectly).
* `Data.Macaw.Memory.ElfLoader.PLTStubs`: a collection of heuristics for
  detecting the addresses of PLT stubs in a dynamically linked binary.

It is worth noting that shared libraries are rife with nuance and subtlety,
and the way `macaw` models shared libraries is not 100% accurate. I have
written a length `Note [Shared libraries]` in `Data.Macaw.Symbolic.Testing`
to describe where corners had to be cut.

Fixes #318.
@RyanGlScott RyanGlScott marked this pull request as ready for review February 23, 2023 20:48
@RyanGlScott RyanGlScott merged commit 97c61e4 into master Feb 23, 2023
@RyanGlScott RyanGlScott deleted the T318 branch February 23, 2023 22:16
RyanGlScott added a commit to GaloisInc/macaw-loader that referenced this pull request Feb 23, 2023
This:

* Bumps the `elf-edit` submodule to bring in the changes from
  GaloisInc/elf-edit#34, which adds `decodeHeaderDynsym`.
* Bumps the `macaw` submodule to bring in the changes from
  GaloisInc/macaw#320, which changes the ELF loader to always load
  dynamic function symbols.

  (Bumping the `macaw` submodule also requires bumping the `crucible`,
  `llvm-pretty`, and `semmc` submodules to adapt to recent changes.)
* Modifies the code for X86-64, AArch32, and PPC to always include dynamic
  function symbols.

Fixes #12.
RyanGlScott added a commit to GaloisInc/macaw-loader that referenced this pull request Feb 25, 2023
This:

* Bumps the `elf-edit` submodule to bring in the changes from
  GaloisInc/elf-edit#34, which adds `decodeHeaderDynsym`.
* Bumps the `macaw` submodule to bring in the changes from
  GaloisInc/macaw#320, which changes the ELF loader to always load
  dynamic function symbols.

  (Bumping the `macaw` submodule also requires bumping the `crucible`,
  `llvm-pretty`, and `semmc` submodules to adapt to recent changes.)
* Modifies the code for X86-64, AArch32, and PPC to always include dynamic
  function symbols.

Fixes #12.
RyanGlScott added a commit to RyanGlScott/pate that referenced this pull request Nov 14, 2023
Previously, PATE had no PLT stub-finding heuristics for PPC32, which meant that
PATE would crash whenever it tried to execute code that invokes a PLT stub.
While it is difficult in general to predict what the layout of a `.plt` section
will be on an arbitrary PPC32 binary, we can at least give PATE some plausible
heuristics that were derived from the `target1-self` binary.

Previously, the code in `Pate.Discovery.PLT` hard-coded heuristics that were
specific to AArch32, so this patch needed to cargo-cult some code from
GaloisInc/macaw#320 in order to appropriately
generalize the code to other architectures.
danmatichuk pushed a commit to GaloisInc/pate that referenced this pull request Nov 15, 2023
Previously, PATE had no PLT stub-finding heuristics for PPC32, which meant that
PATE would crash whenever it tried to execute code that invokes a PLT stub.
While it is difficult in general to predict what the layout of a `.plt` section
will be on an arbitrary PPC32 binary, we can at least give PATE some plausible
heuristics that were derived from the `target1-self` binary.

Previously, the code in `Pate.Discovery.PLT` hard-coded heuristics that were
specific to AArch32, so this patch needed to cargo-cult some code from
GaloisInc/macaw#320 in order to appropriately
generalize the code to other architectures.
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 functionality for computing locations of PLT stubs in ELF binaries
2 participants