From mboxrd@z Thu Jan 1 00:00:00 1970 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 06895332604 for ; Tue, 17 Mar 2026 17:05:11 +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=1773767112; cv=none; b=fq1iAVJv5lgHbH0+JpFHxvaRqyyZdMXhVXPgd64xUtrxUGj/jcVefBFxqb9vbZermMDyWlDZApnjenfaqJy05YeDoy/cqJ/Yc3j00AxJR0jiLz8WQWFgZp/kpW1TDMON0cIhnpKjwzIBR3+rtJ3gW8JaL3D0yYXPUIvtuw1cDuE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773767112; c=relaxed/simple; bh=e4xMtnDeKyB7PvCGE3vq4Y6ib+TJDGqMPkMU2n1Z2kA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K9Na1fL3Gf3sAQgimdslcB3nZ4ua10MRXBGabZZRendlx0jHp0aEQw0dK6QQJKPx1jV/kJ1Jk5DsdPNXLE+9exIveFbk98cCe2JKT5b+sKpUcoEm6tzsFSA/fyRdndM/fc9LmVJdn0QYcHnLO4FhCvbWVJ3mls/qxuNZSrb80Lw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l2SPpp7O; 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="l2SPpp7O" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8EC0CC4CEF7; Tue, 17 Mar 2026 17:05:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773767111; bh=e4xMtnDeKyB7PvCGE3vq4Y6ib+TJDGqMPkMU2n1Z2kA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l2SPpp7OvzfPH+5LcD8mxS9aj4wqIV9SYvV2I1dzUUR56qmI/AZqaRnJWIaR6Iri/ 1bb+OgG8odsrACh8gAceW7yVOkuJAvKLtPKutDi52JO9JnwciEN1EO75VBk7bx2TGL OQLelTWgf0rkWVEo8Dq5nOExz3w8qvCzp7GgSyeKS0Q4Lddq/3eY/TcaT3oUibtUMA XtfwPpYnPaeVuPe8V8BpOJ6TcxNKqVPoIUXpF6qLel/DNtzbljFkaq7R39lLZjMtZ5 9UnBTcrMymzGqFv4iLvudjURaG3meE00d3W8uYJNiyBMeS7uTYOdAvvD8Oc53ijhu4 YMKOJh1VM1yaw== From: Sasha Levin To: stable@vger.kernel.org Cc: Alexander Potapenko , Marco Elver , Andrey Konovalov , Andrey Ryabinin , Dmitry Vyukov , Ernesto Martinez Garcia , Greg KH , Kees Cook , Andrew Morton , Sasha Levin Subject: [PATCH 5.15.y] mm/kfence: disable KFENCE upon KASAN HW tags enablement Date: Tue, 17 Mar 2026 13:05:08 -0400 Message-ID: <20260317170508.231008-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2026031757-abreast-angling-34e3@gregkh> References: <2026031757-abreast-angling-34e3@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: Alexander Potapenko [ Upstream commit 09833d99db36d74456a4d13eb29c32d56ff8f2b6 ] KFENCE does not currently support KASAN hardware tags. As a result, the two features are incompatible when enabled simultaneously. Given that MTE provides deterministic protection and KFENCE is a sampling-based debugging tool, prioritize the stronger hardware protections. Disable KFENCE initialization and free the pre-allocated pool if KASAN hardware tags are detected to ensure the system maintains the security guarantees provided by MTE. Link: https://lkml.kernel.org/r/20260213095410.1862978-1-glider@google.com Fixes: 0ce20dd84089 ("mm: add Kernel Electric-Fence infrastructure") Signed-off-by: Alexander Potapenko Suggested-by: Marco Elver Reviewed-by: Marco Elver Cc: Andrey Konovalov Cc: Andrey Ryabinin Cc: Dmitry Vyukov Cc: Ernesto Martinez Garcia Cc: Greg KH Cc: Kees Cook Cc: Signed-off-by: Andrew Morton [ replaced missing kasan_hw_tags_enabled() with equivalent IS_ENABLED/kasan_enabled() check, used kasan.h header, adapted memblock_free() to phys_addr_t API, and targeted older kfence_alloc_pool() function name ] Signed-off-by: Sasha Levin --- mm/kfence/core.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mm/kfence/core.c b/mm/kfence/core.c index e1a555eeec459..9efcf2a4e54f9 100644 --- a/mm/kfence/core.c +++ b/mm/kfence/core.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -807,6 +808,20 @@ void __init kfence_alloc_pool(void) if (!kfence_sample_interval) return; + /* + * If KASAN hardware tags are enabled, disable KFENCE, because it + * does not support MTE yet. + */ + if (IS_ENABLED(CONFIG_KASAN_HW_TAGS) && kasan_enabled()) { + pr_info("disabled as KASAN HW tags are enabled\n"); + if (__kfence_pool) { + memblock_free(__pa(__kfence_pool), KFENCE_POOL_SIZE); + __kfence_pool = NULL; + } + kfence_sample_interval = 0; + return; + } + __kfence_pool = memblock_alloc(KFENCE_POOL_SIZE, PAGE_SIZE); if (!__kfence_pool) -- 2.51.0