From owner-svn-src-head@FreeBSD.ORG Thu Oct 23 14:29:53 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6D1EAF54; Thu, 23 Oct 2014 14:29:53 +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)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 59D43DA8; Thu, 23 Oct 2014 14:29:53 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s9NETrmL070031; Thu, 23 Oct 2014 14:29:53 GMT (envelope-from ae@FreeBSD.org) Received: (from ae@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s9NETr9Y070030; Thu, 23 Oct 2014 14:29:53 GMT (envelope-from ae@FreeBSD.org) Message-Id: <201410231429.s9NETr9Y070030@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: ae set sender to ae@FreeBSD.org using -f From: "Andrey V. Elsukov" Date: Thu, 23 Oct 2014 14:29:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r273547 - head/sys/net X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Oct 2014 14:29:53 -0000 Author: ae Date: Thu Oct 23 14:29:52 2014 New Revision: 273547 URL: https://svnweb.freebsd.org/changeset/base/273547 Log: Move if_get_counter initialization from if_attach into if_alloc. Also, initialize all counters before ifnet will become available in the system. This fixes possible access to uninitialized ifned fields. PR: 194550 Modified: head/sys/net/if.c Modified: head/sys/net/if.c ============================================================================== --- head/sys/net/if.c Thu Oct 23 13:47:19 2014 (r273546) +++ head/sys/net/if.c Thu Oct 23 14:29:52 2014 (r273547) @@ -467,11 +467,10 @@ if_alloc(u_char type) ifq_init(&ifp->if_snd, ifp); refcount_init(&ifp->if_refcount, 1); /* Index reference. */ - ifnet_setbyindex(ifp->if_index, ifp); - for (int i = 0; i < IFCOUNTERS; i++) ifp->if_counters[i] = counter_u64_alloc(M_WAITOK); - + ifp->if_get_counter = if_get_counter_default; + ifnet_setbyindex(ifp->if_index, ifp); return (ifp); } @@ -674,9 +673,6 @@ if_attach_internal(struct ifnet *ifp, in ifp->if_qflush = if_qflush; } - if (ifp->if_get_counter == NULL) - ifp->if_get_counter = if_get_counter_default; - if (!vmove) { #ifdef MAC mac_ifnet_create(ifp);