google / google/security-research
Zentool disassembly shows incorrect register output.
- Dominant language
- C
- Stars
- 4.6k
- Forks
- 582
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 3
Description
https://github.com/google/security-research/blob/f102f0bad048368076affc692c6a0ceacba6eabd/pocs/cpus/entrysign/zentool/disas.c#L105
```
// Now decode the remainder as necessary.
putstr("\t%-*s\t%s, %s, ",
kMnemonicWidth,
mnemonic,
zen_reg_to_string(op.reg2),
zen_reg_to_string(op.reg1));
```
@sirdarckcat
In `dump_reg_op` if both `op.reg1` and `op.reg2` are a different`reg[0-x]` constants, i.e. `"reg2"` `"reg4"`, the printed register is wrong because `zen_reg_to_string` uses the same static char[] buffer to create a formatted return string at runtime. The function `zen_reg_to_string`, is called twice before the return value is used in the `putstr`
Suggesting a change to split it into two separate separate ``putstr(...,zen_reg_to_string(...))`` calls.
```
// Now decode the remainder as necessary.seq
putstr("\t%-*s\t%s, ",
kMnemonicWidth,
mnemonic,
zen_reg_to_string(op.reg2));
putstr("%s, ", zen_reg_to_string(op.reg1));
```
This also changes the expected output for `/test/mcop.sh` in the `mcop 382E9C1110E00000` case from
``adc reg2, reg2, reg7``
to
``adc reg2, reg4, reg7``
Contributor guide
Assessment
This issue has not been assessed yet.