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 289903E6DD0 for ; Tue, 17 Mar 2026 14:30:37 +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=1773757838; cv=none; b=sZIAwpPQpaH4dd+2hRoQnU8Wq+hj87ZBvxt83rRkmU3f2EC7N7O3iEarpL8yVeaPlZLYhZHi9CnqKHbnNh5hSySIButu9rBbaJvbaWaPls9UCw7t87xtIgRN5OdS2mskjBetuK8+U4gWFtS/evckDT5SYoOdkz/wtTjgWFt63AY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773757838; c=relaxed/simple; bh=LnI8PfR9hx7iYyc1eiPLF5G9O82q0DQ2IyDTWaOi77w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hCol0vmoZ6kvQhJiLMYY15TykcFC5wviRProw8+Caweeal1VHHHwpMzKuf0Dfv56+Q6d/nW/OkNLprLYiSV2EXZhC9P/1szicEzntLR8cU3atokH6lRK/VEVFBISStntR701uNdIwZT5ZMaDgDw4jqiWdmuZm0uAmFzdmkvdXG4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Mc0nRj9p; 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="Mc0nRj9p" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A87BEC4CEF7; Tue, 17 Mar 2026 14:30:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773757837; bh=LnI8PfR9hx7iYyc1eiPLF5G9O82q0DQ2IyDTWaOi77w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mc0nRj9p+J7gME/fFF+lz2h4xZRvgGFGQpf364/LfDjBLieXRRxE2wSwYJfpuOaAa sXRbptNS8qqvHuHNbdkduo55I1T1pFAx94Ibt87gFYgNwUOBL2a9CnemMuzILstmmq a1AiGMApkzr4MkT2meL+LL2TC68eu4hx/W5aadv/ukZ83fwNaXQ9M6h1CBqzEQtRmy htcx8HRB8FQg7j9jBiy60xy4Xbkr8UZ2T2xVzkhUyoqE41C0KCiURwZWZAFyFt89pn cGx991uSt8kxFl/jwDICHgllfBX4AHNRyiHENY3fxLxKET6BPgyzhMGB4mEl/hhDsq EAwFyyXSSt3Gg== From: Sasha Levin To: stable@vger.kernel.org Cc: Alexander Potapenko , Ernesto Martinez Garcia , Andrey Konovalov , Andrey Ryabinin , Dmitry Vyukov , Greg KH , Kees Cook , Marco Elver , Andrew Morton , Sasha Levin Subject: [PATCH 6.6.y] mm/kfence: fix KASAN hardware tag faults during late enablement Date: Tue, 17 Mar 2026 10:30:32 -0400 Message-ID: <20260317143032.168309-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2026031725-satisfied-thrower-61b1@gregkh> References: <2026031725-satisfied-thrower-61b1@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 d155aab90fffa00f93cea1f107aef0a3d548b2ff ] When KASAN hardware tags are enabled, re-enabling KFENCE late (via /sys/module/kfence/parameters/sample_interval) causes KASAN faults. This happens because the KFENCE pool and metadata are allocated via the page allocator, which tags the memory, while KFENCE continues to access it using untagged pointers during initialization. Use __GFP_SKIP_KASAN for late KFENCE pool and metadata allocations to ensure the memory remains untagged, consistent with early allocations from memblock. To support this, add __GFP_SKIP_KASAN to the allowlist in __alloc_contig_verify_gfp_mask(). Link: https://lkml.kernel.org/r/20260220144940.2779209-1-glider@google.com Fixes: 0ce20dd84089 ("mm: add Kernel Electric-Fence infrastructure") Signed-off-by: Alexander Potapenko Suggested-by: Ernesto Martinez Garcia Cc: Andrey Konovalov Cc: Andrey Ryabinin Cc: Dmitry Vyukov Cc: Greg KH Cc: Kees Cook Cc: Marco Elver Cc: Signed-off-by: Andrew Morton [ dropped page_alloc.c hunk adding __GFP_SKIP_KASAN ] Signed-off-by: Sasha Levin --- mm/kfence/core.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mm/kfence/core.c b/mm/kfence/core.c index 16a6ecca95fce..837b3942c609a 100644 --- a/mm/kfence/core.c +++ b/mm/kfence/core.c @@ -930,14 +930,14 @@ static int kfence_init_late(void) #ifdef CONFIG_CONTIG_ALLOC struct page *pages; - pages = alloc_contig_pages(nr_pages_pool, GFP_KERNEL, first_online_node, - NULL); + pages = alloc_contig_pages(nr_pages_pool, GFP_KERNEL | __GFP_SKIP_KASAN, + first_online_node, NULL); if (!pages) return -ENOMEM; __kfence_pool = page_to_virt(pages); - pages = alloc_contig_pages(nr_pages_meta, GFP_KERNEL, first_online_node, - NULL); + pages = alloc_contig_pages(nr_pages_meta, GFP_KERNEL | __GFP_SKIP_KASAN, + first_online_node, NULL); if (pages) kfence_metadata_init = page_to_virt(pages); #else @@ -947,11 +947,13 @@ static int kfence_init_late(void) return -EINVAL; } - __kfence_pool = alloc_pages_exact(KFENCE_POOL_SIZE, GFP_KERNEL); + __kfence_pool = alloc_pages_exact(KFENCE_POOL_SIZE, + GFP_KERNEL | __GFP_SKIP_KASAN); if (!__kfence_pool) return -ENOMEM; - kfence_metadata_init = alloc_pages_exact(KFENCE_METADATA_SIZE, GFP_KERNEL); + kfence_metadata_init = alloc_pages_exact(KFENCE_METADATA_SIZE, + GFP_KERNEL | __GFP_SKIP_KASAN); #endif if (!kfence_metadata_init) -- 2.51.0