Skip to content

Commit

Permalink
lockd: set file_lock start and end when decoding nlm4 testargs
Browse files Browse the repository at this point in the history
Commit 6930bcb dropped the setting of the file_lock range when
decoding a nlm_lock off the wire. This causes the client side grant
callback to miss matching blocks and reject the lock, only to rerequest
it 30s later.

Add a helper function to set the file_lock range from the start and end
values that the protocol uses, and have the nlm_lock decoder call that to
set up the file_lock args properly.

Fixes: 6930bcb ("lockd: detect and reject lock arguments that overflow")
Reported-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
Tested-by: Amir Goldstein <amir73il@gmail.com>
Cc: stable@vger.kernel.org #6.0
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
  • Loading branch information
jtlayton authored and amschuma-ntap committed Mar 14, 2023
1 parent 9c88ea0 commit 7ff8491
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
9 changes: 1 addition & 8 deletions fs/lockd/clnt4xdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ static int decode_nlm4_holder(struct xdr_stream *xdr, struct nlm_res *result)
u32 exclusive;
int error;
__be32 *p;
s32 end;

memset(lock, 0, sizeof(*lock));
locks_init_lock(fl);
Expand All @@ -285,13 +284,7 @@ static int decode_nlm4_holder(struct xdr_stream *xdr, struct nlm_res *result)
fl->fl_type = exclusive != 0 ? F_WRLCK : F_RDLCK;
p = xdr_decode_hyper(p, &l_offset);
xdr_decode_hyper(p, &l_len);
end = l_offset + l_len - 1;

fl->fl_start = (loff_t)l_offset;
if (l_len == 0 || end < 0)
fl->fl_end = OFFSET_MAX;
else
fl->fl_end = (loff_t)end;
nlm4svc_set_file_lock_range(fl, l_offset, l_len);
error = 0;
out:
return error;
Expand Down
13 changes: 12 additions & 1 deletion fs/lockd/xdr4.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ loff_t_to_s64(loff_t offset)
return res;
}

void nlm4svc_set_file_lock_range(struct file_lock *fl, u64 off, u64 len)
{
s64 end = off + len - 1;

fl->fl_start = off;
if (len == 0 || end < 0)
fl->fl_end = OFFSET_MAX;
else
fl->fl_end = end;
}

/*
* NLM file handles are defined by specification to be a variable-length
* XDR opaque no longer than 1024 bytes. However, this implementation
Expand Down Expand Up @@ -80,7 +91,7 @@ svcxdr_decode_lock(struct xdr_stream *xdr, struct nlm_lock *lock)
locks_init_lock(fl);
fl->fl_flags = FL_POSIX;
fl->fl_type = F_RDLCK;

nlm4svc_set_file_lock_range(fl, lock->lock_start, lock->lock_len);
return true;
}

Expand Down
1 change: 1 addition & 0 deletions include/linux/lockd/xdr4.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define nlm4_fbig cpu_to_be32(NLM_FBIG)
#define nlm4_failed cpu_to_be32(NLM_FAILED)

void nlm4svc_set_file_lock_range(struct file_lock *fl, u64 off, u64 len);
bool nlm4svc_decode_void(struct svc_rqst *rqstp, struct xdr_stream *xdr);
bool nlm4svc_decode_testargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
bool nlm4svc_decode_lockargs(struct svc_rqst *rqstp, struct xdr_stream *xdr);
Expand Down

0 comments on commit 7ff8491

Please sign in to comment.