Source-Changes-HG archive

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

[src/trunk]: src/sys/net Don't accept negative value.



details:   https://anonhg.NetBSD.org/src/rev/124f3943487d
branches:  trunk
changeset: 936037:124f3943487d
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Thu Jul 16 15:02:08 2020 +0000

description:
Don't accept negative value.

Reported-by: syzbot+e71a77402d6668f1868d%syzkaller.appspotmail.com@localhost

diffstat:

 sys/compat/common/uipc_syscalls_40.c       |  9 ++++++---
 sys/compat/linux/common/linux_socket.c     |  9 ++++++---
 sys/compat/linux32/common/linux32_socket.c |  9 ++++++---
 sys/net/if.c                               |  9 ++++++---
 4 files changed, 24 insertions(+), 12 deletions(-)

diffs (135 lines):

diff -r 276f62c21629 -r 124f3943487d sys/compat/common/uipc_syscalls_40.c
--- a/sys/compat/common/uipc_syscalls_40.c      Thu Jul 16 14:57:59 2020 +0000
+++ b/sys/compat/common/uipc_syscalls_40.c      Thu Jul 16 15:02:08 2020 +0000
@@ -1,9 +1,9 @@
-/*     $NetBSD: uipc_syscalls_40.c,v 1.22 2020/02/22 09:42:20 maxv Exp $       */
+/*     $NetBSD: uipc_syscalls_40.c,v 1.23 2020/07/16 15:02:08 msaitoh Exp $    */
 
 /* written by Pavel Cahyna, 2006. Public domain. */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls_40.c,v 1.22 2020/02/22 09:42:20 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls_40.c,v 1.23 2020/07/16 15:02:08 msaitoh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_compat_netbsd.h"
@@ -54,11 +54,14 @@
                return ENOSYS;
        }
 
-       memset(&ifr, 0, sizeof(ifr));
        if (docopy) {
+               if (ifc->ifc_len < 0)
+                       return EINVAL;
+
                space = ifc->ifc_len;
                ifrp = ifc->ifc_req;
        }
+       memset(&ifr, 0, sizeof(ifr));
 
        bound = curlwp_bind();
        s = pserialize_read_enter();
diff -r 276f62c21629 -r 124f3943487d sys/compat/linux/common/linux_socket.c
--- a/sys/compat/linux/common/linux_socket.c    Thu Jul 16 14:57:59 2020 +0000
+++ b/sys/compat/linux/common/linux_socket.c    Thu Jul 16 15:02:08 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux_socket.c,v 1.149 2019/09/08 18:46:32 maxv Exp $  */
+/*     $NetBSD: linux_socket.c,v 1.150 2020/07/16 15:02:08 msaitoh Exp $       */
 
 /*-
  * Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.149 2019/09/08 18:46:32 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.150 2020/07/16 15:02:08 msaitoh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1140,12 +1140,15 @@
        if (error)
                return error;
 
-       memset(&ifr, 0, sizeof(ifr));
        docopy = ifc.ifc_req != NULL;
        if (docopy) {
+               if (ifc.ifc_len < 0)
+                       return EINVAL;
+
                space = ifc.ifc_len;
                ifrp = ifc.ifc_req;
        }
+       memset(&ifr, 0, sizeof(ifr));
 
        bound = curlwp_bind();
        s = pserialize_read_enter();
diff -r 276f62c21629 -r 124f3943487d sys/compat/linux32/common/linux32_socket.c
--- a/sys/compat/linux32/common/linux32_socket.c        Thu Jul 16 14:57:59 2020 +0000
+++ b/sys/compat/linux32/common/linux32_socket.c        Thu Jul 16 15:02:08 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: linux32_socket.c,v 1.30 2019/04/18 17:45:12 christos Exp $ */
+/*     $NetBSD: linux32_socket.c,v 1.31 2020/07/16 15:02:08 msaitoh Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.30 2019/04/18 17:45:12 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.31 2020/07/16 15:02:08 msaitoh Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -431,12 +431,15 @@
        if (error)
                return error;
 
-       memset(&ifr, 0, sizeof(ifr));
        docopy = NETBSD32PTR64(ifc.ifc_req) != NULL;
        if (docopy) {
+               if (ifc.ifc_len < 0)
+                       return EINVAL;
+
                space = ifc.ifc_len;
                ifrp = NETBSD32PTR64(ifc.ifc_req);
        }
+       memset(&ifr, 0, sizeof(ifr));
 
        bound = curlwp_bind();
        s = pserialize_read_enter();
diff -r 276f62c21629 -r 124f3943487d sys/net/if.c
--- a/sys/net/if.c      Thu Jul 16 14:57:59 2020 +0000
+++ b/sys/net/if.c      Thu Jul 16 15:02:08 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.478 2020/06/12 11:04:45 roy Exp $     */
+/*     $NetBSD: if.c,v 1.479 2020/07/16 15:02:08 msaitoh Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.478 2020/06/12 11:04:45 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.479 2020/07/16 15:02:08 msaitoh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -3484,11 +3484,14 @@
        int bound;
        struct psref psref;
 
-       memset(&ifr, 0, sizeof(ifr));
        if (docopy) {
+               if (ifc->ifc_len < 0)
+                       return EINVAL;
+
                space = ifc->ifc_len;
                ifrp = ifc->ifc_req;
        }
+       memset(&ifr, 0, sizeof(ifr));
 
        bound = curlwp_bind();
        s = pserialize_read_enter();



Home | Main Index | Thread Index | Old Index