Repository navigation
PE: read the loading environment from the optional header - #800
Conversation
Every PE was reported as os == "windows", so a UEFI module was handed to angr's SimWindows, which reaches for a Win32 syscall calling convention. On RISC-V there is no such convention and the project failed to build at all. The optional header's subsystem says which environment loads the image; read it. A Terse Executable only exists inside UEFI firmware, so it says so too.
|
THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS
Before — the RISC-V driver raises before the project exists; the two TE angr master + cle masterAfter — all three load as UEFI, and the driver that could not be built at with this changeThe AArch64 TE convention is unchanged, which is the point: only the two x86 session: sharpen |
|
THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS Validation record for the UEFI chain: angr/binaries#218, #800, and the Base revisions: angr Suites
Merge-base lint and typecheck, the comparison the hosted jobs make per Both repositories' full pre-commit hook sets pass; What did not run. The complete workspace gate did not run. Five corpus sweep Test inputs. session: sharpen |
|
Corpus decompilation diffs can be found at angr/dec-snapshots@master...angr/cle_800 |
THIS MESSAGE WAS GENERATED BY AN AUTOMATED PROCESS
Problem
PE.osis the string"windows"for every PE, whatever the image says aboutitself. That is wrong for UEFI modules, and downstream it is fatal: angr routes
on
os, soHighMemDxe.efi-- a RISC-V UEFI boot service driver -- reachesSimWindows, which asks for a Win32 syscall calling convention on anarchitecture that has never run Windows:
The project never gets built, so nothing about the image can be analysed. A
corpus census over a sample of 11,989 objects put this at 2 objects overall and
2 of the 32 sampled from a Debian edk2 collection of 2,219.
Root cause
cle/backends/pe/pe.pyassignedself.os = "windows"before it had even parsedthe headers. The optional header records which environment loads the image --
subsystems 10 through 13 are the EFI ones, and the Microsoft loader will not
load any of them -- and nothing read that field.
The same is true a second time for
cle/backends/te.py: a Terse Executable is aUEFI construct and exists nowhere else, and it set no
osat all.Fix
Read the subsystem.
PE.osis"uefi"when the optional header declares one ofEFI_APPLICATION,EFI_BOOT_SERVICE_DRIVER,EFI_RUNTIME_DRIVERorEFI_ROM,and
"windows"otherwise;TE.osis"uefi"unconditionally. This is not a newbranch for an awkward case -- it replaces a constant with the field that was
always there to answer the question.
Nothing else in cle reads
osfor a PE, and the assignment moved to just afterthe optional header is parsed, which is the first point at which it can be
answered.
Testing
tests/test_pe.py::test_uefi_image_is_not_windowsloads the RISC-V driver addedin angr/binaries#218 and asserts
os == "uefi"with the arch still RISCV64;test_exeabove it already assertsos == "windows"for a WindowsPE, so both directions are covered.
tests/test_te.py::test_os_is_ueficoversthe two Terse Executables. On master the first fails with
assert 'windows' == 'uefi'.python -m pytest tests: 244 passed, 9 skipped.The consumer is the angr change linked in a comment below, which registers the
UEFI environment
os == "uefi"now selects.sync: angr/binaries#218
session: sharpen