This is an archive of the discontinued LLVM Phabricator instance.

[AddressSanitizer] Allow prefixing meminstrinsic calls in kernel mode
ClosedPublic

Authored by melver on Mar 30 2022, 5:06 AM.

Details

Summary

Allow receiving memcpy/memset/memmove instrumentation by using asan or
hwasan prefixed versions for AddressSanitizer and HWAddressSanitizer
respectively when compiling in kernel mode, by passing params
-asan-kernel-mem-intrinsic-prefix or -hwasan-kernel-mem-intrinsic-prefix.

By default the kernel-specialized versions of both passes drop the
prefixes for calls generated by memintrinsics. This assumes that all
locations that can lower the intrinsics to libcalls can safely be
instrumented. This unfortunately is not the case when implicit calls to
memintrinsics are inserted by the compiler in no_sanitize functions [1].

To solve the issue, normal memcpy/memset/memmove need to be
uninstrumented, and instrumented code should instead use the prefixed
versions. This also aligns with ASan behaviour in user space.

[1] https://lore.kernel.org/lkml/Yj2yYFloadFobRPx@lakrids/

Diff Detail

Event Timeline

melver created this revision.Mar 30 2022, 5:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 30 2022, 5:06 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
melver requested review of this revision.Mar 30 2022, 5:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 30 2022, 5:06 AM

LGTM. Thanks for taking care of this!

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
2737

There's a lot of common code between ASan and HWASan these days. Sigh.

glider accepted this revision.Mar 30 2022, 7:32 AM
This revision is now accepted and ready to land.Mar 30 2022, 7:32 AM
This revision was landed with ongoing or failed builds.Mar 31 2022, 2:22 AM
This revision was automatically updated to reflect the committed changes.