Skip to content

Commit 13bf9fb

Browse files
author
J. Bruce Fields
committed
nfsd: stricter decoding of write-like NFSv2/v3 ops
The NFSv2/v3 code does not systematically check whether we decode past the end of the buffer. This generally appears to be harmless, but there are a few places where we do arithmetic on the pointers involved and don't account for the possibility that a length could be negative. Add checks to catch these. Reported-by: Tuomas Haanpää <[email protected]> Reported-by: Ari Kauppi <[email protected]> Reviewed-by: NeilBrown <[email protected]> Cc: [email protected] Signed-off-by: J. Bruce Fields <[email protected]>
1 parent db44bac commit 13bf9fb

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

fs/nfsd/nfs3xdr.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ nfs3svc_decode_writeargs(struct svc_rqst *rqstp, __be32 *p,
369369
args->count = ntohl(*p++);
370370
args->stable = ntohl(*p++);
371371
len = args->len = ntohl(*p++);
372+
if ((void *)p > head->iov_base + head->iov_len)
373+
return 0;
372374
/*
373375
* The count must equal the amount of data passed.
374376
*/
@@ -472,6 +474,8 @@ nfs3svc_decode_symlinkargs(struct svc_rqst *rqstp, __be32 *p,
472474
/* first copy and check from the first page */
473475
old = (char*)p;
474476
vec = &rqstp->rq_arg.head[0];
477+
if ((void *)old > vec->iov_base + vec->iov_len)
478+
return 0;
475479
avail = vec->iov_len - (old - (char*)vec->iov_base);
476480
while (len && avail && *old) {
477481
*new++ = *old++;

fs/nfsd/nfsxdr.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ nfssvc_decode_writeargs(struct svc_rqst *rqstp, __be32 *p,
302302
* bytes.
303303
*/
304304
hdr = (void*)p - head->iov_base;
305+
if (hdr > head->iov_len)
306+
return 0;
305307
dlen = head->iov_len + rqstp->rq_arg.page_len - hdr;
306308

307309
/*

0 commit comments

Comments
 (0)