Source-Changes-HG archive

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

[src/trunk]: src/sys/uvm uvm(9): fo_mmap caller guarantees positive size.



details:   https://anonhg.NetBSD.org/src/rev/b8a4f4704c96
branches:  trunk
changeset: 368339:b8a4f4704c96
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Wed Jul 06 01:12:45 2022 +0000

description:
uvm(9): fo_mmap caller guarantees positive size.

No functional change intended, just sprinkling assertions to make it
clearer.

diffstat:

 sys/dev/audio/audio.c                      |  8 ++++++--
 sys/dev/nvmm/nvmm.c                        |  6 ++++--
 sys/external/bsd/drm2/dist/drm/drm_prime.c |  6 ++++--
 sys/external/bsd/drm2/drm/drm_cdevsw.c     |  6 ++++--
 sys/external/bsd/drm2/drm/drm_gem_vm.c     |  8 ++++++--
 sys/external/bsd/drm2/drm/drm_vm.c         |  5 +++--
 sys/kern/kern_ksyms.c                      |  5 +++--
 sys/kern/subr_kcov.c                       |  4 +++-
 sys/kern/vfs_vnops.c                       |  6 ++++--
 sys/uvm/uvm_device.c                       |  6 ++++--
 sys/uvm/uvm_mmap.c                         |  6 ++++--
 11 files changed, 45 insertions(+), 21 deletions(-)

diffs (truncated from 311 to 300 lines):

diff -r 5ea4aa9120d7 -r b8a4f4704c96 sys/dev/audio/audio.c
--- a/sys/dev/audio/audio.c     Wed Jul 06 00:40:28 2022 +0000
+++ b/sys/dev/audio/audio.c     Wed Jul 06 01:12:45 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audio.c,v 1.133 2022/04/23 11:44:01 isaki Exp $        */
+/*     $NetBSD: audio.c,v 1.134 2022/07/06 01:12:45 riastradh Exp $    */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -181,7 +181,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.133 2022/04/23 11:44:01 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.134 2022/07/06 01:12:45 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -2098,6 +2098,8 @@
        int bound;
        int error;
 
+       KASSERT(len > 0);
+
        KASSERT(fp->f_audioctx);
        file = fp->f_audioctx;
        dev = file->dev;
@@ -3562,6 +3564,8 @@
 
        TRACEF(2, file, "off=%lld, prot=%d", (long long)(*offp), prot);
 
+       KASSERT(len > 0);
+
        if (*offp < 0)
                return EINVAL;
 
diff -r 5ea4aa9120d7 -r b8a4f4704c96 sys/dev/nvmm/nvmm.c
--- a/sys/dev/nvmm/nvmm.c       Wed Jul 06 00:40:28 2022 +0000
+++ b/sys/dev/nvmm/nvmm.c       Wed Jul 06 01:12:45 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nvmm.c,v 1.43 2021/04/12 09:22:58 mrg Exp $    */
+/*     $NetBSD: nvmm.c,v 1.44 2022/07/06 01:12:45 riastradh Exp $      */
 
 /*
  * Copyright (c) 2018-2020 Maxime Villard, m00nbsd.net
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.43 2021/04/12 09:22:58 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm.c,v 1.44 2022/07/06 01:12:45 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1099,6 +1099,8 @@
        nvmm_cpuid_t cpuid;
        int error;
 
+       KASESRT(size > 0);
+
        if (prot & PROT_EXEC)
                return EACCES;
        if (size != PAGE_SIZE)
diff -r 5ea4aa9120d7 -r b8a4f4704c96 sys/external/bsd/drm2/dist/drm/drm_prime.c
--- a/sys/external/bsd/drm2/dist/drm/drm_prime.c        Wed Jul 06 00:40:28 2022 +0000
+++ b/sys/external/bsd/drm2/dist/drm/drm_prime.c        Wed Jul 06 01:12:45 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: drm_prime.c,v 1.19 2021/12/19 11:37:23 riastradh Exp $ */
+/*     $NetBSD: drm_prime.c,v 1.20 2022/07/06 01:12:45 riastradh Exp $ */
 
 /*
  * Copyright © 2012 Red Hat
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_prime.c,v 1.19 2021/12/19 11:37:23 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_prime.c,v 1.20 2022/07/06 01:12:45 riastradh Exp $");
 
 #include <linux/export.h>
 #include <linux/dma-buf.h>
@@ -901,6 +901,7 @@
                goto out;
 
 #ifdef __NetBSD__
+       KASSERT(size > 0);
        ret = obj->dev->driver->mmap_object(obj->dev, *offp, size, prot, uobjp,
            offp, fil);
 #else
@@ -946,6 +947,7 @@
                return -ENOSYS;
 
 #ifdef __NetBSD__
+       KASSERT(size > 0);
        return dev->driver->gem_prime_mmap(obj, offp, size, prot, flagsp,
            advicep, uobjp, maxprotp);
 #else
diff -r 5ea4aa9120d7 -r b8a4f4704c96 sys/external/bsd/drm2/drm/drm_cdevsw.c
--- a/sys/external/bsd/drm2/drm/drm_cdevsw.c    Wed Jul 06 00:40:28 2022 +0000
+++ b/sys/external/bsd/drm2/drm/drm_cdevsw.c    Wed Jul 06 01:12:45 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: drm_cdevsw.c,v 1.29 2021/12/19 12:23:42 riastradh Exp $        */
+/*     $NetBSD: drm_cdevsw.c,v 1.30 2022/07/06 01:12:45 riastradh Exp $        */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_cdevsw.c,v 1.29 2021/12/19 12:23:42 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_cdevsw.c,v 1.30 2022/07/06 01:12:45 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -520,6 +520,8 @@
        int error;
 
        KASSERT(fp == file->filp);
+       KASSERT(len > 0);
+
        /* XXX errno Linux->NetBSD */
        error = -(*dev->driver->mmap_object)(dev, *offp, len, prot, uobjp,
            offp, file->filp);
diff -r 5ea4aa9120d7 -r b8a4f4704c96 sys/external/bsd/drm2/drm/drm_gem_vm.c
--- a/sys/external/bsd/drm2/drm/drm_gem_vm.c    Wed Jul 06 00:40:28 2022 +0000
+++ b/sys/external/bsd/drm2/drm/drm_gem_vm.c    Wed Jul 06 01:12:45 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: drm_gem_vm.c,v 1.14 2021/12/19 09:52:00 riastradh Exp $        */
+/*     $NetBSD: drm_gem_vm.c,v 1.15 2022/07/06 01:12:45 riastradh Exp $        */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_gem_vm.c,v 1.14 2021/12/19 09:52:00 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_gem_vm.c,v 1.15 2022/07/06 01:12:45 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/file.h>
@@ -71,6 +71,8 @@
 {
        int ret;
 
+       KASSERT(nbytes > 0);
+
        ret = drm_gem_mmap_object(dev, byte_offset, nbytes, prot, uobjp,
            uoffsetp, file);
        if (ret)
@@ -88,6 +90,8 @@
 {
        int ret;
 
+       KASSERT(nbytes > 0);
+
        mutex_lock(&dev->struct_mutex);
        ret = drm_gem_mmap_object_locked(dev, byte_offset, nbytes, prot,
            uobjp, uoffsetp, file);
diff -r 5ea4aa9120d7 -r b8a4f4704c96 sys/external/bsd/drm2/drm/drm_vm.c
--- a/sys/external/bsd/drm2/drm/drm_vm.c        Wed Jul 06 00:40:28 2022 +0000
+++ b/sys/external/bsd/drm2/drm/drm_vm.c        Wed Jul 06 01:12:45 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: drm_vm.c,v 1.12 2021/12/19 09:52:59 riastradh Exp $    */
+/*     $NetBSD: drm_vm.c,v 1.13 2022/07/06 01:12:45 riastradh Exp $    */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drm_vm.c,v 1.12 2021/12/19 09:52:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drm_vm.c,v 1.13 2022/07/06 01:12:45 riastradh Exp $");
 
 #include <sys/types.h>
 #include <sys/conf.h>
@@ -60,6 +60,7 @@
        struct uvm_object *uobj;
 
        KASSERT(offset == (offset & ~(PAGE_SIZE-1)));
+       KASSERT(size > 0);
 
        /*
         * Attach the device.  The size and offset are used only for
diff -r 5ea4aa9120d7 -r b8a4f4704c96 sys/kern/kern_ksyms.c
--- a/sys/kern/kern_ksyms.c     Wed Jul 06 00:40:28 2022 +0000
+++ b/sys/kern/kern_ksyms.c     Wed Jul 06 01:12:45 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_ksyms.c,v 1.105 2021/09/22 05:42:19 rin Exp $     */
+/*     $NetBSD: kern_ksyms.c,v 1.106 2022/07/06 01:12:46 riastradh Exp $       */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.105 2021/09/22 05:42:19 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.106 2022/07/06 01:12:46 riastradh Exp $");
 
 #if defined(_KERNEL) && defined(_KERNEL_OPT)
 #include "opt_copy_symtab.h"
@@ -1395,6 +1395,7 @@
        /* uvm_mmap guarantees page-aligned offset and size.  */
        KASSERT(*offp == round_page(*offp));
        KASSERT(nbytes == round_page(nbytes));
+       KASSERT(nbytes > 0);
 
        /* Refuse negative offsets.  */
        if (*offp < 0)
diff -r 5ea4aa9120d7 -r b8a4f4704c96 sys/kern/subr_kcov.c
--- a/sys/kern/subr_kcov.c      Wed Jul 06 00:40:28 2022 +0000
+++ b/sys/kern/subr_kcov.c      Wed Jul 06 01:12:45 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_kcov.c,v 1.16 2020/07/03 16:11:11 maxv Exp $      */
+/*     $NetBSD: subr_kcov.c,v 1.17 2022/07/06 01:12:46 riastradh Exp $ */
 
 /*
  * Copyright (c) 2019-2020 The NetBSD Foundation, Inc.
@@ -524,6 +524,8 @@
        kcov_t *kd, *kdbuf;
        int error = 0;
 
+       KASSERT(size > 0);
+
        if (prot & PROT_EXEC)
                return EACCES;
        if (off < 0)
diff -r 5ea4aa9120d7 -r b8a4f4704c96 sys/kern/vfs_vnops.c
--- a/sys/kern/vfs_vnops.c      Wed Jul 06 00:40:28 2022 +0000
+++ b/sys/kern/vfs_vnops.c      Wed Jul 06 01:12:45 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_vnops.c,v 1.228 2022/05/22 11:27:36 andvar Exp $   */
+/*     $NetBSD: vfs_vnops.c,v 1.229 2022/07/06 01:12:46 riastradh Exp $        */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.228 2022/05/22 11:27:36 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.229 2022/07/06 01:12:46 riastradh Exp $");
 
 #include "veriexec.h"
 
@@ -919,6 +919,8 @@
        flags = *flagsp;
        maxprot = VM_PROT_EXECUTE;
 
+       KASSERT(size > 0);
+
        vp = fp->f_vnode;
        if (vp->v_type != VREG && vp->v_type != VCHR &&
            vp->v_type != VBLK) {
diff -r 5ea4aa9120d7 -r b8a4f4704c96 sys/uvm/uvm_device.c
--- a/sys/uvm/uvm_device.c      Wed Jul 06 00:40:28 2022 +0000
+++ b/sys/uvm/uvm_device.c      Wed Jul 06 01:12:45 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_device.c,v 1.73 2022/03/28 12:39:18 riastradh Exp $        */
+/*     $NetBSD: uvm_device.c,v 1.74 2022/07/06 01:12:46 riastradh Exp $        */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_device.c,v 1.73 2022/03/28 12:39:18 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_device.c,v 1.74 2022/07/06 01:12:46 riastradh Exp $");
 
 #include "opt_uvmhist.h"
 
@@ -117,6 +117,8 @@
        UVMHIST_FUNC(__func__);
        UVMHIST_CALLARGS(maphist, "(device=%#jx)", device,0,0,0);
 
+       KASSERT(size > 0);
+
        /*
         * before we do anything, ensure this device supports mmap
         */
diff -r 5ea4aa9120d7 -r b8a4f4704c96 sys/uvm/uvm_mmap.c
--- a/sys/uvm/uvm_mmap.c        Wed Jul 06 00:40:28 2022 +0000
+++ b/sys/uvm/uvm_mmap.c        Wed Jul 06 01:12:45 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uvm_mmap.c,v 1.182 2022/07/06 00:40:28 riastradh Exp $ */
+/*     $NetBSD: uvm_mmap.c,v 1.183 2022/07/06 01:12:46 riastradh Exp $ */
 
 /*
  * Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -46,7 +46,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_mmap.c,v 1.182 2022/07/06 00:40:28 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_mmap.c,v 1.183 2022/07/06 01:12:46 riastradh Exp $");
 



Home | Main Index | Thread Index | Old Index