Date: Mon, 4 Apr 2011 07:45:09 +0000 (UTC) From: Gleb Smirnoff <glebius@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r220317 - head/sys/net Message-ID: <201104040745.p347j9IW074920@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: glebius Date: Mon Apr 4 07:45:08 2011 New Revision: 220317 URL: http://svn.freebsd.org/changeset/base/220317 Log: When removing ifnets, we should first remove the reference to ifnet from the interface index, then decrease refcount, not vice versa. Otherwise there is a race (reproducible) when if_free_internal() contests on IFNET_WLOCK(), and we got a zero-refed ifnet in the index for a long time. It may be picked by some other thread, that runs ifnet_byindex_ref(), who takes the ifnet from index, and bumps refcount. When reader drops the lock, if_free_internal() proceeds with free. Then reader tries to free it a second time. Modified: head/sys/net/if.c Modified: head/sys/net/if.c ============================================================================== --- head/sys/net/if.c Mon Apr 4 03:43:13 2011 (r220316) +++ head/sys/net/if.c Mon Apr 4 07:45:08 2011 (r220317) @@ -465,8 +465,8 @@ if_alloc(u_char type) } /* - * Do the actual work of freeing a struct ifnet, associated index, and layer - * 2 common structure. This call is made when the last reference to an + * Do the actual work of freeing a struct ifnet, and layer 2 common + * structure. This call is made when the last reference to an * interface is released. */ static void @@ -476,13 +476,6 @@ if_free_internal(struct ifnet *ifp) KASSERT((ifp->if_flags & IFF_DYING), ("if_free_internal: interface not dying")); - IFNET_WLOCK(); - KASSERT(ifp == ifnet_byindex_locked(ifp->if_index), - ("%s: freeing unallocated ifnet", ifp->if_xname)); - - ifindex_free_locked(ifp->if_index); - IFNET_WUNLOCK(); - if (if_com_free[ifp->if_alloctype] != NULL) if_com_free[ifp->if_alloctype](ifp->if_l2com, ifp->if_alloctype); @@ -513,6 +506,14 @@ if_free_type(struct ifnet *ifp, u_char t ifp->if_alloctype)); ifp->if_flags |= IFF_DYING; /* XXX: Locking */ + + IFNET_WLOCK(); + KASSERT(ifp == ifnet_byindex_locked(ifp->if_index), + ("%s: freeing unallocated ifnet", ifp->if_xname)); + + ifindex_free_locked(ifp->if_index); + IFNET_WUNLOCK(); + if (!refcount_release(&ifp->if_refcount)) return; if_free_internal(ifp);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201104040745.p347j9IW074920>