mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yeoreum Yun <yeoreum.yun@arm.com>
To: Ada Couprie Diaz <ada.coupriediaz@arm.com>
Cc: kasan-dev@googlegroups.com, Nathan Chancellor <nathan@kernel.org>,
	Nicolas Schier <nicolas.schier@linux.dev>,
	Andrey Ryabinin <ryabinin.a.a@gmail.com>,
	Alexander Potapenko <glider@google.com>,
	Andrey Konovalov <andreyknvl@gmail.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>,
	Marco Elver <elver@google.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Michael Ellerman <mpe@ellerman.id.au>,
	linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
	Mark Rutland <mark.rutland@arm.com>
Subject: Re: [PATCH] kasan: fix GCC mem-intrinsic prefix with sw tags
Date: Thu, 21 Aug 2025 15:30:34 +0100	[thread overview]
Message-ID: <aKctip0/nVuirL4U@e129823.arm.com> (raw)
In-Reply-To: <20250821120735.156244-1-ada.coupriediaz@arm.com>

Reviewed-by: Yeoreum Yun <yeoreum.yun@arm.com>

On Thu, Aug 21, 2025 at 01:07:35PM +0100, Ada Couprie Diaz wrote:
> GCC doesn't support "hwasan-kernel-mem-intrinsic-prefix", only
> "asan-kernel-mem-intrinsic-prefix"[0], while LLVM supports both.
> This is already taken into account when checking
> "CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX", but not in the KASAN Makefile
> adding those parameters when "CONFIG_KASAN_SW_TAGS" is enabled.
>
> Replace the version check with "CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX",
> which already validates that mem-intrinsic prefix parameter can be used,
> and choose the correct name depending on compiler.
>
> GCC 13 and above trigger "CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX" which
> prevents `mem{cpy,move,set}()` being redefined in "mm/kasan/shadow.c"
> since commit 36be5cba99f6 ("kasan: treat meminstrinsic as builtins
> in uninstrumented files"), as we expect the compiler to prefix
> those calls with `__(hw)asan_` instead.
> But as the option passed to GCC has been incorrect, the compiler has
> not been emitting those prefixes, effectively never calling
> the instrumented versions of `mem{cpy,move,set}()`
> with "CONFIG_KASAN_SW_TAGS" enabled.
>
> If "CONFIG_FORTIFY_SOURCES" is enabled, this issue would be mitigated
> as it redefines `mem{cpy,move,set}()` and properly aliases the
> `__underlying_mem*()` that will be called to the instrumented versions.
>
> [0]: https://gcc.gnu.org/onlinedocs/gcc-13.4.0/gcc/Optimize-Options.html
>
> Signed-off-by: Ada Couprie Diaz <ada.coupriediaz@arm.com>
> Fixes: 36be5cba99f6 ("kasan: treat meminstrinsic as builtins in uninstrumented files")
> ---
>  scripts/Makefile.kasan | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan
> index 693dbbebebba..0ba2aac3b8dc 100644
> --- a/scripts/Makefile.kasan
> +++ b/scripts/Makefile.kasan
> @@ -86,10 +86,14 @@ kasan_params += hwasan-instrument-stack=$(stack_enable) \
>  		hwasan-use-short-granules=0 \
>  		hwasan-inline-all-checks=0
>
> -# Instrument memcpy/memset/memmove calls by using instrumented __hwasan_mem*().
> -ifeq ($(call clang-min-version, 150000)$(call gcc-min-version, 130000),y)
> -	kasan_params += hwasan-kernel-mem-intrinsic-prefix=1
> -endif
> +# Instrument memcpy/memset/memmove calls by using instrumented __(hw)asan_mem*().
> +ifdef CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX
> +	ifdef CONFIG_CC_IS_GCC
> +		kasan_params += asan-kernel-mem-intrinsic-prefix=1
> +	else
> +		kasan_params += hwasan-kernel-mem-intrinsic-prefix=1
> +	endif
> +endif # CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX
>
>  endif # CONFIG_KASAN_SW_TAGS
>
>
> base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
> --
> 2.43.0
>

--
Sincerely,
Yeoreum Yun

      reply	other threads:[~2025-08-21 14:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-21 12:07 Ada Couprie Diaz
2025-08-21 14:30 ` Yeoreum Yun [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aKctip0/nVuirL4U@e129823.arm.com \
    --to=yeoreum.yun@arm.com \
    --cc=ada.coupriediaz@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@gmail.com \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=glider@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mpe@ellerman.id.au \
    --cc=nathan@kernel.org \
    --cc=nicolas.schier@linux.dev \
    --cc=ryabinin.a.a@gmail.com \
    --cc=vincenzo.frascino@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®