Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Protect if_clone data with if_clone_mtx
details: https://anonhg.NetBSD.org/src/rev/52b81f17dcab
branches: trunk
changeset: 350763:52b81f17dcab
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Fri Jan 20 08:35:33 2017 +0000
description:
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.
diffstat:
sys/net/if.c | 30 +++++++++++++++++++-----
sys/rump/net/lib/libnetinet/netinet_component.c | 16 ++++++++-----
tests/net/if/t_ifconfig.sh | 4 +-
3 files changed, 35 insertions(+), 15 deletions(-)
diffs (168 lines):
diff -r 8eef85f46e4f -r 52b81f17dcab sys/net/if.c
--- a/sys/net/if.c Fri Jan 20 08:16:31 2017 +0000
+++ b/sys/net/if.c Fri Jan 20 08:35:33 2017 +0000
@@ -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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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;
}
diff -r 8eef85f46e4f -r 52b81f17dcab sys/rump/net/lib/libnetinet/netinet_component.c
--- a/sys/rump/net/lib/libnetinet/netinet_component.c Fri Jan 20 08:16:31 2017 +0000
+++ b/sys/rump/net/lib/libnetinet/netinet_component.c Fri Jan 20 08:35:33 2017 +0000
@@ -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 @@
#include <rump-sys/kern.h>
#include <rump-sys/net.h>
-int carpattach(int);
-
RUMP_COMPONENT(RUMP_COMPONENT_NET)
{
extern struct domain arpdomain, inetdomain;
@@ -54,9 +52,15 @@
domain_attach(&arpdomain);
domain_attach(&inetdomain);
- carpattach(1);
+ rump_netisr_register(NETISR_ARP, arpintr);
+}
+
+int carpattach(int);
- rump_netisr_register(NETISR_ARP, arpintr);
+RUMP_COMPONENT(RUMP_COMPONENT_NET_IF)
+{
+
+ carpattach(1);
}
RUMP_COMPONENT(RUMP_COMPONENT_NET_IFCFG)
diff -r 8eef85f46e4f -r 52b81f17dcab tests/net/if/t_ifconfig.sh
--- a/tests/net/if/t_ifconfig.sh Fri Jan 20 08:16:31 2017 +0000
+++ b/tests/net/if/t_ifconfig.sh Fri Jan 20 08:35:33 2017 +0000
@@ -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 -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
}
Home |
Main Index |
Thread Index |
Old Index