Skip to content

Commit 6930bcb

Browse files
jtlaytonchucklever
authored andcommitted
lockd: detect and reject lock arguments that overflow
lockd doesn't currently vet the start and length in nlm4 requests like it should, and can end up generating lock requests with arguments that overflow when passed to the filesystem. The NLM4 protocol uses unsigned 64-bit arguments for both start and length, whereas struct file_lock tracks the start and end as loff_t values. By the time we get around to calling nlm4svc_retrieve_args, we've lost the information that would allow us to determine if there was an overflow. Start tracking the actual start and len for NLM4 requests in the nlm_lock. In nlm4svc_retrieve_args, vet these values to ensure they won't cause an overflow, and return NLM4_FBIG if they do. Link: https://bugzilla.linux-nfs.org/show_bug.cgi?id=392 Reported-by: Jan Kasiak <[email protected]> Signed-off-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]> Cc: <[email protected]> # 5.14+
1 parent dd8dd40 commit 6930bcb

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

fs/lockd/svc4proc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ nlm4svc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,
3232
if (!nlmsvc_ops)
3333
return nlm_lck_denied_nolocks;
3434

35+
if (lock->lock_start > OFFSET_MAX ||
36+
(lock->lock_len && ((lock->lock_len - 1) > (OFFSET_MAX - lock->lock_start))))
37+
return nlm4_fbig;
38+
3539
/* Obtain host handle */
3640
if (!(host = nlmsvc_lookup_host(rqstp, lock->caller, lock->len))
3741
|| (argp->monitor && nsm_monitor(host) < 0))
@@ -50,6 +54,10 @@ nlm4svc_retrieve_args(struct svc_rqst *rqstp, struct nlm_args *argp,
5054
/* Set up the missing parts of the file_lock structure */
5155
lock->fl.fl_file = file->f_file[mode];
5256
lock->fl.fl_pid = current->tgid;
57+
lock->fl.fl_start = (loff_t)lock->lock_start;
58+
lock->fl.fl_end = lock->lock_len ?
59+
(loff_t)(lock->lock_start + lock->lock_len - 1) :
60+
OFFSET_MAX;
5361
lock->fl.fl_lmops = &nlmsvc_lock_operations;
5462
nlmsvc_locks_init_private(&lock->fl, host, (pid_t)lock->svid);
5563
if (!lock->fl.fl_owner) {

fs/lockd/xdr4.c

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@
2020

2121
#include "svcxdr.h"
2222

23-
static inline loff_t
24-
s64_to_loff_t(__s64 offset)
25-
{
26-
return (loff_t)offset;
27-
}
28-
29-
3023
static inline s64
3124
loff_t_to_s64(loff_t offset)
3225
{
@@ -70,8 +63,6 @@ static bool
7063
svcxdr_decode_lock(struct xdr_stream *xdr, struct nlm_lock *lock)
7164
{
7265
struct file_lock *fl = &lock->fl;
73-
u64 len, start;
74-
s64 end;
7566

7667
if (!svcxdr_decode_string(xdr, &lock->caller, &lock->len))
7768
return false;
@@ -81,20 +72,14 @@ svcxdr_decode_lock(struct xdr_stream *xdr, struct nlm_lock *lock)
8172
return false;
8273
if (xdr_stream_decode_u32(xdr, &lock->svid) < 0)
8374
return false;
84-
if (xdr_stream_decode_u64(xdr, &start) < 0)
75+
if (xdr_stream_decode_u64(xdr, &lock->lock_start) < 0)
8576
return false;
86-
if (xdr_stream_decode_u64(xdr, &len) < 0)
77+
if (xdr_stream_decode_u64(xdr, &lock->lock_len) < 0)
8778
return false;
8879

8980
locks_init_lock(fl);
9081
fl->fl_flags = FL_POSIX;
9182
fl->fl_type = F_RDLCK;
92-
end = start + len - 1;
93-
fl->fl_start = s64_to_loff_t(start);
94-
if (len == 0 || end < 0)
95-
fl->fl_end = OFFSET_MAX;
96-
else
97-
fl->fl_end = s64_to_loff_t(end);
9883

9984
return true;
10085
}

include/linux/lockd/xdr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ struct nlm_lock {
4141
struct nfs_fh fh;
4242
struct xdr_netobj oh;
4343
u32 svid;
44+
u64 lock_start;
45+
u64 lock_len;
4446
struct file_lock fl;
4547
};
4648

0 commit comments

Comments
 (0)