From: "Chuck Lever" <cel@kernel.org>
To: "Jeff Layton" <jlayton@kernel.org>,
"Chuck Lever" <chuck.lever@oracle.com>,
NeilBrown <neil@brown.name>,
"Olga Kornievskaia" <okorniev@redhat.com>,
"Dai Ngo" <Dai.Ngo@oracle.com>, "Tom Talpey" <tom@talpey.com>,
"Mike Snitzer" <snitzer@kernel.org>
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] nfsd: don't free session slots that are still in use
Date: Tue, 26 May 2026 10:58:31 -0400 [thread overview]
Message-ID: <f0c2c3ce-cb3b-4156-a2ad-6730e34c403f@app.fastmail.com> (raw)
In-Reply-To: <20260526-nfsd4_sequence_shrink_uaf_on_loaded_slot-v1-1-504a6a7fd9b4@kernel.org>
On Tue, May 26, 2026, at 10:22 AM, Jeff Layton wrote:
> nfsd4_sequence() can free the very slot it is currently processing.
> When the session shrinker has reduced se_target_maxslots below
> se_fchannel.maxreqs, the shrink path checks three conditions before
> calling free_session_slots():
>
> 1. se_target_maxslots < maxreqs (shrink was advertised)
> 2. slot->sl_generation == se_slot_gen (slot is up-to-date)
> 3. seq->maxslots <= se_target_maxslots (client acknowledges)
>
> However, seq->slotid is never checked against se_target_maxslots.
> A client using a slot in the range [se_target_maxslots, maxreqs) can
> satisfy all three conditions: its slot has the current generation
> (set by a prior SEQUENCE), and it sends sa_highest_slotid <=
> se_target_maxslots to acknowledge the reduction.
>
> free_session_slots() then kfrees every slot at index >=
> se_target_maxslots, including the caller's own slot. The function
> continues to write sl_seqid, sl_flags, sl_generation, and stores the
> dangling pointer in cstate->slot. Later, nfsd4_store_cache_entry()
> copies up to maxresp_cached bytes of the compound reply into the freed
> sl_data[] array, corrupting whatever slab object now occupies that
> address.
>
> This is a remotely triggerable heap use-after-free from any
> authenticated NFSv4.1+ client with an established session, requiring
> only that the kernel memory shrinker has run against nfsd session slots
> (a normal occurrence under memory pressure).
>
> Fix this by adding a check that the current request's slotid is below
> the shrink boundary before allowing the slot reduction to proceed.
>
> Fixes: 8fb77d12c76e ("nfsd: add support for freeing unused session-DRC slots")
> Signed-off-by: Jeff Layton <jlayton@kernel.org>
> ---
> fs/nfsd/nfs4state.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
> index d5cbf626ab9b..f90ad8281a95 100644
> --- a/fs/nfsd/nfs4state.c
> +++ b/fs/nfsd/nfs4state.c
> @@ -4848,7 +4848,8 @@ nfsd4_sequence(struct svc_rqst *rqstp, struct
> nfsd4_compound_state *cstate,
>
> if (session->se_target_maxslots < session->se_fchannel.maxreqs &&
> slot->sl_generation == session->se_slot_gen &&
> - seq->maxslots <= session->se_target_maxslots)
> + seq->maxslots <= session->se_target_maxslots &&
> + seq->slotid < session->se_target_maxslots)
> /* Client acknowledged our reduce maxreqs */
> free_session_slots(session, session->se_target_maxslots);
>
The patch guards only against the caller freeing its own slot. It
doesn't guard against freeing a different slot that is concurrently
in use by another thread. Perhaps free_session_slots() should skip
any slot with NFSD4_SLOT_INUSE set. Or the shrink could be deferred
until no high-numbered slots are in use?
--
Chuck Lever
prev parent reply other threads:[~2026-05-26 14:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-26 14:22 Jeff Layton
2026-05-26 14:58 ` Chuck Lever [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=f0c2c3ce-cb3b-4156-a2ad-6730e34c403f@app.fastmail.com \
--to=cel@kernel.org \
--cc=Dai.Ngo@oracle.com \
--cc=chuck.lever@oracle.com \
--cc=jlayton@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=neil@brown.name \
--cc=okorniev@redhat.com \
--cc=snitzer@kernel.org \
--cc=tom@talpey.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®