Skip to content

Commit 69840cc

Browse files
jtlaytonsmb49
authored andcommitted
lockd: set file_lock start and end when decoding nlm4 testargs
BugLink: https://bugs.launchpad.net/bugs/2023230 commit 7ff8491 upstream. 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 <[email protected]> Signed-off-by: Jeff Layton <[email protected]> Tested-by: Amir Goldstein <[email protected]> Cc: [email protected] #6.0 Signed-off-by: Anna Schumaker <[email protected]> Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Kamal Mostafa <[email protected]> Signed-off-by: Luke Nowakowski-Krijger <[email protected]>
1 parent 6258118 commit 69840cc

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

fs/lockd/clnt4xdr.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ static int decode_nlm4_holder(struct xdr_stream *xdr, struct nlm_res *result)
261261
u32 exclusive;
262262
int error;
263263
__be32 *p;
264-
s32 end;
265264

266265
memset(lock, 0, sizeof(*lock));
267266
locks_init_lock(fl);
@@ -285,13 +284,7 @@ static int decode_nlm4_holder(struct xdr_stream *xdr, struct nlm_res *result)
285284
fl->fl_type = exclusive != 0 ? F_WRLCK : F_RDLCK;
286285
p = xdr_decode_hyper(p, &l_offset);
287286
xdr_decode_hyper(p, &l_len);
288-
end = l_offset + l_len - 1;
289-
290-
fl->fl_start = (loff_t)l_offset;
291-
if (l_len == 0 || end < 0)
292-
fl->fl_end = OFFSET_MAX;
293-
else
294-
fl->fl_end = (loff_t)end;
287+
nlm4svc_set_file_lock_range(fl, l_offset, l_len);
295288
error = 0;
296289
out:
297290
return error;

fs/lockd/xdr4.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ loff_t_to_s64(loff_t offset)
3333
return res;
3434
}
3535

36+
void nlm4svc_set_file_lock_range(struct file_lock *fl, u64 off, u64 len)
37+
{
38+
s64 end = off + len - 1;
39+
40+
fl->fl_start = off;
41+
if (len == 0 || end < 0)
42+
fl->fl_end = OFFSET_MAX;
43+
else
44+
fl->fl_end = end;
45+
}
46+
3647
/*
3748
* NLM file handles are defined by specification to be a variable-length
3849
* XDR opaque no longer than 1024 bytes. However, this implementation
@@ -80,7 +91,7 @@ svcxdr_decode_lock(struct xdr_stream *xdr, struct nlm_lock *lock)
8091
locks_init_lock(fl);
8192
fl->fl_flags = FL_POSIX;
8293
fl->fl_type = F_RDLCK;
83-
94+
nlm4svc_set_file_lock_range(fl, lock->lock_start, lock->lock_len);
8495
return true;
8596
}
8697

include/linux/lockd/xdr4.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525

2626

27+
void nlm4svc_set_file_lock_range(struct file_lock *fl, u64 off, u64 len);
2728
int nlm4svc_decode_testargs(struct svc_rqst *, __be32 *);
2829
int nlm4svc_encode_testres(struct svc_rqst *, __be32 *);
2930
int nlm4svc_decode_lockargs(struct svc_rqst *, __be32 *);

0 commit comments

Comments
 (0)