mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joseph Qi <joseph.qi@linux.alibaba.com>
To: Sasha Levin <sashal@kernel.org>, Chuck Lever <cel@kernel.org>,
	Jeff Layton <jlayton@kernel.org>
Cc: stable@vger.kernel.org, linux-nfs@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Joseph Qi <joseph.qi@linux.alibaba.com>
Subject: [PATCH 6.6.y] nfsd: fix NULL dereference in nfsd4_free_layout_stateid()
Date: Mon,  9 Nov 2026 16:49:32 +0800	[thread overview]
Message-ID: <20261109084932.3861080-1-joseph.qi@linux.alibaba.com> (raw)

Commit d12af460df27 ("nfsd: fix BUG_ON in nfsd4_alloc_layout_stateid on
racing delegation revoke") replaced BUG_ON(!ls->ls_file) with a bail-out
that calls nfs4_put_stid() on the partially initialized layout stateid.

nfs4_alloc_stid() leaves sc_count at 1 and nothing takes another
reference before that bail-out, so the put runs sc_free, which is
nfsd4_free_layout_stateid().  That function uses ls->ls_file
unconditionally, both for vfs_setlease() and for nfsd_file_put(), and
nfsd_file_put() does not accept NULL either.  The new error path thus
turns the race it was meant to handle gracefully into a NULL pointer
dereference.  The nfsd4_layout_setlease() failure path that already
called nfs4_put_stid() was safe only because the BUG_ON guaranteed
ls_file was non-NULL.

Upstream does not have this problem because its destructor goes through
nfsd4_close_layout(), which tests the pointer before using it.  That
helper came in with the admin-revoke series, which is not in 6.6, so
just add the NULL test here.

Fixes: d12af460df27 ("nfsd: fix BUG_ON in nfsd4_alloc_layout_stateid on racing delegation revoke")
Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com>
---
 fs/nfsd/nfs4layouts.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/fs/nfsd/nfs4layouts.c b/fs/nfsd/nfs4layouts.c
index bea7513a0de90..7c3f0948a610c 100644
--- a/fs/nfsd/nfs4layouts.c
+++ b/fs/nfsd/nfs4layouts.c
@@ -168,9 +168,13 @@ nfsd4_free_layout_stateid(struct nfs4_stid *stid)
 	list_del_init(&ls->ls_perfile);
 	spin_unlock(&fp->fi_lock);
 
-	if (!nfsd4_layout_ops[ls->ls_layout_type]->disable_recalls)
-		vfs_setlease(ls->ls_file->nf_file, F_UNLCK, NULL, (void **)&ls);
-	nfsd_file_put(ls->ls_file);
+	/* ls_file is NULL if nfsd4_alloc_layout_stateid() bailed out early */
+	if (ls->ls_file) {
+		if (!nfsd4_layout_ops[ls->ls_layout_type]->disable_recalls)
+			vfs_setlease(ls->ls_file->nf_file, F_UNLCK, NULL,
+				     (void **)&ls);
+		nfsd_file_put(ls->ls_file);
+	}
 
 	if (ls->ls_recalled)
 		atomic_dec(&ls->ls_stid.sc_file->fi_lo_recalls);
-- 
2.39.3


                 reply	other threads:[~2026-11-09  8:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261109084932.3861080-1-joseph.qi@linux.alibaba.com \
    --to=joseph.qi@linux.alibaba.com \
    --cc=cel@kernel.org \
    --cc=jlayton@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=sashal@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

all inboxes | Powered by JetHome®