Skip to contentSkip to conversation

FAILED: patch "[PATCH] lockd: fix NULL dereference on lockowner allocation failure" failed to apply to 5.10-stable tree

PATCH New [email protected] 2 participants 3 messages Sep 3 – Sep 9

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x 4c7fc129db061c7daab841c4f3c342d894832362
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090351-sprung-ongoing-f2c7@gregkh' --subject-prefix 'PATCH 5.10.y' 'HEAD^..'

Possible dependencies:

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 4c7fc129db061c7daab841c4f3c342d894832362 Mon Sep 17 00:00:00 2001
From: Shuangpeng Bai <[email protected]>
Date: Fri, 17 Jul 2026 13:28:09 -0400
Subject: [PATCH] lockd: fix NULL dereference on lockowner allocation failure

nlmclnt_locks_init_private() installs NLM file lock operations even when nlmclnt_find_lockowner() fails to allocate a lockowner. nlmclnt_proc() then returns -ENOMEM, but the VFS still tears down the partially initialized file_lock and calls locks_release_private().

That invokes nlmclnt_locks_release_private(), which dereferences fl->fl_u.nfs_fl.owner and crashes because the owner was never installed.

Clear fl_ops before attempting to initialize the NLM private state, and install the NLM lock operations only after a lockowner has been allocated successfully.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
fs/lockd/clntproc.c +3 -0
index f06faf577cea..f8018bfe9c64 100644
@@ -487,9 +487,12 @@ static const struct file_lock_operations nlmclnt_lock_ops = {
 static void nlmclnt_locks_init_private(struct file_lock *fl, struct nlm_host *host)
 {
 	fl->fl_u.nfs_fl.state = 0;
+	fl->fl_ops = NULL;
 	fl->fl_u.nfs_fl.owner = nlmclnt_find_lockowner(host,
 						       fl->c.flc_owner);
 	INIT_LIST_HEAD(&fl->fl_u.nfs_fl.list);
+	if (!fl->fl_u.nfs_fl.owner)
+		return;
 	fl->fl_ops = &nlmclnt_lock_ops;
 }
 
maintainer
#1 lore raw

PATCH 1/2 filelock: split common fields into struct file_lock_core

From: Jeff Layton <[email protected]>

[ Upstream commit a69ce85ec9af6bdc0b3511959a7dc1a324e5e16a ]

In a future patch, we're going to split file leases into their own structure. Since a lot of the underlying machinery uses the same fields move those into a new file_lock_core, and embed that inside struct file_lock.

For now, add some macros to ensure that we can continue to build while the conversion is in progress.

[6.1 dependency adaptation]
The stable tree still defines struct file_lock in include/linux/fs.h and has neither the separate filelock.h header nor the later locking helpers. Define file_lock_core in the existing header, retaining the stable tree's unsigned fl_pid type. Embed the core in an anonymous union with matching legacy fields so existing users and trace-event field names continue to work without global field-name macros or a tree-wide conversion.

Use c.flc_owner in nlmclnt_locks_init_private(), with upstream formatting, to prepare the exact context required by 4c7fc129db061 ("lockd: fix NULL dereference on lockowner allocation failure"). Leave that fix itself to the target commit. Drop the unused macro-enabling includes, conversions of absent helpers, and unrelated whitespace changes. No functions are added.

[ sashal: Reduced backport -- upstream a69ce85ec9af6 touches 24 file(s), this
backport carries 2. Not backported here:
fs/9p/vfs_file.c
fs/afs/internal.h
fs/ceph/locks.c
fs/dlm/plock.c
fs/fuse/file.c
fs/gfs2/file.c
fs/locks.c
fs/nfsd/netns.h
... and 15 more
This note is generated from the file lists only; see the resolution record for the reasoning. ]

Stable-dep-of: 4c7fc129db06 ("lockd: fix NULL dereference on lockowner allocation failure")

---
 fs/lockd/clntproc.c |  3 ++-
 include/linux/fs.h  | 56 ++++++++++++++++++++++++++++++++-------------
 2 files changed, 42 insertions(+), 17 deletions(-)
fs/lockd/clntproc.c +2 -1
index 99fffc9cb9585..32790a57351a5 100644
@@ -479,7 +479,8 @@ static const struct file_lock_operations nlmclnt_lock_ops = {
 static void nlmclnt_locks_init_private(struct file_lock *fl, struct nlm_host *host)
 {
 	fl->fl_u.nfs_fl.state = 0;
-	fl->fl_u.nfs_fl.owner = nlmclnt_find_lockowner(host, fl->fl_owner);
+	fl->fl_u.nfs_fl.owner = nlmclnt_find_lockowner(host,
+						       fl->c.flc_owner);
 	INIT_LIST_HEAD(&fl->fl_u.nfs_fl.list);
 	fl->fl_ops = &nlmclnt_lock_ops;
 }
include/linux/fs.h +40 -16

68 lines not on this page · raw message

Signature · 1 line
2.53.0
maintainer
#2 lore raw

PATCH 2/2 lockd: fix NULL dereference on lockowner allocation failure

From: Shuangpeng Bai <[email protected]>

[ Upstream commit 4c7fc129db061c7daab841c4f3c342d894832362 ]

nlmclnt_locks_init_private() installs NLM file lock operations even when nlmclnt_find_lockowner() fails to allocate a lockowner. nlmclnt_proc() then returns -ENOMEM, but the VFS still tears down the partially initialized file_lock and calls locks_release_private().

That invokes nlmclnt_locks_release_private(), which dereferences fl->fl_u.nfs_fl.owner and crashes because the owner was never installed.

Clear fl_ops before attempting to initialize the NLM private state, and install the NLM lock operations only after a lockowner has been allocated successfully.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 fs/lockd/clntproc.c | 3 +++
 1 file changed, 3 insertions(+)
fs/lockd/clntproc.c +3 -0
index 32790a57351a5..bae25519771d1 100644
@@ -479,9 +479,12 @@ static const struct file_lock_operations nlmclnt_lock_ops = {
 static void nlmclnt_locks_init_private(struct file_lock *fl, struct nlm_host *host)
 {
 	fl->fl_u.nfs_fl.state = 0;
+	fl->fl_ops = NULL;
 	fl->fl_u.nfs_fl.owner = nlmclnt_find_lockowner(host,
 						       fl->c.flc_owner);
 	INIT_LIST_HEAD(&fl->fl_u.nfs_fl.list);
+	if (!fl->fl_u.nfs_fl.owner)
+		return;
 	fl->fl_ops = &nlmclnt_lock_ops;
 }
 
Signature · 1 line
2.53.0