summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoranton <anton@openbsd.org>2019-06-18 07:33:24 +0000
committeranton <anton@openbsd.org>2019-06-18 07:33:24 +0000
commit68f41304bb411f03ab1705da1a6951ecca2fbb8c (patch)
treee3678fa339e52b6d604463bf2d5d72da28d931ac
parentThere is no need to -I${.OBJDIR} (diff)
downloadwireguard-openbsd-68f41304bb411f03ab1705da1a6951ecca2fbb8c.tar.xz
wireguard-openbsd-68f41304bb411f03ab1705da1a6951ecca2fbb8c.zip
Ensure the length passed to ffs_truncate() is within bounds before calling
uvm_vnp_setsize() which is not free from side-effects. ok visa@
-rw-r--r--sys/ufs/ffs/ffs_inode.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/sys/ufs/ffs/ffs_inode.c b/sys/ufs/ffs/ffs_inode.c
index 62ebc844cd7..686de3a5dcb 100644
--- a/sys/ufs/ffs/ffs_inode.c
+++ b/sys/ufs/ffs/ffs_inode.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ffs_inode.c,v 1.77 2018/03/30 17:35:20 dhill Exp $ */
+/* $OpenBSD: ffs_inode.c,v 1.78 2019/06/18 07:33:24 anton Exp $ */
/* $NetBSD: ffs_inode.c,v 1.10 1996/05/11 18:27:19 mycroft Exp $ */
/*
@@ -168,6 +168,10 @@ ffs_truncate(struct inode *oip, off_t length, int flags, struct ucred *cred)
if ((error = getinoquota(oip)) != 0)
return (error);
+ fs = oip->i_fs;
+ if (length > fs->fs_maxfilesize)
+ return (EFBIG);
+
uvm_vnp_setsize(ovp, length);
oip->i_ci.ci_lasta = oip->i_ci.ci_clen
= oip->i_ci.ci_cstart = oip->i_ci.ci_lastw = 0;
@@ -196,7 +200,6 @@ ffs_truncate(struct inode *oip, off_t length, int flags, struct ucred *cred)
}
}
- fs = oip->i_fs;
osize = DIP(oip, size);
/*
* Lengthen the size of the file. We must ensure that the
@@ -204,8 +207,6 @@ ffs_truncate(struct inode *oip, off_t length, int flags, struct ucred *cred)
* value of osize is 0, length will be at least 1.
*/
if (osize < length) {
- if (length > fs->fs_maxfilesize)
- return (EFBIG);
aflags = B_CLRBUF;
if (flags & IO_SYNC)
aflags |= B_SYNC;