qmonnet / rbpf

Rust virtual machine and JIT compiler for eBPF programs
Apache License 2.0
922 stars 235 forks source link

Attempt to negate with overflow in ld_st_imm_str of disassembler #91

Closed pcy190 closed 9 months ago

pcy190 commented 9 months ago

The disassembler would panic in ld_st_imm_str when it tries to negate the 0x8000i16 value in

https://github.com/qmonnet/rbpf/blob/4812c52fe1009ee1e3c2307662d175bdd07b5c71/src/disassembler.rs#L29-L33

The PoC program to reproduce:

disassembler::disassemble(&[98, 1, 0, 128, 0, 0, 31, 145])

The would panic the disassembler:

thread '<unnamed>' panicked at 'attempt to negate with overflow', /rbpf-0.2.0/src/disassembler.rs:33:56

To enhance the robustness of the disassembler, the negation logic of i16 could be restructured in ld_st_imm_str function.