Re: Having problems when trying to instrument all code of a specific UEFI driver (including the library code)


mick21@...
 

For ASan and MSan I just add the relevant flags to CC_FLAGS and sometimes I have to add custom flags. I must mention that I enabled Windows as a target for MSan, this wasn't the case for my LLVM version.

[BuildOptions]
*_*_*_CC_FLAGS = -fsanitize=memory -mllvm -msan-smm-tianocore=1 -fsanitize-blacklist=/mnt/part5/edk2-msan/msan_blacklist.txt
For ASan I had to remove link-time optimizations, due to errors related to comdat sections which I could not fix. The more difficult part for me is setting up the shadow memory and implementing enough of the sanitizer runtime in order for it to work.

Also, some functions have other dependencies which are out of the instrumentation still, for instance [1]:

InternalSmmBase2->GetSmstLocation (InternalSmmBase2, &gSmst);
ASSERT (gSmst != NULL);
This initializes the gSmst variable, with the function SmmBase2GetSmstLocation() [2] in PiSmmIpl.c, and will now cause MSan to error on the ASSERT() call. I still have to work out these cases. That said, it is still very much a work in progress and it is all a bit hacky.

Kind regards,

Mick

[1] https://github.com/tianocore/edk2/blob/83876950ab3cf5278d0ae7542086bd4be75059d3/MdePkg/Library/SmmServicesTableLib/SmmServicesTableLib.c#L52
[2] https://github.com/tianocore/edk2/blob/83876950ab3cf5278d0ae7542086bd4be75059d3/MdeModulePkg/Core/PiSmmCore/PiSmmIpl.c#L77

Join discuss@edk2.groups.io to automatically receive all group messages.