From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795987334; b=jnO4lJ6FGpt2YnZvMOG8hgpq6btcHZRufKyV+5hXe03A5pAZQxj3sCwz3+Iw8DAyTeCe JHAPHf6SlWNx7Idisebq1YICWceRrsQp2OYQKaoiEn3K7lCj4OirpYPLIZVeP7ZKuAgGb ZaMuztY99gX8G98/LWzMUfPA9BunRE2pdW4Nubsc1FVq/gAGKgKHwJCOcOz7ptcQ7jniU zhvxabylMQVe8i1NLIHHXiluqAMGmv6ZfKpKF+eVsrKepm/1UNXZPCCo7Sgc87lPgzyVZ YOWwpskuCK43FC2XC5Ucvjw7iWSO883cpZmM/Hl1Ed27zIw8bi1RZsnh0dphegVcqyw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795987334; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=yNnUqFpKkUCBJxrxFA0T1GpopitOmvLZyGb7TBa3BKQ=; b=R47r2XvkaIRLI9v7fGwsnMFhn+RwtAhWSsT3e5jUigSt1NGgm+2UnFqMm/p/G692qArL Bx2gNnNTiVxGbxN2tfXKHc78K9aUC4h/Bito/vNradUm0dPfVSWUYs74hWAH9XmpZG9pO 14R8Ie3w7LZ6q5QANz828gOTY25UNrIAFvrva4Aobgqf/r89M35CNkTcGc7J3lMbdJQFT HJ4/+ZMAbpB+A6UpTpkHeKRUotMefiHOBSYTLn2ZQzSxO/wAXBdhRCpKud9pNGEaRaWQp 5MpXTUVs/tI0Em9Q8EQt/QN8Usz0y98AvqBJnvVsscG6qhQGfidX5SwjcakJq6UR9Mw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=MPDkfa8b; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A7D5606A325 for ; Sun, 29 Nov 2026 21:22:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=MPDkfa8b Received: by smtp.kernel.org (Postfix) with ESMTPSA id 740B21F00925; Sun, 29 Nov 2026 21:22:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1795987333; bh=yNnUqFpKkUCBJxrxFA0T1GpopitOmvLZyGb7TBa3BKQ=; h=Date:To:From:In-Reply-To:References:Subject; b=MPDkfa8bhNvjnIefbCdprdmYc+4EpWR34oVrDQ5sSCzSHJXjTSu40J2OZGyGpsmxc cGyE5LHb207UThIE6Uo2mYQNpu0BOKWZ7b+LE+aPVih7HZawC+G/yLbGERNNLDXkXH moPdI1usd8yNu6Oi7J3Av4QzvA7HT0wdLjUaxwk8= Date: Sun, 29 Nov 2026 13:22:12 -0800 To: mm-commits@vger.kernel.org,glider@google.com,elver@google.com, dvyukov@google.com,david@kernel.org,mason@kernel.org, akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261129-kfence_guard_zero-v2-1-d99b004b1671@kernel.org> References: <20261129-kfence_guard_zero-v2-1-d99b004b1671@kernel.org> Subject: + kfence-use-a-nofault-store-to-zero-the-guard-page.patch added to mm-new branch Message-Id: <20261129212213.740B21F00925@smtp.kernel.org> X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: kfence: use a nofault store to zero the guard page has been added to the -mm mm-new branch. Its filename is kfence-use-a-nofault-store-to-zero-the-guard-page.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/kfence-use-a-nofault-store-to-zero-the-guard-page.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Chris Mason Subject: kfence: use a nofault store to zero the guard page Date: Sun, 29 Nov 2026 11:35:42 +0100 After an out-of-bounds report, freeing the reported object can deadlock on its own meta->lock with interrupts disabled, or trigger a false out-of-bounds report on a neighbouring object. With kfence.fault=oops, this can happen more reliably, without races. kfence_guarded_free() zeroes the guard page that meta->unprotected_page points at while holding meta->lock, assuming that the page is unprotected. However, the page might still be protected: - kfence_handle_page_fault() calls kfence_unprotect() only after dropping the lock, so a concurrent free is possible. - With kfence.fault=oops, kfence_handle_fault() calls BUG(), so we never get to kfence_unprotect(). - If both neighbours of a guard page recorded it, freeing the first one protects it again. The store then faults, and kfence_handle_page_fault() either tries to take the meta->lock we are holding, or reports a bogus out-of-bounds access on the other neighbour. Let's fix it by zeroing the page with copy_to_kernel_nofault(), so that a store to a protected page simply fails. All architectures that support KFENCE try exception fixups before they call kfence_handle_page_fault(). Skipping the zeroing is fine: either the other neighbour zeroed the page before protecting it, or it was never unprotected. [david@kernel.org: adjust comment and description] Link: https://patch.msgid.link/20261129-kfence_guard_zero-v2-1-d99b004b1671@kernel.org Fixes: 94868a1e127b ("kfence: zero guard page after out-of-bounds access") Fixes: da735962d05c ("kfence: add kfence.fault parameter") Signed-off-by: Chris Mason Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Andrew Morton Acked-by: Marco Elver Cc: Alexander Potapenko Cc: Dmitry Vyukov mm/kfence/core.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/mm/kfence/core.c~kfence-use-a-nofault-store-to-zero-the-guard-page +++ a/mm/kfence/core.c @@ -33,6 +33,7 @@ #include #include #include +#include #include @@ -553,7 +554,13 @@ static void kfence_guarded_free(void *ad /* Restore page protection if there was an OOB access. */ if (meta->unprotected_page) { - memzero_explicit((void *)ALIGN_DOWN(meta->unprotected_page, PAGE_SIZE), PAGE_SIZE); + /* + * The fault handler may not have unprotected the page, or + * freeing a neighbouring object may have re-protected it. Don't + * fault, otherwise we can deadlock on meta->lock. + */ + copy_to_kernel_nofault((void *)ALIGN_DOWN(meta->unprotected_page, PAGE_SIZE), + page_address(ZERO_PAGE(0)), PAGE_SIZE); kfence_protect(meta->unprotected_page); meta->unprotected_page = 0; } _ Patches currently in -mm which might be from mason@kernel.org are mm-swap-fix-large-swap-in-across-swap-file-extents.patch hugetlbfs-do-not-grow-a-sealed-file-in-mmap.patch mm-hugetlb-keep-surplus-folios-that-are-reserved.patch mm-hugetlb-fix-reservation-leak-on-min_size=-mounts.patch mm-cachestat-count-each-page-only-once.patch mm-cachestat-restart-the-walk-after-each-entry.patch percpu-queue-the-balance-work-on-an-unbound-workqueue.patch mm-vma-fix-uncharge-after-failed-stack-relocation.patch mm-mremap-apply-the-mmap-offset-limits-on-expansion.patch mm-mremap-respect-guard-gaps-on-in-place-expansion.patch mm-vma-make-brk-mappings-non-executable-under-mdwe.patch mm-hmm-refuse-secretmem-vmas-in-hmm_range_fault.patch mm-mglru-count-all-generations-as-evictable.patch mm-mglru-test-pg_lru-before-taking-a-folio-reference.patch mm-mglru-report-root-reclaim-to-memorypressure_level.patch kfence-use-a-nofault-store-to-zero-the-guard-page.patch