Module Name: src
Committed By: mlelstv
Date: Sun Dec 6 08:53:22 UTC 2015
Modified Files:
src/sys/uvm: uvm_vnode.c
Log Message:
Clean up assertions and catch integer overflow.
To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/sys/uvm/uvm_vnode.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/uvm/uvm_vnode.c
diff -u src/sys/uvm/uvm_vnode.c:1.100 src/sys/uvm/uvm_vnode.c:1.101
--- src/sys/uvm/uvm_vnode.c:1.100 Mon Aug 24 22:50:32 2015
+++ src/sys/uvm/uvm_vnode.c Sun Dec 6 08:53:22 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: uvm_vnode.c,v 1.100 2015/08/24 22:50:32 pooka Exp $ */
+/* $NetBSD: uvm_vnode.c,v 1.101 2015/12/06 08:53:22 mlelstv Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -45,7 +45,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_vnode.c,v 1.100 2015/08/24 22:50:32 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_vnode.c,v 1.101 2015/12/06 08:53:22 mlelstv Exp $");
#ifdef _KERNEL_OPT
#include "opt_uvmhist.h"
@@ -348,15 +348,19 @@ uvm_vnp_setsize(struct vnode *vp, voff_t
* toss some pages...
*/
- KASSERT(newsize != VSIZENOTSET);
+ KASSERT(newsize != VSIZENOTSET && newsize >= 0);
KASSERT(vp->v_size <= vp->v_writesize);
KASSERT(vp->v_size == vp->v_writesize ||
newsize == vp->v_writesize || newsize <= vp->v_size);
oldsize = vp->v_writesize;
- KASSERT(oldsize != VSIZENOTSET || pgend > oldsize);
- if (oldsize > pgend) {
+ /*
+ * check wether size shrinks
+ * if old size hasn't been set, there are no pages to drop
+ * if there was an integer overflow in pgend, then this is no shrink
+ */
+ if (oldsize > pgend && oldsize != VSIZENOTSET && pgend >= 0) {
(void) uvn_put(uobj, pgend, 0, PGO_FREE | PGO_SYNCIO);
mutex_enter(uobj->vmobjlock);
}
@@ -369,7 +373,7 @@ uvm_vnp_setwritesize(struct vnode *vp, v
{
mutex_enter(vp->v_interlock);
- KASSERT(newsize != VSIZENOTSET);
+ KASSERT(newsize != VSIZENOTSET && newsize >= 0);
KASSERT(vp->v_size != VSIZENOTSET);
KASSERT(vp->v_writesize != VSIZENOTSET);
KASSERT(vp->v_size <= vp->v_writesize);