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

Fix various inaccuracies in the RISC-V lifter #64

Merged
merged 4 commits into from
Apr 30, 2024

Conversation

nmeum
Copy link
Contributor

@nmeum nmeum commented Apr 29, 2024

This patchset fixes several issues where the provided lifter for the RISC-V 32-bit base instruction set would not correctly capture the semantics of RISC-V instruction as mandated by the RISC-V specification. As illustrated in #62, this causes angr to miss execution paths during symbolic execution, when used with this lifter. With this patchset applied, angr finds all 625 paths in the example binary provided in #62.

Specifically, this patchset fixes the following issues:

  1. Arithmetic shift (e.g. as used in the SRA instruction) was modeled incorrectly.
  2. R-Type shift instructions used the lower bits of the register index, not the register value as a shift amount.
  3. Load instruction did not properly zero- and sign-extend the register value.
  4. The shift value for I-type instructions was incorrectly extracted as a signed value.
  5. The comparison instructions (SLT, SLTI, …) did not correctly compare signed integers.

With these patches applied, angr passes the riscv-tests for the 32-bit base instruction set (rv32i). I did not test the lifter for additional instruction set extensions (e.g. the M- or C-extension).

Fixes #62


CC: @twizmwazin

The shift value must be treated as an unsigned integer otherwise
a shift value such as '0b11111' would be interpreted as -1 instead
of 31.
For arithmetic shift instructions, use the .sra() method provided
by VexValue. For R-type shift instructions, extract the shift amount
by reading the lower 5 bits of the register (previously the shift
amount was incorrectly extracted from the register index, not the
register value).
@twizmwazin twizmwazin merged commit c9de71d into angr:master Apr 30, 2024
12 of 13 checks passed
@twizmwazin
Copy link
Member

Thank you!

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.

angr misses paths on RISC-V binary found by other symbolic execution engines
2 participants