Source-Changes-HG archive

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

[src/trunk]: src/sys/kern mmap(2): Avoid overflow in overflow check in vn_mmap.



details:   https://anonhg.NetBSD.org/src/rev/0fa20c247299
branches:  trunk
changeset: 368340:0fa20c247299
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Wed Jul 06 01:13:06 2022 +0000

description:
mmap(2): Avoid overflow in overflow check in vn_mmap.

diffstat:

 sys/kern/vfs_vnops.c |  7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diffs (28 lines):

diff -r b8a4f4704c96 -r 0fa20c247299 sys/kern/vfs_vnops.c
--- a/sys/kern/vfs_vnops.c      Wed Jul 06 01:12:45 2022 +0000
+++ b/sys/kern/vfs_vnops.c      Wed Jul 06 01:13:06 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_vnops.c,v 1.229 2022/07/06 01:12:46 riastradh Exp $        */
+/*     $NetBSD: vfs_vnops.c,v 1.230 2022/07/06 01:13:06 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.229 2022/07/06 01:12:46 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.230 2022/07/06 01:13:06 riastradh Exp $");
 
 #include "veriexec.h"
 
@@ -930,7 +930,8 @@
        if (vp->v_type != VCHR && off < 0) {
                return EINVAL;
        }
-       if (vp->v_type != VCHR && (off_t)(off + size) < off) {
+       if (vp->v_type != VCHR &&
+           (size > __type_max(off_t) || off > __type_max(off_t) - size)) {
                /* no offset wrapping */
                return EOVERFLOW;
        }



Home | Main Index | Thread Index | Old Index