Skip to contentSkip to conversation

nfsd/dlm: fix knfsd panic when NFSv4 client does GETLK call

PATCH Applied Jeff Layton 2 participants 7 messages Jan 22, 2009 – Jan 27, 2009

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

cover nfsd/dlm: fix knfsd panic when NFSv4 client does GETLK call

This patchset fixes a regression due to this patch:

----------------[snip]----------------
commit 55ef1274dddd4de387c54d110e354ffbb6cdc706

Author: J. Bruce Fields <[email protected]>
Date:   Sat Dec 20 11:58:38 2008 -0800

nfsd: Ensure nfsv4 calls the underlying filesystem on LOCKT
----------------[snip]----------------

To reproduce, set up a nfs server that is serving out a GFS2 filesystem. Set a lock locally on a file on the GFS2 export on the server. From a NFSv4 client, do a GETLK against the same file. The server will oops due to a NULL pointer dereference. The fl_lmops will be set, but the fl_owner will be a NULL pointer. The knfsd code does not account for this possibility. It assumes that when fl_lmops is set this way that the fl_owner will point to a valid nfs4_stateowner struct.

In actuality, Bruce's patch is correct, but it exposes a bug in DLM's GETLK codepath. The first patch in this set fixes that.

The second patch fixes knfsd to be a little more careful about the file_lock struct it builds to pass to vfs_test_lock.

Either patch should prevent the panic, though I think applying both patches is the best approach to fixing this.

Jeff Layton (2):
dlm: initialize file_lock struct in GETLK before copying conflicting
lock
nfsd: only set file_lock.fl_lmops in nfsd4_lockt if a stateowner is
found

 fs/dlm/plock.c      |    2 ++
 fs/nfsd/nfs4state.c |    1 -
 2 files changed, 2 insertions(+), 1 deletions(-)
#1 lore raw

PATCH 1/2 dlm: initialize file_lock struct in GETLK before copying conflicting lock

dlm_posix_get fills out the relevant fields in the file_lock before returning when there is a lock conflict, but doesn't clean out any of the other fields in the file_lock.

When nfsd does a NFSv4 lockt call, it sets the fl_lmops to nfsd_posix_mng_ops before calling the lower fs. When the lock comes back after testing a lock on GFS2, it still has that field set. This confuses nfsd into thinking that the file_lock is a nfsd4 lock.

Fix this by making DLM reinitialize the file_lock before copying the fields from the conflicting lock.

---
 fs/dlm/plock.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
fs/dlm/plock.c +2 -0
index eba87ff..ca46f11 100644
@@ -304,7 +304,9 @@ int dlm_posix_get(dlm_lockspace_t *lockspace, u64 number, struct file *file,
 	if (rv == -ENOENT)
 		rv = 0;
 	else if (rv > 0) {
+		locks_init_lock(fl);
 		fl->fl_type = (op->info.ex) ? F_WRLCK : F_RDLCK;
+		fl->fl_flags = FL_POSIX;
 		fl->fl_pid = op->info.pid;
 		fl->fl_start = op->info.start;
 		fl->fl_end = op->info.end;
Signature · 1 line
1.5.5.6
#2 lore raw

Re: [PATCH 1/2] dlm: initialize file_lock struct in GETLK before copying conflicting lock

Quoted 9 lines · Jeff Layton

dlm_posix_get fills out the relevant fields in the file_lock before returning when there is a lock conflict, but doesn't clean out any of the other fields in the file_lock.

When nfsd does a NFSv4 lockt call, it sets the fl_lmops to nfsd_posix_mng_ops before calling the lower fs. When the lock comes back after testing a lock on GFS2, it still has that field set. This confuses nfsd into thinking that the file_lock is a nfsd4 lock.

Quoted 4 lines

Fix this by making DLM reinitialize the file_lock before copying the fields from the conflicting lock.

I'll leave this one to gfs2 people to apply unless I'm told otherwise.

--b.

Quoted 21 lines
---
 fs/dlm/plock.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
fs/dlm/plock.c +2 -0
index eba87ff..ca46f11 100644
@@ -304,7 +304,9 @@ int dlm_posix_get(dlm_lockspace_t *lockspace, u64 number, struct file *file,
 	if (rv == -ENOENT)
 		rv = 0;
 	else if (rv > 0) {
+		locks_init_lock(fl);
 		fl->fl_type = (op->info.ex) ? F_WRLCK : F_RDLCK;
+		fl->fl_flags = FL_POSIX;
 		fl->fl_pid = op->info.pid;
 		fl->fl_start = op->info.start;
 		fl->fl_end = op->info.end;
Signature · 1 line
1.5.5.6
#3 lore raw

Re: [PATCH 1/2] dlm: initialize file_lock struct in GETLK before copying conflicting lock

Quoted 10 lines · On Tue, 27 Jan 2009 17:34:01 -0500 "J. Bruce Fields" <[email protected]>…
Quoted 9 lines · Jeff Layton

dlm_posix_get fills out the relevant fields in the file_lock before returning when there is a lock conflict, but doesn't clean out any of the other fields in the file_lock.

When nfsd does a NFSv4 lockt call, it sets the fl_lmops to nfsd_posix_mng_ops before calling the lower fs. When the lock comes back after testing a lock on GFS2, it still has that field set. This confuses nfsd into thinking that the file_lock is a nfsd4 lock.

Quoted 9 lines
Quoted 4 lines

Fix this by making DLM reinitialize the file_lock before copying the fields from the conflicting lock.

I'll leave this one to gfs2 people to apply unless I'm told otherwise.

--b.

That should be fine. Dave T. has taken this into his tree and is pushing it to Linus.

Thanks,

Signature · 1 line
Jeff Layton <[email protected]>
#4 lore raw

PATCH 2/2 nfsd: only set file_lock.fl_lmops in nfsd4_lockt if a stateowner is found

In reply to Jeff Layton

nfsd4_lockt does a search for a lockstateowner when building the lock struct to test. If one is found, it'll set fl_owner to it. Regardless of whether that happens, it'll also set fl_lmops. Given that this lock is basically a "lightweight" lock that's just used for checking conflicts, setting fl_lmops is probably not appropriate for it.

This behavior exposed a bug in DLM's GETLK implementation where it wasn't clearing out the fields in the file_lock before filling in conflicting lock info. While we were able to fix this in DLM, it still seems pointless and dangerous to set the fl_lmops this way when we may have a NULL lockstateowner.

---
 fs/nfsd/nfs4state.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
fs/nfsd/nfs4state.c +0 -1
index 88db7d3..b6f60f4 100644
@@ -2871,7 +2871,6 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 		file_lock.fl_owner = (fl_owner_t)lockt->lt_stateowner;
 	file_lock.fl_pid = current->tgid;
 	file_lock.fl_flags = FL_POSIX;
-	file_lock.fl_lmops = &nfsd_posix_mng_ops;
 
 	file_lock.fl_start = lockt->lt_offset;
 	file_lock.fl_end = last_byte_offset(lockt->lt_offset, lockt->lt_length);
Signature · 1 line
1.5.5.6
#5 lore raw

Re: [PATCH 2/2] nfsd: only set file_lock.fl_lmops in nfsd4_lockt if a stateowner is found

Quoted 6 lines · Jeff Layton

nfsd4_lockt does a search for a lockstateowner when building the lock struct to test. If one is found, it'll set fl_owner to it. Regardless of whether that happens, it'll also set fl_lmops. Given that this lock is basically a "lightweight" lock that's just used for checking conflicts, setting fl_lmops is probably not appropriate for it.

Quoted 7 lines

This behavior exposed a bug in DLM's GETLK implementation where it wasn't clearing out the fields in the file_lock before filling in conflicting lock info. While we were able to fix this in DLM, it still seems pointless and dangerous to set the fl_lmops this way when we may have a NULL lockstateowner.

Thanks, applied.--b.

Quoted 19 lines
---
 fs/nfsd/nfs4state.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
fs/nfsd/nfs4state.c +0 -1
index 88db7d3..b6f60f4 100644
@@ -2871,7 +2871,6 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 		file_lock.fl_owner = (fl_owner_t)lockt->lt_stateowner;
 	file_lock.fl_pid = current->tgid;
 	file_lock.fl_flags = FL_POSIX;
-	file_lock.fl_lmops = &nfsd_posix_mng_ops;
 
 	file_lock.fl_start = lockt->lt_offset;
 	file_lock.fl_end = last_byte_offset(lockt->lt_offset, lockt->lt_length);
Signature · 1 line
1.5.5.6
#6 lore raw
In reply to Jeff Layton
Quoted 1 line · Jeff Layton

This patchset fixes a regression due to this patch:

These look reasonable, thanks.

My testing infrastructure and stuff is still down, so I may be a little slow getting these upstream.... Bug me again next week if I haven't done anything and you think of it.

--b.

Quoted 36 lines

----------------[snip]----------------
commit 55ef1274dddd4de387c54d110e354ffbb6cdc706

Author: J. Bruce Fields <[email protected]>
Date:   Sat Dec 20 11:58:38 2008 -0800

nfsd: Ensure nfsv4 calls the underlying filesystem on LOCKT
----------------[snip]----------------

To reproduce, set up a nfs server that is serving out a GFS2 filesystem. Set a lock locally on a file on the GFS2 export on the server. From a NFSv4 client, do a GETLK against the same file. The server will oops due to a NULL pointer dereference. The fl_lmops will be set, but the fl_owner will be a NULL pointer. The knfsd code does not account for this possibility. It assumes that when fl_lmops is set this way that the fl_owner will point to a valid nfs4_stateowner struct.

In actuality, Bruce's patch is correct, but it exposes a bug in DLM's GETLK codepath. The first patch in this set fixes that.

The second patch fixes knfsd to be a little more careful about the file_lock struct it builds to pass to vfs_test_lock.

Either patch should prevent the panic, though I think applying both patches is the best approach to fixing this.

Jeff Layton (2):
dlm: initialize file_lock struct in GETLK before copying conflicting
lock
nfsd: only set file_lock.fl_lmops in nfsd4_lockt if a stateowner is
found

 fs/dlm/plock.c      |    2 ++
 fs/nfsd/nfs4state.c |    1 -
 2 files changed, 2 insertions(+), 1 deletions(-)