Module Name: src Committed By: bouyer Date: Tue May 13 19:36:16 UTC 2014
Modified Files: src/sys/external/bsd/ipf/netinet: ip_fil_netbsd.c src/sys/net: if_ethersubr.c if_loop.c if_vlan.c src/sys/netinet: ip_carp.c Log Message: Make sure *(if_output)() is called with KERNEL_LOCK held. Add some KASSERT for this. See http://mail-index.netbsd.org/tech-net/2014/04/09/msg004511.html for details. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/sys/external/bsd/ipf/netinet/ip_fil_netbsd.c cvs rdiff -u -r1.196 -r1.197 src/sys/net/if_ethersubr.c cvs rdiff -u -r1.76 -r1.77 src/sys/net/if_loop.c cvs rdiff -u -r1.69 -r1.70 src/sys/net/if_vlan.c cvs rdiff -u -r1.53 -r1.54 src/sys/netinet/ip_carp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/external/bsd/ipf/netinet/ip_fil_netbsd.c diff -u src/sys/external/bsd/ipf/netinet/ip_fil_netbsd.c:1.8 src/sys/external/bsd/ipf/netinet/ip_fil_netbsd.c:1.9 --- src/sys/external/bsd/ipf/netinet/ip_fil_netbsd.c:1.8 Sun Mar 16 05:20:30 2014 +++ src/sys/external/bsd/ipf/netinet/ip_fil_netbsd.c Tue May 13 19:36:16 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: ip_fil_netbsd.c,v 1.8 2014/03/16 05:20:30 dholland Exp $ */ +/* $NetBSD: ip_fil_netbsd.c,v 1.9 2014/05/13 19:36:16 bouyer Exp $ */ /* * Copyright (C) 2012 by Darren Reed. @@ -8,7 +8,7 @@ #if !defined(lint) #if defined(__NetBSD__) #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ip_fil_netbsd.c,v 1.8 2014/03/16 05:20:30 dholland Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip_fil_netbsd.c,v 1.9 2014/05/13 19:36:16 bouyer Exp $"); #else static const char sccsid[] = "@(#)ip_fil.c 2.41 6/5/96 (C) 1993-2000 Darren Reed"; static const char rcsid[] = "@(#)Id: ip_fil_netbsd.c,v 1.1.1.2 2012/07/22 13:45:17 darrenr Exp"; @@ -1209,7 +1209,9 @@ ipf_fastroute(mb_t *m0, mb_t **mpp, fr_i ip->ip_sum = in_cksum(m, hlen); # endif /* M_CSUM_IPv4 */ + KERNEL_LOCK(1, NULL); error = (*ifp->if_output)(ifp, m, dst, rt); + KERNEL_UNLOCK_ONE(NULL); goto done; } @@ -1296,7 +1298,9 @@ sendorfree: m0 = m->m_act; m->m_act = 0; if (error == 0) { + KERNEL_LOCK(1, NULL); error = (*ifp->if_output)(ifp, m, dst, rt); + KERNEL_UNLOCK_ONE(NULL); } else { FREE_MB_T(m); } Index: src/sys/net/if_ethersubr.c diff -u src/sys/net/if_ethersubr.c:1.196 src/sys/net/if_ethersubr.c:1.197 --- src/sys/net/if_ethersubr.c:1.196 Tue Feb 25 22:42:06 2014 +++ src/sys/net/if_ethersubr.c Tue May 13 19:36:16 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: if_ethersubr.c,v 1.196 2014/02/25 22:42:06 pooka Exp $ */ +/* $NetBSD: if_ethersubr.c,v 1.197 2014/05/13 19:36:16 bouyer Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -61,7 +61,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.196 2014/02/25 22:42:06 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.197 2014/05/13 19:36:16 bouyer Exp $"); #include "opt_inet.h" #include "opt_atalk.h" @@ -211,6 +211,8 @@ ether_output(struct ifnet * const ifp0, struct at_ifaddr *aa; #endif /* NETATALK */ + KASSERT(KERNEL_LOCKED_P()); + #ifdef MBUFTRACE m_claimm(m, ifp->if_mowner); #endif Index: src/sys/net/if_loop.c diff -u src/sys/net/if_loop.c:1.76 src/sys/net/if_loop.c:1.77 --- src/sys/net/if_loop.c:1.76 Fri Mar 1 18:25:56 2013 +++ src/sys/net/if_loop.c Tue May 13 19:36:16 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: if_loop.c,v 1.76 2013/03/01 18:25:56 joerg Exp $ */ +/* $NetBSD: if_loop.c,v 1.77 2014/05/13 19:36:16 bouyer Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -65,7 +65,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.76 2013/03/01 18:25:56 joerg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.77 2014/05/13 19:36:16 bouyer Exp $"); #include "opt_inet.h" #include "opt_atalk.h" @@ -216,6 +216,8 @@ looutput(struct ifnet *ifp, struct mbuf int csum_flags; MCLAIM(m, ifp->if_mowner); + KASSERT(KERNEL_LOCKED_P()); + if ((m->m_flags & M_PKTHDR) == 0) panic("looutput: no header mbuf"); if (ifp->if_flags & IFF_LOOPBACK) Index: src/sys/net/if_vlan.c diff -u src/sys/net/if_vlan.c:1.69 src/sys/net/if_vlan.c:1.70 --- src/sys/net/if_vlan.c:1.69 Wed Oct 19 22:07:09 2011 +++ src/sys/net/if_vlan.c Tue May 13 19:36:16 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: if_vlan.c,v 1.69 2011/10/19 22:07:09 dyoung Exp $ */ +/* $NetBSD: if_vlan.c,v 1.70 2014/05/13 19:36:16 bouyer Exp $ */ /*- * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc. @@ -78,7 +78,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.69 2011/10/19 22:07:09 dyoung Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.70 2014/05/13 19:36:16 bouyer Exp $"); #include "opt_inet.h" @@ -681,6 +681,8 @@ vlan_start(struct ifnet *ifp) int error; ALTQ_DECL(struct altq_pktattr pktattr;) + KASSERT(KERNEL_LOCKED_P()); + ifp->if_flags |= IFF_OACTIVE; for (;;) { Index: src/sys/netinet/ip_carp.c diff -u src/sys/netinet/ip_carp.c:1.53 src/sys/netinet/ip_carp.c:1.54 --- src/sys/netinet/ip_carp.c:1.53 Fri Apr 4 12:53:04 2014 +++ src/sys/netinet/ip_carp.c Tue May 13 19:36:16 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: ip_carp.c,v 1.53 2014/04/04 12:53:04 bouyer Exp $ */ +/* $NetBSD: ip_carp.c,v 1.54 2014/05/13 19:36:16 bouyer Exp $ */ /* $OpenBSD: ip_carp.c,v 1.113 2005/11/04 08:11:54 mcbride Exp $ */ /* @@ -31,7 +31,7 @@ #include "opt_mbuftrace.h" #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.53 2014/04/04 12:53:04 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip_carp.c,v 1.54 2014/05/13 19:36:16 bouyer Exp $"); /* * TODO: @@ -355,6 +355,7 @@ carp_setroute(struct carp_softc *sc, int struct ifaddr *ifa; int s; + KERNEL_LOCK(1, NULL); s = splsoftnet(); IFADDR_FOREACH(ifa, &sc->sc_if) { switch (ifa->ifa_addr->sa_family) { @@ -452,6 +453,7 @@ carp_setroute(struct carp_softc *sc, int } } splx(s); + KERNEL_UNLOCK_ONE(NULL); } /* @@ -866,6 +868,7 @@ carpdetach(struct carp_softc *sc) carp_setrun(sc, 0); carp_multicast_cleanup(sc); + KERNEL_LOCK(1, NULL); s = splnet(); if (sc->sc_carpdev != NULL) { /* XXX linkstatehook removal */ @@ -879,6 +882,7 @@ carpdetach(struct carp_softc *sc) } sc->sc_carpdev = NULL; splx(s); + KERNEL_UNLOCK_ONE(NULL); } /* Detach an interface from the carp. */ @@ -945,6 +949,7 @@ carp_send_ad(void *v) struct ifaddr *ifa; struct sockaddr sa; + KERNEL_LOCK(1, NULL); s = splsoftnet(); advbase = advskew = 0; /* Sssssh compiler */ @@ -1147,6 +1152,7 @@ carp_send_ad(void *v) retry_later: splx(s); + KERNEL_UNLOCK_ONE(NULL); if (advbase != 255 || advskew != 255) callout_schedule(&sc->sc_ad_tmo, tvtohz(&tv)); } @@ -1161,8 +1167,10 @@ carp_send_arp(struct carp_softc *sc) { struct ifaddr *ifa; struct in_addr *in; - int s = splsoftnet(); + int s; + KERNEL_LOCK(1, NULL); + s = splsoftnet(); IFADDR_FOREACH(ifa, &sc->sc_if) { if (ifa->ifa_addr->sa_family != AF_INET) @@ -1172,6 +1180,7 @@ carp_send_arp(struct carp_softc *sc) arprequest(sc->sc_carpdev, in, in, CLLADDR(sc->sc_if.if_sadl)); } splx(s); + KERNEL_UNLOCK_ONE(NULL); } #ifdef INET6 @@ -1181,7 +1190,10 @@ carp_send_na(struct carp_softc *sc) struct ifaddr *ifa; struct in6_addr *in6; static struct in6_addr mcast = IN6ADDR_LINKLOCAL_ALLNODES_INIT; - int s = splsoftnet(); + int s; + + KERNEL_LOCK(1, NULL); + s = splsoftnet(); IFADDR_FOREACH(ifa, &sc->sc_if) { @@ -1193,6 +1205,7 @@ carp_send_na(struct carp_softc *sc) ND_NA_FLAG_OVERRIDE, 1, NULL); } splx(s); + KERNEL_UNLOCK_ONE(NULL); } #endif /* INET6 */ @@ -1605,10 +1618,12 @@ carp_set_ifp(struct carp_softc *sc, stru if (sc->sc_naddrs || sc->sc_naddrs6) sc->sc_if.if_flags |= IFF_UP; carp_set_enaddr(sc); + KERNEL_LOCK(1, NULL); s = splnet(); /* XXX linkstatehooks establish */ carp_carpdev_state(ifp); splx(s); + KERNEL_UNLOCK_ONE(NULL); } else { carpdetach(sc); sc->sc_if.if_flags &= ~(IFF_UP|IFF_RUNNING); @@ -2072,6 +2087,7 @@ carp_output(struct ifnet *ifp, struct mb struct rtentry *rt) { struct carp_softc *sc = ((struct carp_softc *)ifp->if_softc); + KASSERT(KERNEL_LOCKED_P()); if (sc->sc_carpdev != NULL && sc->sc_state == MASTER) { return (sc->sc_carpdev->if_output(ifp, m, sa, rt));