Skip to contentSkip to conversation

lockd: Fix invalid lockowner cast after vfs_test_lock

PATCH Superseded Benjamin Coddington 2 participants 3 messages Jul 25, 2021 – Jul 26, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lockd: Fix invalid lockowner cast after vfs_test_lock

After calling vfs_test_lock() the pointer to a conflicting lock can be returned, and that lock is not garunteed to owned by nlm. In that case, we cannot cast it to struct nlm_lockowner. Instead, return the pid of that conflicting lock.

Fixes 646d73e91b42 ("lockd: Show pid of lockd for remote locks")
---
 fs/lockd/svclock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/lockd/svclock.c +1 -1
index 61d3cc2283dc..498cb70c2c0d 100644
@@ -634,7 +634,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
 	conflock->caller = "somehost";	/* FIXME */
 	conflock->len = strlen(conflock->caller);
 	conflock->oh.len = 0;		/* don't return OH info */
-	conflock->svid = ((struct nlm_lockowner *)lock->fl.fl_owner)->pid;
+	conflock->svid = lock->fl.fl_pid;
 	conflock->fl.fl_type = lock->fl.fl_type;
 	conflock->fl.fl_start = lock->fl.fl_start;
 	conflock->fl.fl_end = lock->fl.fl_end;
Signature · 1 line
2.30.2
#1 lore raw

PATCH v2 1/1 lockd: Fix invalid lockowner cast after vfs_test_lock

V2: fix typos in patch header

8<-------------------------------------------------------

After calling vfs_test_lock() the pointer to a conflicting lock can be returned, and that lock is not guarunteed to be owned by nlm. In that case, we cannot cast it to struct nlm_lockowner. Instead return the pid of that conflicting lock.

Fixes 646d73e91b42 ("lockd: Show pid of lockd for remote locks")
---
 fs/lockd/svclock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/lockd/svclock.c +1 -1
index 61d3cc2283dc..498cb70c2c0d 100644
@@ -634,7 +634,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
 	conflock->caller = "somehost";	/* FIXME */
 	conflock->len = strlen(conflock->caller);
 	conflock->oh.len = 0;		/* don't return OH info */
-	conflock->svid = ((struct nlm_lockowner *)lock->fl.fl_owner)->pid;
+	conflock->svid = lock->fl.fl_pid;
 	conflock->fl.fl_type = lock->fl.fl_type;
 	conflock->fl.fl_start = lock->fl.fl_start;
 	conflock->fl.fl_end = lock->fl.fl_end;
Signature · 1 line
2.30.2
#2 lore raw

Hi Ben-

Quoted 6 lines · Benjamin Coddington

V2: fix typos in patch header

8<-------------------------------------------------------

Quoted 7 lines

After calling vfs_test_lock() the pointer to a conflicting lock can be returned, and that lock is not guarunteed to be owned by nlm. In that case, we cannot cast it to struct nlm_lockowner. Instead return the pid of that conflicting lock.

Fixes 646d73e91b42 ("lockd: Show pid of lockd for remote locks")

I've added this change provisionally to

https://git.kernel.org/pub/scm/linux/kernel/git/cel/linux.git/log/?h=for-next

Quoted 20 lines

---
fs/lockd/svclock.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
fs/lockd/svclock.c +1 -1
index 61d3cc2283dc..498cb70c2c0d 100644
@@ -634,7 +634,7 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
 	conflock->caller = "somehost";	/* FIXME */
 	conflock->len = strlen(conflock->caller);
 	conflock->oh.len = 0;		/* don't return OH info */
-	conflock->svid = ((struct nlm_lockowner *)lock->fl.fl_owner)->pid;
+	conflock->svid = lock->fl.fl_pid;
 	conflock->fl.fl_type = lock->fl.fl_type;
 	conflock->fl.fl_start = lock->fl.fl_start;
 	conflock->fl.fl_end = lock->fl.fl_end;
Signature · 1 line
2.30.2

--
Chuck Lever