From: Tien Phan <tienpp@gmail.com>
To: security@kernel.org
Cc: Chuck Lever <chuck.lever@oracle.com>, NeilBrown <neilb@suse.de>,
Jeff Layton <jlayton@kernel.org>, Tien Phan <tienpp@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH] nfsd: fix use-after-free of DRC slot in nfsd4_sequence()
Date: Wed, 19 Aug 2026 14:43:26 +0900 [thread overview]
Message-ID: <20260819054326.1265334-1-tienpp@gmail.com> (raw)
nfsd4_sequence() loads the slot addressed by the client-supplied
seq->slotid, bounded only against se_fchannel.maxreqs:
if (seq->slotid >= session->se_fchannel.maxreqs)
goto out_put_session;
slot = xa_load(&session->se_slots, seq->slotid);
When the client acknowledges a slot-count reduction, the handler frees
every slot in [se_target_maxslots, maxreqs):
if (session->se_target_maxslots < session->se_fchannel.maxreqs &&
slot->sl_generation == session->se_slot_gen &&
seq->maxslots <= session->se_target_maxslots)
free_session_slots(session, session->se_target_maxslots);
but never checks that the slot it just loaded lies outside that range.
A malicious NFSv4.1 client can pick seq->slotid >= se_target_maxslots
(still < maxreqs, so the bound above passes) and, once the DRC slot
shrinker has lowered se_target_maxslots below maxreqs, issue two SEQUENCE
calls on that high slot: the first aligns slot->sl_generation with
se_slot_gen, the second satisfies the reduce-ack condition and calls
free_session_slots(), which kfree()s the very slot still referenced by
the handler. The slot is then written (slot->sl_seqid = seq->seqid,
slot->sl_flags, cstate->slot = slot) and used for DRC caching -- a
use-after-free write.
Reject a slotid that falls within the range about to be freed before
freeing it, so the handler never operates on a freed slot.
Found with an in-tree KASAN harness driving the real free_session_slots()
on a live slot xarray (KASAN: slab-use-after-free, write of size 4).
Fixes: fc8738c68d0b ("nfsd: add support for freeing unused session-DRC slots")
Cc: stable@vger.kernel.org # 6.14+
Signed-off-by: Tien Phan <tienpp@gmail.com>
---
fs/nfsd/nfs4state.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index a42f34842d77..f737b841b5a2 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -4575,9 +4575,19 @@ 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) {
/* Client acknowledged our reduce maxreqs */
+ if (seq->slotid >= session->se_target_maxslots) {
+ /*
+ * ... but is using a slot from the range we are
+ * about to free. Proceeding would leave the code
+ * below dereferencing a freed slot (use-after-free).
+ */
+ status = nfserr_badslot;
+ goto out_put_session;
+ }
free_session_slots(session, session->se_target_maxslots);
+ }
buflen = (seq->cachethis) ?
session->se_fchannel.maxresp_cached :
--
2.34.1
next reply other threads:[~2026-08-19 5:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-19 5:43 Tien Phan [this message]
2026-08-19 5:52 ` [PATCH] nfsd: fix use-after-free of DRC slot in nfsd4_sequence() Greg KH
[not found] ` <CALjHmwND53Gdy0xMaPNMtvBP5=9KQ7M9-E2S+W1wweQw30tEmw@mail.gmail.com>
2026-08-19 7:29 ` Greg KH
2026-08-19 11:00 ` Jeff Layton
2026-08-19 7:21 ` [PATCH v2] " Tien Phan
2026-08-19 7:47 ` [PATCH v3] " Tien Phan
2026-08-19 11:23 ` Jeff Layton
2026-08-23 9:26 ` Ingo Molnar
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=20260819054326.1265334-1-tienpp@gmail.com \
--to=tienpp@gmail.com \
--cc=chuck.lever@oracle.com \
--cc=jlayton@kernel.org \
--cc=neilb@suse.de \
--cc=security@kernel.org \
--cc=stable@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox