-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
The CheckShadow implementation in https://github.com/ErichStyger/mcuoneclipse/blob/e657b75382ec3a61b63832670be26ecb29c85534/Examples/MCUXpresso/tinyK22/tinyK22_FreeRTOS_ASAN/source/McuASAN.c
is wrong.
You should be checking the shadow bit for the first byte of an access and the last byte separately with something like
CheckShadow(addr,AccessSize)
{
shadow_value=shadow[((size_t)addr-mem_start) >>3]
if ((shadow_value>> (addr&7))&1)
{
ReportError;
return;
}
addr+=AccessSize-1
shadow_value=shadow[((size_t)addr-mem_start) >>3]
if ((shadow_value>> (addr&7))&1)
{
ReportError;
return;
}
}
You should also add a no_sanitize attribute to these functions, but that's a separate issue.
Technically you need to actually check every byte's shadow bit for large access sizes, but since you have padding around it checking the first and the last will be enough for small-ish accesses I think.
Also: The asan_free implementation doesn't respect the C standard, free(NULL) isn't a nop for this function, but it should be.
Several of your for loops use an int as an iterator, which is illegal for large allocations
Use size_t.