On Mon, Oct 19, 2026 at 09:59:01AM +0800, Qiliang Yuan wrote:
> sized_strscpy() copies a word at a time. The loads go through
> read_word_at_a_time(), which checks the first byte of each word with
> KASAN, or through load_unaligned_zeropad() on architectures with
> CONFIG_DCACHE_WORD_ACCESS. Under KMSAN it copies byte by byte instead.
> 
> load_unaligned_zeropad() is inline assembly that the compiler does not
> instrument. Since sized_strscpy() switched to it, generic and software
> tag-based KASAN no longer report strscpy() reading from a freed or
> out-of-bounds source on x86_64, arm64 and the other architectures that
> select CONFIG_DCACHE_WORD_ACCESS. On x86_64 the kasan_strings KUnit
> case, which expects a report when the first source byte is out of
> bounds, fails as a result:
> 
>   KASAN and string KUnit suites      failures
>   on x86_64, generic KASAN        before    after
>   CONFIG_FORTIFY_SOURCE=n              1        0
>   CONFIG_FORTIFY_SOURCE=y              1        0
> 
> Copy byte by byte under generic and software tag-based KASAN too, as
> under KMSAN, so that every byte strscpy() reads is checked. Hardware
> tag-based KASAN keeps the word loop that load_unaligned_zeropad() was
> brought in for.

...

> -     if (IS_ENABLED(CONFIG_KMSAN))
> +     if (IS_ENABLED(CONFIG_KMSAN) || IS_ENABLED(CONFIG_KASAN_GENERIC) ||
> +         IS_ENABLED(CONFIG_KASAN_SW_TAGS))
>               max = 0;

Logically better to have them grouped by SANitizer:

        if (IS_ENABLED(CONFIG_KASAN_GENERIC) || 
IS_ENABLED(CONFIG_KASAN_SW_TAGS) ||
            IS_ENABLED(CONFIG_KMSAN)) 

-- 
With Best Regards,
Andy Shevchenko



Reply via email to