Pull up following revision(s) (requested by msaitoh in ticket #1576): sys/net/if.c: revision 1.479 sys/compat/common/uipc_syscalls_40.c: revision 1.23 sys/compat/linux/common/linux_socket.c: revision 1.150 sys/compat/linux32/common/linux32_socket.c: revision 1.31 Don't accept negative value.diff -r1.13.6.3 -r1.13.6.4 src/sys/compat/common/uipc_syscalls_40.c
(martin)
--- src/sys/compat/common/uipc_syscalls_40.c 2019/04/19 09:12:58 1.13.6.3
+++ src/sys/compat/common/uipc_syscalls_40.c 2020/07/17 15:28:07 1.13.6.4
@@ -1,19 +1,19 @@ | @@ -1,19 +1,19 @@ | |||
1 | /* $NetBSD: uipc_syscalls_40.c,v 1.13.6.3 2019/04/19 09:12:58 martin Exp $ */ | 1 | /* $NetBSD: uipc_syscalls_40.c,v 1.13.6.4 2020/07/17 15:28:07 martin Exp $ */ | |
2 | 2 | |||
3 | /* written by Pavel Cahyna, 2006. Public domain. */ | 3 | /* written by Pavel Cahyna, 2006. Public domain. */ | |
4 | 4 | |||
5 | #include <sys/cdefs.h> | 5 | #include <sys/cdefs.h> | |
6 | __KERNEL_RCSID(0, "$NetBSD: uipc_syscalls_40.c,v 1.13.6.3 2019/04/19 09:12:58 martin Exp $"); | 6 | __KERNEL_RCSID(0, "$NetBSD: uipc_syscalls_40.c,v 1.13.6.4 2020/07/17 15:28:07 martin Exp $"); | |
7 | 7 | |||
8 | /* | 8 | /* | |
9 | * System call interface to the socket abstraction. | 9 | * System call interface to the socket abstraction. | |
10 | */ | 10 | */ | |
11 | 11 | |||
12 | #include <sys/param.h> | 12 | #include <sys/param.h> | |
13 | #include <sys/kernel.h> | 13 | #include <sys/kernel.h> | |
14 | #include <sys/msg.h> | 14 | #include <sys/msg.h> | |
15 | #include <sys/sysctl.h> | 15 | #include <sys/sysctl.h> | |
16 | #include <sys/syscallargs.h> | 16 | #include <sys/syscallargs.h> | |
17 | #include <sys/errno.h> | 17 | #include <sys/errno.h> | |
18 | 18 | |||
19 | #include <net/if.h> | 19 | #include <net/if.h> | |
@@ -32,31 +32,34 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_syscall | @@ -32,31 +32,34 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_syscall | |||
32 | int | 32 | int | |
33 | compat_ifconf(u_long cmd, void *data) | 33 | compat_ifconf(u_long cmd, void *data) | |
34 | { | 34 | { | |
35 | struct oifconf *ifc = data; | 35 | struct oifconf *ifc = data; | |
36 | struct ifnet *ifp; | 36 | struct ifnet *ifp; | |
37 | struct oifreq ifr, *ifrp = NULL; | 37 | struct oifreq ifr, *ifrp = NULL; | |
38 | int space = 0, error = 0; | 38 | int space = 0, error = 0; | |
39 | const int sz = (int)sizeof(ifr); | 39 | const int sz = (int)sizeof(ifr); | |
40 | const bool docopy = ifc->ifc_req != NULL; | 40 | const bool docopy = ifc->ifc_req != NULL; | |
41 | int s; | 41 | int s; | |
42 | int bound; | 42 | int bound; | |
43 | struct psref psref; | 43 | struct psref psref; | |
44 | 44 | |||
45 | memset(&ifr, 0, sizeof(ifr)); | |||
46 | if (docopy) { | 45 | if (docopy) { | |
46 | if (ifc->ifc_len < 0) | |||
47 | return EINVAL; | |||
48 | ||||
47 | space = ifc->ifc_len; | 49 | space = ifc->ifc_len; | |
48 | ifrp = ifc->ifc_req; | 50 | ifrp = ifc->ifc_req; | |
49 | } | 51 | } | |
52 | memset(&ifr, 0, sizeof(ifr)); | |||
50 | 53 | |||
51 | bound = curlwp_bind(); | 54 | bound = curlwp_bind(); | |
52 | s = pserialize_read_enter(); | 55 | s = pserialize_read_enter(); | |
53 | IFNET_READER_FOREACH(ifp) { | 56 | IFNET_READER_FOREACH(ifp) { | |
54 | struct ifaddr *ifa; | 57 | struct ifaddr *ifa; | |
55 | 58 | |||
56 | if_acquire(ifp, &psref); | 59 | if_acquire(ifp, &psref); | |
57 | pserialize_read_exit(s); | 60 | pserialize_read_exit(s); | |
58 | 61 | |||
59 | (void)strncpy(ifr.ifr_name, ifp->if_xname, | 62 | (void)strncpy(ifr.ifr_name, ifp->if_xname, | |
60 | sizeof(ifr.ifr_name)); | 63 | sizeof(ifr.ifr_name)); | |
61 | if (ifr.ifr_name[sizeof(ifr.ifr_name) - 1] != '\0') { | 64 | if (ifr.ifr_name[sizeof(ifr.ifr_name) - 1] != '\0') { | |
62 | error = ENAMETOOLONG; | 65 | error = ENAMETOOLONG; |
--- src/sys/compat/linux/common/linux_socket.c 2020/01/21 18:12:54 1.138.6.5
+++ src/sys/compat/linux/common/linux_socket.c 2020/07/17 15:28:08 1.138.6.6
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: linux_socket.c,v 1.138.6.5 2020/01/21 18:12:54 martin Exp $ */ | 1 | /* $NetBSD: linux_socket.c,v 1.138.6.6 2020/07/17 15:28:08 martin Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Frank van der Linden and Eric Haszlakiewicz. | 8 | * by Frank van der Linden and Eric Haszlakiewicz. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -25,27 +25,27 @@ | @@ -25,27 +25,27 @@ | |||
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | /* | 32 | /* | |
33 | * Functions in multiarch: | 33 | * Functions in multiarch: | |
34 | * linux_sys_socketcall : linux_socketcall.c | 34 | * linux_sys_socketcall : linux_socketcall.c | |
35 | */ | 35 | */ | |
36 | 36 | |||
37 | #include <sys/cdefs.h> | 37 | #include <sys/cdefs.h> | |
38 | __KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.138.6.5 2020/01/21 18:12:54 martin Exp $"); | 38 | __KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.138.6.6 2020/07/17 15:28:08 martin Exp $"); | |
39 | 39 | |||
40 | #if defined(_KERNEL_OPT) | 40 | #if defined(_KERNEL_OPT) | |
41 | #include "opt_inet.h" | 41 | #include "opt_inet.h" | |
42 | #endif /* defined(_KERNEL_OPT) */ | 42 | #endif /* defined(_KERNEL_OPT) */ | |
43 | 43 | |||
44 | #include <sys/param.h> | 44 | #include <sys/param.h> | |
45 | #include <sys/kernel.h> | 45 | #include <sys/kernel.h> | |
46 | #include <sys/systm.h> | 46 | #include <sys/systm.h> | |
47 | #include <sys/buf.h> | 47 | #include <sys/buf.h> | |
48 | #include <sys/ioctl.h> | 48 | #include <sys/ioctl.h> | |
49 | #include <sys/tty.h> | 49 | #include <sys/tty.h> | |
50 | #include <sys/file.h> | 50 | #include <sys/file.h> | |
51 | #include <sys/filedesc.h> | 51 | #include <sys/filedesc.h> | |
@@ -1146,32 +1146,35 @@ linux_getifconf(struct lwp *l, register_ | @@ -1146,32 +1146,35 @@ linux_getifconf(struct lwp *l, register_ | |||
1146 | struct sockaddr *sa; | 1146 | struct sockaddr *sa; | |
1147 | struct osockaddr *osa; | 1147 | struct osockaddr *osa; | |
1148 | int space = 0, error; | 1148 | int space = 0, error; | |
1149 | const int sz = (int)sizeof(ifr); | 1149 | const int sz = (int)sizeof(ifr); | |
1150 | bool docopy; | 1150 | bool docopy; | |
1151 | int s; | 1151 | int s; | |
1152 | int bound; | 1152 | int bound; | |
1153 | struct psref psref; | 1153 | struct psref psref; | |
1154 | 1154 | |||
1155 | error = copyin(data, &ifc, sizeof(ifc)); | 1155 | error = copyin(data, &ifc, sizeof(ifc)); | |
1156 | if (error) | 1156 | if (error) | |
1157 | return error; | 1157 | return error; | |
1158 | 1158 | |||
1159 | memset(&ifr, 0, sizeof(ifr)); | |||
1160 | docopy = ifc.ifc_req != NULL; | 1159 | docopy = ifc.ifc_req != NULL; | |
1161 | if (docopy) { | 1160 | if (docopy) { | |
1161 | if (ifc.ifc_len < 0) | |||
1162 | return EINVAL; | |||
1163 | ||||
1162 | space = ifc.ifc_len; | 1164 | space = ifc.ifc_len; | |
1163 | ifrp = ifc.ifc_req; | 1165 | ifrp = ifc.ifc_req; | |
1164 | } | 1166 | } | |
1167 | memset(&ifr, 0, sizeof(ifr)); | |||
1165 | 1168 | |||
1166 | bound = curlwp_bind(); | 1169 | bound = curlwp_bind(); | |
1167 | s = pserialize_read_enter(); | 1170 | s = pserialize_read_enter(); | |
1168 | IFNET_READER_FOREACH(ifp) { | 1171 | IFNET_READER_FOREACH(ifp) { | |
1169 | struct ifaddr *ifa; | 1172 | struct ifaddr *ifa; | |
1170 | if_acquire(ifp, &psref); | 1173 | if_acquire(ifp, &psref); | |
1171 | pserialize_read_exit(s); | 1174 | pserialize_read_exit(s); | |
1172 | 1175 | |||
1173 | (void)strncpy(ifr.ifr_name, ifp->if_xname, | 1176 | (void)strncpy(ifr.ifr_name, ifp->if_xname, | |
1174 | sizeof(ifr.ifr_name)); | 1177 | sizeof(ifr.ifr_name)); | |
1175 | if (ifr.ifr_name[sizeof(ifr.ifr_name) - 1] != '\0') { | 1178 | if (ifr.ifr_name[sizeof(ifr.ifr_name) - 1] != '\0') { | |
1176 | error = ENAMETOOLONG; | 1179 | error = ENAMETOOLONG; | |
1177 | goto release_exit; | 1180 | goto release_exit; |
--- src/sys/compat/linux32/common/linux32_socket.c 2019/04/19 09:12:58 1.27.6.3
+++ src/sys/compat/linux32/common/linux32_socket.c 2020/07/17 15:28:08 1.27.6.4
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: linux32_socket.c,v 1.27.6.3 2019/04/19 09:12:58 martin Exp $ */ | 1 | /* $NetBSD: linux32_socket.c,v 1.27.6.4 2020/07/17 15:28:08 martin Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved. | 4 | * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved. | |
5 | * | 5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | 6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions | 7 | * modification, are permitted provided that the following conditions | |
8 | * are met: | 8 | * are met: | |
9 | * 1. Redistributions of source code must retain the above copyright | 9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | 10 | * notice, this list of conditions and the following disclaimer. | |
11 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. | |
14 | * 3. All advertising materials mentioning features or use of this software | 14 | * 3. All advertising materials mentioning features or use of this software | |
@@ -23,27 +23,27 @@ | @@ -23,27 +23,27 @@ | |||
23 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 23 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS | 24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS | |
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
31 | * POSSIBILITY OF SUCH DAMAGE. | 31 | * POSSIBILITY OF SUCH DAMAGE. | |
32 | */ | 32 | */ | |
33 | 33 | |||
34 | #include <sys/cdefs.h> | 34 | #include <sys/cdefs.h> | |
35 | 35 | |||
36 | __KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.27.6.3 2019/04/19 09:12:58 martin Exp $"); | 36 | __KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.27.6.4 2020/07/17 15:28:08 martin Exp $"); | |
37 | 37 | |||
38 | #include <sys/types.h> | 38 | #include <sys/types.h> | |
39 | #include <sys/param.h> | 39 | #include <sys/param.h> | |
40 | #include <sys/fstypes.h> | 40 | #include <sys/fstypes.h> | |
41 | #include <sys/signal.h> | 41 | #include <sys/signal.h> | |
42 | #include <sys/dirent.h> | 42 | #include <sys/dirent.h> | |
43 | #include <sys/kernel.h> | 43 | #include <sys/kernel.h> | |
44 | #include <sys/fcntl.h> | 44 | #include <sys/fcntl.h> | |
45 | #include <sys/select.h> | 45 | #include <sys/select.h> | |
46 | #include <sys/proc.h> | 46 | #include <sys/proc.h> | |
47 | #include <sys/ucred.h> | 47 | #include <sys/ucred.h> | |
48 | #include <sys/swap.h> | 48 | #include <sys/swap.h> | |
49 | #include <sys/file.h> | 49 | #include <sys/file.h> | |
@@ -421,32 +421,35 @@ linux32_getifconf(struct lwp *l, registe | @@ -421,32 +421,35 @@ linux32_getifconf(struct lwp *l, registe | |||
421 | struct sockaddr *sa; | 421 | struct sockaddr *sa; | |
422 | struct osockaddr *osa; | 422 | struct osockaddr *osa; | |
423 | int space = 0, error; | 423 | int space = 0, error; | |
424 | const int sz = (int)sizeof(ifr); | 424 | const int sz = (int)sizeof(ifr); | |
425 | bool docopy; | 425 | bool docopy; | |
426 | int s; | 426 | int s; | |
427 | int bound; | 427 | int bound; | |
428 | struct psref psref; | 428 | struct psref psref; | |
429 | 429 | |||
430 | error = copyin(data, &ifc, sizeof(ifc)); | 430 | error = copyin(data, &ifc, sizeof(ifc)); | |
431 | if (error) | 431 | if (error) | |
432 | return error; | 432 | return error; | |
433 | 433 | |||
434 | memset(&ifr, 0, sizeof(ifr)); | |||
435 | docopy = NETBSD32PTR64(ifc.ifc_req) != NULL; | 434 | docopy = NETBSD32PTR64(ifc.ifc_req) != NULL; | |
436 | if (docopy) { | 435 | if (docopy) { | |
436 | if (ifc.ifc_len < 0) | |||
437 | return EINVAL; | |||
438 | ||||
437 | space = ifc.ifc_len; | 439 | space = ifc.ifc_len; | |
438 | ifrp = NETBSD32PTR64(ifc.ifc_req); | 440 | ifrp = NETBSD32PTR64(ifc.ifc_req); | |
439 | } | 441 | } | |
442 | memset(&ifr, 0, sizeof(ifr)); | |||
440 | 443 | |||
441 | bound = curlwp_bind(); | 444 | bound = curlwp_bind(); | |
442 | s = pserialize_read_enter(); | 445 | s = pserialize_read_enter(); | |
443 | IFNET_READER_FOREACH(ifp) { | 446 | IFNET_READER_FOREACH(ifp) { | |
444 | struct ifaddr *ifa; | 447 | struct ifaddr *ifa; | |
445 | if_acquire(ifp, &psref); | 448 | if_acquire(ifp, &psref); | |
446 | pserialize_read_exit(s); | 449 | pserialize_read_exit(s); | |
447 | 450 | |||
448 | (void)strncpy(ifr.ifr_name, ifp->if_xname, | 451 | (void)strncpy(ifr.ifr_name, ifp->if_xname, | |
449 | sizeof(ifr.ifr_name)); | 452 | sizeof(ifr.ifr_name)); | |
450 | if (ifr.ifr_name[sizeof(ifr.ifr_name) - 1] != '\0') { | 453 | if (ifr.ifr_name[sizeof(ifr.ifr_name) - 1] != '\0') { | |
451 | error = ENAMETOOLONG; | 454 | error = ENAMETOOLONG; | |
452 | goto release_exit; | 455 | goto release_exit; |
--- src/sys/net/if.c 2019/09/24 18:27:09 1.394.2.18
+++ src/sys/net/if.c 2020/07/17 15:28:07 1.394.2.19
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: if.c,v 1.394.2.18 2019/09/24 18:27:09 martin Exp $ */ | 1 | /* $NetBSD: if.c,v 1.394.2.19 2020/07/17 15:28:07 martin Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by William Studenmund and Jason R. Thorpe. | 8 | * by William Studenmund and Jason R. Thorpe. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -80,27 +80,27 @@ | @@ -80,27 +80,27 @@ | |||
80 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 80 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
81 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 81 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
82 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 82 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
83 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 83 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
84 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 84 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
85 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 85 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
86 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 86 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
87 | * SUCH DAMAGE. | 87 | * SUCH DAMAGE. | |
88 | * | 88 | * | |
89 | * @(#)if.c 8.5 (Berkeley) 1/9/95 | 89 | * @(#)if.c 8.5 (Berkeley) 1/9/95 | |
90 | */ | 90 | */ | |
91 | 91 | |||
92 | #include <sys/cdefs.h> | 92 | #include <sys/cdefs.h> | |
93 | __KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.18 2019/09/24 18:27:09 martin Exp $"); | 93 | __KERNEL_RCSID(0, "$NetBSD: if.c,v 1.394.2.19 2020/07/17 15:28:07 martin Exp $"); | |
94 | 94 | |||
95 | #if defined(_KERNEL_OPT) | 95 | #if defined(_KERNEL_OPT) | |
96 | #include "opt_inet.h" | 96 | #include "opt_inet.h" | |
97 | #include "opt_ipsec.h" | 97 | #include "opt_ipsec.h" | |
98 | #include "opt_atalk.h" | 98 | #include "opt_atalk.h" | |
99 | #include "opt_natm.h" | 99 | #include "opt_natm.h" | |
100 | #include "opt_wlan.h" | 100 | #include "opt_wlan.h" | |
101 | #include "opt_net_mpsafe.h" | 101 | #include "opt_net_mpsafe.h" | |
102 | #include "opt_mrouting.h" | 102 | #include "opt_mrouting.h" | |
103 | #endif | 103 | #endif | |
104 | 104 | |||
105 | #include <sys/param.h> | 105 | #include <sys/param.h> | |
106 | #include <sys/mbuf.h> | 106 | #include <sys/mbuf.h> | |
@@ -3382,31 +3382,34 @@ static int | @@ -3382,31 +3382,34 @@ static int | |||
3382 | ifconf(u_long cmd, void *data) | 3382 | ifconf(u_long cmd, void *data) | |
3383 | { | 3383 | { | |
3384 | struct ifconf *ifc = (struct ifconf *)data; | 3384 | struct ifconf *ifc = (struct ifconf *)data; | |
3385 | struct ifnet *ifp; | 3385 | struct ifnet *ifp; | |
3386 | struct ifaddr *ifa; | 3386 | struct ifaddr *ifa; | |
3387 | struct ifreq ifr, *ifrp = NULL; | 3387 | struct ifreq ifr, *ifrp = NULL; | |
3388 | int space = 0, error = 0; | 3388 | int space = 0, error = 0; | |
3389 | const int sz = (int)sizeof(struct ifreq); | 3389 | const int sz = (int)sizeof(struct ifreq); | |
3390 | const bool docopy = ifc->ifc_req != NULL; | 3390 | const bool docopy = ifc->ifc_req != NULL; | |
3391 | int s; | 3391 | int s; | |
3392 | int bound; | 3392 | int bound; | |
3393 | struct psref psref; | 3393 | struct psref psref; | |
3394 | 3394 | |||
3395 | memset(&ifr, 0, sizeof(ifr)); | |||
3396 | if (docopy) { | 3395 | if (docopy) { | |
3396 | if (ifc->ifc_len < 0) | |||
3397 | return EINVAL; | |||
3398 | ||||
3397 | space = ifc->ifc_len; | 3399 | space = ifc->ifc_len; | |
3398 | ifrp = ifc->ifc_req; | 3400 | ifrp = ifc->ifc_req; | |
3399 | } | 3401 | } | |
3402 | memset(&ifr, 0, sizeof(ifr)); | |||
3400 | 3403 | |||
3401 | bound = curlwp_bind(); | 3404 | bound = curlwp_bind(); | |
3402 | s = pserialize_read_enter(); | 3405 | s = pserialize_read_enter(); | |
3403 | IFNET_READER_FOREACH(ifp) { | 3406 | IFNET_READER_FOREACH(ifp) { | |
3404 | psref_acquire(&psref, &ifp->if_psref, ifnet_psref_class); | 3407 | psref_acquire(&psref, &ifp->if_psref, ifnet_psref_class); | |
3405 | pserialize_read_exit(s); | 3408 | pserialize_read_exit(s); | |
3406 | 3409 | |||
3407 | (void)strncpy(ifr.ifr_name, ifp->if_xname, | 3410 | (void)strncpy(ifr.ifr_name, ifp->if_xname, | |
3408 | sizeof(ifr.ifr_name)); | 3411 | sizeof(ifr.ifr_name)); | |
3409 | if (ifr.ifr_name[sizeof(ifr.ifr_name) - 1] != '\0') { | 3412 | if (ifr.ifr_name[sizeof(ifr.ifr_name) - 1] != '\0') { | |
3410 | error = ENAMETOOLONG; | 3413 | error = ENAMETOOLONG; | |
3411 | goto release_exit; | 3414 | goto release_exit; | |
3412 | } | 3415 | } |