From owner-svn-src-all@FreeBSD.ORG Tue Jan 7 21:14:29 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 29D77C5F; Tue, 7 Jan 2014 21:14:29 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 1637C1F19; Tue, 7 Jan 2014 21:14:29 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id s07LES2k099579; Tue, 7 Jan 2014 21:14:28 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id s07LESBF099576; Tue, 7 Jan 2014 21:14:28 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <201401072114.s07LESBF099576@svn.freebsd.org> From: Luigi Rizzo Date: Tue, 7 Jan 2014 21:14:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r260411 - head/sys/dev/netmap X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Jan 2014 21:14:29 -0000 Author: luigi Date: Tue Jan 7 21:14:28 2014 New Revision: 260411 URL: http://svnweb.freebsd.org/changeset/base/260411 Log: fix use after free when releasing a netmap adapter. Submitted by: Giuseppe Lettieri Modified: head/sys/dev/netmap/netmap.c head/sys/dev/netmap/netmap_kern.h Modified: head/sys/dev/netmap/netmap.c ============================================================================== --- head/sys/dev/netmap/netmap.c Tue Jan 7 21:04:49 2014 (r260410) +++ head/sys/dev/netmap/netmap.c Tue Jan 7 21:14:28 2014 (r260411) @@ -2208,9 +2208,14 @@ netmap_detach(struct ifnet *ifp) NMG_LOCK(); netmap_disable_all_rings(ifp); - netmap_adapter_put(na); - na->ifp = NULL; - netmap_enable_all_rings(ifp); + if (!netmap_adapter_put(na)) { + /* someone is still using the adapter, + * tell them that the interface is gone + */ + na->ifp = NULL; + /* give them a chance to notice */ + netmap_enable_all_rings(ifp); + } NMG_UNLOCK(); } Modified: head/sys/dev/netmap/netmap_kern.h ============================================================================== --- head/sys/dev/netmap/netmap_kern.h Tue Jan 7 21:04:49 2014 (r260410) +++ head/sys/dev/netmap/netmap_kern.h Tue Jan 7 21:14:28 2014 (r260411) @@ -899,11 +899,11 @@ void __netmap_adapter_get(struct netmap_ int __netmap_adapter_put(struct netmap_adapter *na); #define netmap_adapter_put(na) \ - do { \ + ({ \ struct netmap_adapter *__na = na; \ D("putting %p:%s (%d)", __na, NM_IFPNAME(__na->ifp), __na->na_refcount); \ __netmap_adapter_put(__na); \ - } while (0) + }) #else /* !NM_DEBUG_PUTGET */