Source-Changes-HG archive

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

[src/pgoyette-compat]: src/sys/uvm Properly detect 'compat handler for SWAP_S...



details:   https://anonhg.NetBSD.org/src/rev/a27053dd3010
branches:  pgoyette-compat
changeset: 321021:a27053dd3010
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Tue Mar 13 21:59:51 2018 +0000

description:
Properly detect 'compat handler for SWAP_STATSxx not present' and return
EINVAL as we would for any other unsupported command.

diffstat:

 sys/uvm/uvm_swap.c |  32 +++++++++++++++++---------------
 1 files changed, 17 insertions(+), 15 deletions(-)

diffs (53 lines):

diff -r 8420475968c9 -r a27053dd3010 sys/uvm/uvm_swap.c
--- a/sys/uvm/uvm_swap.c        Tue Mar 13 09:10:31 2018 +0000
+++ b/sys/uvm/uvm_swap.c        Tue Mar 13 21:59:51 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_swap.c,v 1.175.2.1 2018/03/13 09:10:31 pgoyette Exp $      */
+/*     $NetBSD: uvm_swap.c,v 1.175.2.2 2018/03/13 21:59:51 pgoyette Exp $      */
 
 /*
  * Copyright (c) 1995, 1996, 1997, 2009 Matthew R. Green
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.175.2.1 2018/03/13 09:10:31 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_swap.c,v 1.175.2.2 2018/03/13 21:59:51 pgoyette Exp $");
 
 #include "opt_uvmhist.h"
 #include "opt_compat_netbsd.h"
@@ -499,19 +499,21 @@
         * to grab the uvm_swap_data_lock because we may fault&sleep during
         * copyout() and we don't want to be holding that lock then!
         */
-       len = 0;
-       if (SCARG(uap, cmd) == SWAP_STATS)
-               len = sizeof(struct swapent);
-       else if (SCARG(uap, cmd) == SWAP_STATS13)
-               len = swapstats_len_13;
-       else if (SCARG(uap, cmd) == SWAP_STATS50)
-               len = swapstats_len_50;
-       /*
-        * If the compat_* code isn't loaded, len will still be zero
-        * and we'll just fall through and return EINVAL
-        */
-       if (len > 0) {
-               if (misc < 0) {
+       if (SCARG(uap,cmd) == SWAP_STATS || SCARG(uap, cmd) == SWAP_STATS13 ||
+           SCARG(uap,cmd) == SWAP_STATS50) {
+               len = 0;
+               if (SCARG(uap, cmd) == SWAP_STATS)
+                       len = sizeof(struct swapent);
+               else if (SCARG(uap, cmd) == SWAP_STATS13)
+                       len = swapstats_len_13;
+               else if (SCARG(uap, cmd) == SWAP_STATS50)
+                       len = swapstats_len_50;
+               /*
+                * If len is still zero at this point, no compat code
+                * for the current cmd exists, so error out.  Also,
+                * error if user-specified buffer size is less than zero.
+                */
+               if (len == 0 || misc < 0) {
                        error = EINVAL;
                        goto out;
                }



Home | Main Index | Thread Index | Old Index