Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/uvm Clean up assertions and catch integer overflow.



details:   https://anonhg.NetBSD.org/src/rev/edc56abce525
branches:  trunk
changeset: 342103:edc56abce525
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Sun Dec 06 08:53:22 2015 +0000

description:
Clean up assertions and catch integer overflow.

diffstat:

 sys/uvm/uvm_vnode.c |  16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diffs (50 lines):

diff -r 1c43bf338887 -r edc56abce525 sys/uvm/uvm_vnode.c
--- a/sys/uvm/uvm_vnode.c       Sun Dec 06 07:40:04 2015 +0000
+++ b/sys/uvm/uvm_vnode.c       Sun Dec 06 08:53:22 2015 +0000
@@ -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 @@
         * 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 @@
 {
 
        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);



Home | Main Index | Thread Index | Old Index