Module Name: src Committed By: ozaki-r Date: Fri Jan 20 08:35:33 UTC 2017
Modified Files: src/sys/net: if.c src/sys/rump/net/lib/libnetinet: netinet_component.c src/tests/net/if: t_ifconfig.sh Log Message: Protect if_clone data with if_clone_mtx To this end, carpattach needs to be delayed from RUMP_COMPONENT_NET to RUMP_COMPONENT_NET_IF on rump_server. Otherwise mutex_enter via carpattach for if_clone_mtx is called before mutex_init for it in ifinit1. To generate a diff of this commit: cvs rdiff -u -r1.371 -r1.372 src/sys/net/if.c cvs rdiff -u -r1.7 -r1.8 src/sys/rump/net/lib/libnetinet/netinet_component.c cvs rdiff -u -r1.14 -r1.15 src/tests/net/if/t_ifconfig.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/net/if.c diff -u src/sys/net/if.c:1.371 src/sys/net/if.c:1.372 --- src/sys/net/if.c:1.371 Tue Jan 10 08:45:45 2017 +++ src/sys/net/if.c Fri Jan 20 08:35:33 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: if.c,v 1.371 2017/01/10 08:45:45 ozaki-r Exp $ */ +/* $NetBSD: if.c,v 1.372 2017/01/20 08:35:33 ozaki-r 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.371 2017/01/10 08:45:45 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.372 2017/01/20 08:35:33 ozaki-r Exp $"); #if defined(_KERNEL_OPT) #include "opt_inet.h" @@ -1537,6 +1537,8 @@ if_clone_create(const char *name) struct ifnet *ifp; struct psref psref; + KASSERT(mutex_owned(&if_clone_mtx)); + ifc = if_clone_lookup(name, &unit); if (ifc == NULL) return EINVAL; @@ -1560,6 +1562,8 @@ if_clone_destroy(const char *name) struct ifnet *ifp; struct psref psref; + KASSERT(mutex_owned(&if_clone_mtx)); + ifc = if_clone_lookup(name, NULL); if (ifc == NULL) return EINVAL; @@ -1596,6 +1600,8 @@ if_clone_lookup(const char *name, int *u char *dp, ifname[IFNAMSIZ + 3]; int unit; + KASSERT(mutex_owned(&if_clone_mtx)); + strcpy(ifname, "if_"); /* separate interface name from unit */ for (dp = ifname + 3, cp = name; cp - name < IFNAMSIZ && @@ -1641,8 +1647,10 @@ void if_clone_attach(struct if_clone *ifc) { + mutex_enter(&if_clone_mtx); LIST_INSERT_HEAD(&if_cloners, ifc, ifc_list); if_cloners_count++; + mutex_exit(&if_clone_mtx); } /* @@ -1652,6 +1660,7 @@ void if_clone_detach(struct if_clone *ifc) { + KASSERT(mutex_owned(&if_clone_mtx)); LIST_REMOVE(ifc, ifc_list); if_cloners_count--; } @@ -1666,14 +1675,17 @@ if_clone_list(int buf_count, char *buffe struct if_clone *ifc; int count, error = 0; + mutex_enter(&if_clone_mtx); *total = if_cloners_count; if ((dst = buffer) == NULL) { /* Just asking how many there are. */ - return 0; + goto out; } - if (buf_count < 0) - return EINVAL; + if (buf_count < 0) { + error = EINVAL; + goto out; + } count = (if_cloners_count < buf_count) ? if_cloners_count : buf_count; @@ -1681,13 +1693,17 @@ if_clone_list(int buf_count, char *buffe for (ifc = LIST_FIRST(&if_cloners); ifc != NULL && count != 0; ifc = LIST_NEXT(ifc, ifc_list), count--, dst += IFNAMSIZ) { (void)strncpy(outbuf, ifc->ifc_name, sizeof(outbuf)); - if (outbuf[sizeof(outbuf) - 1] != '\0') - return ENAMETOOLONG; + if (outbuf[sizeof(outbuf) - 1] != '\0') { + error = ENAMETOOLONG; + goto out; + } error = copyout(outbuf, dst, sizeof(outbuf)); if (error != 0) break; } +out: + mutex_exit(&if_clone_mtx); return error; } Index: src/sys/rump/net/lib/libnetinet/netinet_component.c diff -u src/sys/rump/net/lib/libnetinet/netinet_component.c:1.7 src/sys/rump/net/lib/libnetinet/netinet_component.c:1.8 --- src/sys/rump/net/lib/libnetinet/netinet_component.c:1.7 Sat Aug 13 11:19:35 2016 +++ src/sys/rump/net/lib/libnetinet/netinet_component.c Fri Jan 20 08:35:33 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: netinet_component.c,v 1.7 2016/08/13 11:19:35 christos Exp $ */ +/* $NetBSD: netinet_component.c,v 1.8 2017/01/20 08:35:33 ozaki-r Exp $ */ /* * Copyright (c) 2009 Antti Kantee. All Rights Reserved. @@ -28,7 +28,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: netinet_component.c,v 1.7 2016/08/13 11:19:35 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: netinet_component.c,v 1.8 2017/01/20 08:35:33 ozaki-r Exp $"); #include <sys/param.h> #include <sys/domain.h> @@ -45,8 +45,6 @@ __KERNEL_RCSID(0, "$NetBSD: netinet_comp #include <rump-sys/kern.h> #include <rump-sys/net.h> -int carpattach(int); - RUMP_COMPONENT(RUMP_COMPONENT_NET) { extern struct domain arpdomain, inetdomain; @@ -54,11 +52,17 @@ RUMP_COMPONENT(RUMP_COMPONENT_NET) domain_attach(&arpdomain); domain_attach(&inetdomain); - carpattach(1); - rump_netisr_register(NETISR_ARP, arpintr); } +int carpattach(int); + +RUMP_COMPONENT(RUMP_COMPONENT_NET_IF) +{ + + carpattach(1); +} + RUMP_COMPONENT(RUMP_COMPONENT_NET_IFCFG) { struct ifaliasreq ia; Index: src/tests/net/if/t_ifconfig.sh diff -u src/tests/net/if/t_ifconfig.sh:1.14 src/tests/net/if/t_ifconfig.sh:1.15 --- src/tests/net/if/t_ifconfig.sh:1.14 Sat Oct 1 22:15:04 2016 +++ src/tests/net/if/t_ifconfig.sh Fri Jan 20 08:35:33 2017 @@ -1,4 +1,4 @@ -# $NetBSD: t_ifconfig.sh,v 1.14 2016/10/01 22:15:04 kre Exp $ +# $NetBSD: t_ifconfig.sh,v 1.15 2017/01/20 08:35:33 ozaki-r Exp $ # # Copyright (c) 2015 The NetBSD Foundation, Inc. # All rights reserved. @@ -181,7 +181,7 @@ ifconfig_options_body() # ifconfig -C # -C shows all of the interface cloners available on the system - atf_check -s exit:0 -o match:'shmif lo carp' rump.ifconfig -C + atf_check -s exit:0 -o match:'shmif carp lo' rump.ifconfig -C unset RUMP_SERVER }