From owner-svn-src-all@FreeBSD.ORG Wed Jun 24 10:36:49 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 183F61065673; Wed, 24 Jun 2009 10:36:49 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 066788FC15; Wed, 24 Jun 2009 10:36:49 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n5OAamQ6009309; Wed, 24 Jun 2009 10:36:48 GMT (envelope-from rwatson@svn.freebsd.org) Received: (from rwatson@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n5OAamNW009307; Wed, 24 Jun 2009 10:36:48 GMT (envelope-from rwatson@svn.freebsd.org) Message-Id: <200906241036.n5OAamNW009307@svn.freebsd.org> From: Robert Watson Date: Wed, 24 Jun 2009 10:36:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r194821 - head/sys/net X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 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: Wed, 24 Jun 2009 10:36:49 -0000 Author: rwatson Date: Wed Jun 24 10:36:48 2009 New Revision: 194821 URL: http://svn.freebsd.org/changeset/base/194821 Log: In if_setlladdr(), use IF_ADDR_LOCK() and ifaddr references to improve the safety of link layer address manipulation. MFC after: 6 weeks Modified: head/sys/net/if.c Modified: head/sys/net/if.c ============================================================================== --- head/sys/net/if.c Wed Jun 24 10:33:35 2009 (r194820) +++ head/sys/net/if.c Wed Jun 24 10:36:48 2009 (r194821) @@ -3145,14 +3145,23 @@ if_setlladdr(struct ifnet *ifp, const u_ struct ifaddr *ifa; struct ifreq ifr; + IF_ADDR_LOCK(ifp); ifa = ifp->if_addr; - if (ifa == NULL) + if (ifa == NULL) { + IF_ADDR_UNLOCK(ifp); return (EINVAL); + } + ifa_ref(ifa); + IF_ADDR_UNLOCK(ifp); sdl = (struct sockaddr_dl *)ifa->ifa_addr; - if (sdl == NULL) + if (sdl == NULL) { + ifa_free(ifa); return (EINVAL); - if (len != sdl->sdl_alen) /* don't allow length to change */ + } + if (len != sdl->sdl_alen) { /* don't allow length to change */ + ifa_free(ifa); return (EINVAL); + } switch (ifp->if_type) { case IFT_ETHER: case IFT_FDDI: @@ -3164,10 +3173,13 @@ if_setlladdr(struct ifnet *ifp, const u_ case IFT_IEEE8023ADLAG: case IFT_IEEE80211: bcopy(lladdr, LLADDR(sdl), len); + ifa_free(ifa); break; default: + ifa_free(ifa); return (ENODEV); } + /* * If the interface is already up, we need * to re-init it in order to reprogram its