Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3757327B355 for ; Wed, 10 Sep 2025 11:53:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757505231; cv=none; b=DHpsfLOM9hM+mnwjpkTw7SX4wIcKF1UewhOiyTd0AeA17b4xKcZS55SbvLFqdMexg7IsZZt2IKyccaQIJjs51m0F1UOdAprCvwzid88G17axx6tC1rEuyPsYoddvsYxJQC+8uoY+SQA0vxexmp0RSC+IXrHCVZXXiv8ty0G0rNg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757505231; c=relaxed/simple; bh=g+19wzl/ZX2bsToIlYbUvwPyQL18mG7daoTpnDphvsM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IAhjUPRjQhVZzN7cWT7Pdf4GeLljwFDtQNIYvBqUNRPbq+My0GxrhLPH/nH2V9J78eHDtE2cxlO4CzemcNG/Qe/Y5BN6DDbE6hd9UioREEKoolja2WaYTdV3jz4Q5H373CGHAIshkFmBGxWeGVOEzJ44rmvbDp7tFg9oVmQi9Jc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hedU80tT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hedU80tT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 395CCC4CEF0; Wed, 10 Sep 2025 11:53:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757505230; bh=g+19wzl/ZX2bsToIlYbUvwPyQL18mG7daoTpnDphvsM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hedU80tTCGFNS2zCbTddHAvYJuMzSmzJv5ioJ2pEWwnOj4LfPmJN81bRNkostJl+b AlKJWFlwlrRdE2x5Rgp2neLGNANSoWtFOXI0aXS3rftdJMXDKoBVOBIsZ0VwA0wIq5 ofDlXH/EakRITwMIaNx7CttTFEPbVP0qLA1caYmsRpRoYwfi5DjdtIIxhAXyFjm40k MXkTXFHorbDynPjdertXI7DWwz5yFP679VJsb8MRNPi7HjcVeGaYVcEE6VaXrBimRD NiMOCxaaKiXwudwmJbrYqTxnsuHr0f43T9SpCNtLt/4lW6m0F6FqQwmSyUJz2T5VZR 5/u5DUahfMTEw== From: Sasha Levin To: stable@vger.kernel.org Cc: Ada Couprie Diaz , Yeoreum Yun , Alexander Potapenko , Andrey Konovalov , Andrey Ryabinin , Dmitriy Vyukov , Marco Elver , Marc Rutland , Michael Ellerman , Nathan Chancellor , Vincenzo Frascino , Andrew Morton , Sasha Levin Subject: [PATCH 6.6.y] kasan: fix GCC mem-intrinsic prefix with sw tags Date: Wed, 10 Sep 2025 07:53:46 -0400 Message-ID: <20250910115346.3588109-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2025090600-revenue-discharge-a6c4@gregkh> References: <2025090600-revenue-discharge-a6c4@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Ada Couprie Diaz [ Upstream commit 51337a9a3a404fde0f5337662ffc7699793dfeb5 ] 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. Link: https://lkml.kernel.org/r/20250821120735.156244-1-ada.coupriediaz@arm.com Link: https://gcc.gnu.org/onlinedocs/gcc-13.4.0/gcc/Optimize-Options.html [0] Signed-off-by: Ada Couprie Diaz Fixes: 36be5cba99f6 ("kasan: treat meminstrinsic as builtins in uninstrumented files") Reviewed-by: Yeoreum Yun Cc: Alexander Potapenko Cc: Andrey Konovalov Cc: Andrey Ryabinin Cc: Dmitriy Vyukov Cc: Marco Elver Cc: Marc Rutland Cc: Michael Ellerman Cc: Nathan Chancellor Cc: Vincenzo Frascino Cc: Signed-off-by: Andrew Morton [ kasan_params => CFLAGS_KASAN ] Signed-off-by: Sasha Levin --- scripts/Makefile.kasan | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan index 390658a2d5b74..a57c24c129720 100644 --- a/scripts/Makefile.kasan +++ b/scripts/Makefile.kasan @@ -68,10 +68,14 @@ CFLAGS_KASAN := -fsanitize=kernel-hwaddress \ $(call cc-param,hwasan-inline-all-checks=0) \ $(instrumentation_flags) -# Instrument memcpy/memset/memmove calls by using instrumented __hwasan_mem*(). -ifeq ($(call clang-min-version, 150000)$(call gcc-min-version, 130000),y) -CFLAGS_KASAN += $(call cc-param,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 + CFLAGS_KASAN += $(call cc-param,asan-kernel-mem-intrinsic-prefix=1) + else + CFLAGS_KASAN += $(call cc-param,hwasan-kernel-mem-intrinsic-prefix=1) + endif +endif # CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX endif # CONFIG_KASAN_SW_TAGS -- 2.51.0