考虑以下代码:
volatile int status;
status = process_package_header(&pack_header, PACK_INFO_CONST);
if ((((status) == (SUCCESS_CONST)) ? ((random_delay() && ((SUCCESS_CONST) == (status))) ? 0 : side_channel_sttack_detected()) : 1))
{
...
}
生成此机器代码(使用工具链的objdump生成):
60: f7ff fffe bl 0 <process_package_header>
64: 9000 str r0, [sp, #0] /* <- storing to memory as status is volatile */
66: 42a0 cmp r0, r4 /* <- where is the load before compare? status is volatile, it could have change between the last store instruction (above line) and now */
68: d164 bne.n 134 <func+0x134>
6a: f7ff fffe bl 0 <random_delay>
现在,由于它是易失的,当到达语句status
时它应该已经从内存中读取。if
我希望在将其 ( cmp
) 与进行比较之前看到一些加载命令SUCCESS_CONST
,不管它被分配了函数的返回值process_package_header()
并存储在内存中,因为status
它是易失性的,并且可能在str
指令和cmp
指令之间进行更改。
请尝试忽略if
条件的动机,其目的是尝试检测对 CPU 的物理攻击,其中条件标志和寄存器可以通过物理设备从外部更改。
工具链ARM DS-5_v5.27.0 arm 编译器:ARMCompiler5.06u5 (armcc)
目标是 ARM CortexM0+ CPU