All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tien Phan <tienpp@gmail.com>
To: security@kernel.org
Cc: Greg KH <greg@kroah.com>, Chuck Lever <chuck.lever@oracle.com>,
	NeilBrown <neil@brown.name>, Jeff Layton <jlayton@kernel.org>,
	stable@vger.kernel.org, Tien Phan <tienpp@gmail.com>
Subject: [PATCH v3] nfsd: fix use-after-free of DRC slot in nfsd4_sequence()
Date: Wed, 19 Aug 2026 16:47:01 +0900	[thread overview]
Message-ID: <20260819074701.1312702-1-tienpp@gmail.com> (raw)
In-Reply-To: <20260819054326.1265334-1-tienpp@gmail.com>

nfsd4_sequence() loads the slot for the client-supplied seq->slotid
(bounded only by se_fchannel.maxreqs), then on the reduce-ack path frees
every slot in [se_target_maxslots, maxreqs) with free_session_slots()
without checking that the loaded slot is outside that range.

Once the DRC shrinker has lowered se_target_maxslots below maxreqs, a
client using seq->slotid >= se_target_maxslots has its own slot freed and
then dereferenced and written (slot->sl_seqid, cstate->slot): a
use-after-free.

Reject such a slotid before freeing the slots.

Fixes: fc8738c68d0b ("nfsd: add support for freeing unused session-DRC slots")
Cc: stable@vger.kernel.org # 6.14+
Reported-by: Sentinel (automated analysis agent)
Assisted-by: Claude (Anthropic)
Signed-off-by: Tien Phan <tienpp@gmail.com>
---
v3: trim commit message; drop the added in-code comment (Greg KH).
v2: add Reported-by:/Assisted-by: trailers (Greg KH); fix NeilBrown address.
v1: https://lore.kernel.org/all/20260819054326.1265334-1-tienpp@gmail.com/
 fs/nfsd/nfs4state.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index a42f34842d77..def1ea534e18 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -4575,9 +4575,14 @@ 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) {
+			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


  parent reply	other threads:[~2026-08-19  7:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-19  5:43 [PATCH] nfsd: fix use-after-free of DRC slot in nfsd4_sequence() Tien Phan
2026-08-19  5:52 ` 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 ` Tien Phan [this message]
2026-08-19 11:23   ` [PATCH v3] " 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=20260819074701.1312702-1-tienpp@gmail.com \
    --to=tienpp@gmail.com \
    --cc=chuck.lever@oracle.com \
    --cc=greg@kroah.com \
    --cc=jlayton@kernel.org \
    --cc=neil@brown.name \
    --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 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.