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

From: Maciej Wieczor-Retman
Date: Mon Mar 24 2025 - 06:51:24 EST


On 2025-03-24 at 11:43:27 +0100, Maciej Wieczor-Retman wrote:
>On 2025-03-21 at 21:16:12 +0100, Andrey Konovalov wrote:
>>On Fri, Mar 21, 2025 at 8:21 PM Maciej Wieczor-Retman
>><maciej.wieczor-retman@xxxxxxxxx> wrote:
>>>
>>> >To account for this, let's then set hwasan-instrument-with-calls=0
>>> >when CONFIG_KASAN_INLINE is enabled. And also please add a comment
>>> >explaining why this is done.
>>>
>>> After adding this option the kernel doesn't want to boot past uncompressing :b
>>>
>>> I went into Samuel's clang PR [1] and found there might be one more LShr that
>>> needs changing into AShr [2]? But I'm not very good at clang code. Do you maybe
>>> know if anything else in the clang code could be messing things up?
>>>
>>> After changing that LShr to AShr it moves a little further and hangs on some
>>> initmem setup code. Then I thought my KASAN_SHADOW_OFFSET is an issue so I
>>> changed to 4-level paging and the offset to 0xfffffc0000000000 and it moves a
>>> little further and panics on kmem_cache_init. I'll be debugging that further but
>>> just thought I'd ask if you know about something missing from the compiler side?
>>>
>>> [1] https://github.com/llvm/llvm-project/pull/103727
>>> [2] https://github.com/SiFiveHolland/llvm-project/blob/up/hwasan-opt/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp#L995
>>
>>Hm, I only recall looking at the compiler code when investigating [1].
>>But as this series points out, [1] can be considered a feature and not
>>a bug. Other than that, nothing comes to mind.
>>
>>Thanks!
>>
>>[1] https://bugzilla.kernel.org/show_bug.cgi?id=218043
>
>So I assume that if outline mode works, inline mode should be fine as far as
>kernel is concerned? If so perhaps it will be more time efficient to post v3 of
>this series (once I'm done with kasan_non_canonical_hook() edge cases and
>unpoisoning per-cpu vms[areas] with the same tag) and work on the clang side
>later / in the meantime.

Oh, I guess I also need to add a patch to handle the int3 (X86_TRAP_BP) so
kasan reports show up in inline mode.

--
Kind regards
Maciej Wieczór-Retman