summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2013-12-17 13:10:28 +0000
committerkib <kib@FreeBSD.org>2013-12-17 13:10:28 +0000
commit293c11687ede082f16e5f20e6fa5328b1330cf99 (patch)
treef72d550178dfa61795c52e6c7f668436e697664b
parent758e3a99342f38f2affc2019fd5b16adf0898255 (diff)
downloadFreeBSD-src-293c11687ede082f16e5f20e6fa5328b1330cf99.zip
FreeBSD-src-293c11687ede082f16e5f20e6fa5328b1330cf99.tar.gz
MFC r258088:
Add check for buflen overflow by comparing the buflen with both offset and resid. MFC r258397: Redo r258088 to avoid relying on signed arithmetic overflow.
-rw-r--r--sys/fs/pseudofs/pseudofs_vnops.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/sys/fs/pseudofs/pseudofs_vnops.c b/sys/fs/pseudofs/pseudofs_vnops.c
index 9f97cd3..f00b4b2 100644
--- a/sys/fs/pseudofs/pseudofs_vnops.c
+++ b/sys/fs/pseudofs/pseudofs_vnops.c
@@ -616,8 +616,7 @@ pfs_read(struct vop_read_args *va)
struct proc *proc;
struct sbuf *sb = NULL;
int error, locked;
- off_t offset;
- ssize_t buflen, resid;
+ off_t buflen;
PFS_TRACE(("%s", pn->pn_name));
pfs_assert_not_owned(pn);
@@ -654,14 +653,12 @@ pfs_read(struct vop_read_args *va)
goto ret;
}
- /* beaucoup sanity checks so we don't ask for bogus allocation */
- if (uio->uio_offset < 0 || uio->uio_resid < 0 ||
- (offset = uio->uio_offset) != uio->uio_offset ||
- (resid = uio->uio_resid) != uio->uio_resid ||
- (buflen = offset + resid) < offset || buflen >= INT_MAX) {
+ if (uio->uio_resid < 0 || uio->uio_offset < 0 ||
+ uio->uio_resid > OFF_MAX - uio->uio_offset) {
error = EINVAL;
goto ret;
}
+ buflen = uio->uio_offset + uio->uio_resid;
if (buflen > MAXPHYS)
buflen = MAXPHYS;
OpenPOWER on IntegriCloud