Skip to content

Commit ca2a05a

Browse files
author
J. Bruce Fields
committed
nfsd: Fix handling of negative lengths in read_buf()
The length "nbytes" passed into read_buf should never be negative, but we check only for too-large values of "nbytes", not for too-small values. Make nbytes unsigned, so it's clear that the former tests are sufficient. (Despite this read_buf() currently correctly returns an xdr error in the case of a negative length, thanks to an unsigned comparison with size_of() and bounds-checking in kmalloc(). This seems very fragile, though.) Signed-off-by: J. Bruce Fields <[email protected]>
1 parent a490c68 commit ca2a05a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

fs/nfsd/nfs4xdr.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ xdr_error: \
148148
} \
149149
} while (0)
150150

151-
static __be32 *read_buf(struct nfsd4_compoundargs *argp, int nbytes)
151+
static __be32 *read_buf(struct nfsd4_compoundargs *argp, u32 nbytes)
152152
{
153153
/* We want more bytes than seem to be available.
154154
* Maybe we need a new page, maybe we have just run out
155155
*/
156-
int avail = (char*)argp->end - (char*)argp->p;
156+
unsigned int avail = (char *)argp->end - (char *)argp->p;
157157
__be32 *p;
158158
if (avail + argp->pagelen < nbytes)
159159
return NULL;
@@ -169,6 +169,11 @@ static __be32 *read_buf(struct nfsd4_compoundargs *argp, int nbytes)
169169
return NULL;
170170

171171
}
172+
/*
173+
* The following memcpy is safe because read_buf is always
174+
* called with nbytes > avail, and the two cases above both
175+
* guarantee p points to at least nbytes bytes.
176+
*/
172177
memcpy(p, argp->p, avail);
173178
/* step to next page */
174179
argp->p = page_address(argp->pagelist[0]);

0 commit comments

Comments
 (0)