Re: [PATCH v2 13/14] x86: runtime_const used for KASAN_SHADOW_END

From: Andrey Konovalov
Date: Sat Feb 22 2025 - 10:10:09 EST


On Fri, Feb 21, 2025 at 4:27 PM Maciej Wieczor-Retman
<maciej.wieczor-retman@xxxxxxxxx> wrote:
>
> Also I was wondering if you know what "hwasan-mapping-offset-dynamic" option is?
> I noticed it in the llvm docs but can't find a good description what it does,
> even from looking at the code in HWAddressSanitizer.cpp. If
> hwasan-mapping-offset is not implemeneted for x86 I doubt this is but maybe it
> could help in a cleaner makefile for x86 at least? Especially once these options
> will be working in x86 llvm.

Yeah, reading the code [1] works better to understand these options.

My understanding is that specifying
-hwasan-mapping-offset-dynamic=global without -hwasan-mapping-offset
would make the generated code get the shadow memory address from the
__hwasan_shadow_memory_dynamic_address global variable. This option is
in the common code, so it should work on x86 too. But I believe it's
intended for userspace, not sure if it would work for the kernel.

Even if we use this option, I don't get how it would make the Makefile
cleaner - to me it already looks clean tbh :) But it will possibly
make KASAN work slower.

[1] https://github.com/llvm/llvm-project/blob/llvmorg-21-init/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp#L1929