Missing Alignment Check During AbstractIns #6812
Labels
bug
Something isn't working
compiler: codegen
Everything to do with IR->ASM, register allocation, etc.
P: high
Should be looked at if there are no critical issues left
From https://reports.immunefi.com/fuel-network-or-attackathon/attackathon-_-fuel-network-32439-smart-contract-low-missing-alignment-check-during-abstractinstructi
const_indexing_aggregates_function process VirtualOp::SW without checking the offset in addr_reg is aligned to 8, cause the wrong constant being calculated and leads to incorrect program behavior.
Vulnerability Details
const_indexing_aggregates_function is an optimization pass of AbstractInstructionSet, it is used to propagate constants in the function. During the handling of VirtualOp::SW instruction, the function does not properly validate the offset of BaseOffset. Since the imm argument of VirtualOp::SW representing an offset equals to imm * 8, the conversion (divide by 8) here will truncate offset which isn't aligned to 8 bytes, causing SW instruction to write to incorrect address.
Impact Details
As usual, it is hard to come up with a precise impact estimation of incorrect code generation because it depends on what code the user writes. The best case scenario would be contracts that run into those bugs getting bricked, and the worst case scenario would be that incorrect program behaviors lead to loss of funds.
References
sway/sway-core/src/asm_generation/fuel/optimizations.rs
Line 169 in 7b56ec7
Proof of Concept
This test would fail because buf[16] is not overwritten by sw b a i1.
The text was updated successfully, but these errors were encountered: