From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Marco Elver <elver@google.com>
Cc: Alexander Potapenko <glider@google.com>,
Dmitry Vyukov <dvyukov@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
kasan-dev@googlegroups.com, linux-mm@kvack.org,
Chris Mason <mason@kernel.org>
Subject: Re: [PATCH] kfence: use a nofault store to zero the guard page
Date: Fri, 27 Nov 2026 19:53:49 +0100 [thread overview]
Message-ID: <59221fee-1318-4014-bdbb-50cdec0d7283@kernel.org> (raw)
In-Reply-To: <CANpmjNNTOc0h3yG8n3CHLsmqNH-+Y454=9cATn6rM0dXA-nYFw@mail.gmail.com>
On 11/27/26 15:44, Marco Elver wrote:
> On Fri, 27 Nov 2026 at 11:04, David Hildenbrand (Arm) <david@kernel.org> wrote:
>>
>> From: Chris Mason <mason@kernel.org>
>>
>> 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.
>>
>> This is a quick fix: nothing serializes the protection of a guard page
>> against the fault handler, so after a racing free the page can stay
>> unprotected and we will not report later out-of-bounds accesses to it.
>> Add a TODO as a reminder to sort that out properly.
>
> If an OOB occurred, the kernel is already in a bad state, and any
> recovery attempts are best-effort, so this fix here is "good enough"
> for this intent. You could drop the TODO and just leave the comment.
Ack, makes sense in that case. I'll send a v2 with the TODO removed.
Thanks!
--
Cheers,
David
prev parent reply other threads:[~2026-11-27 18:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 10:04 [PATCH] kfence: use a nofault store to zero the guard page David Hildenbrand (Arm)
2026-11-27 14:44 ` Marco Elver
2026-11-27 18:53 ` David Hildenbrand (Arm) [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=59221fee-1318-4014-bdbb-50cdec0d7283@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-mm@kvack.org \
--cc=mason@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.