Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Oct 2014 14:29:53 +0000 (UTC)
From:      "Andrey V. Elsukov" <ae@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r273547 - head/sys/net
Message-ID:  <201410231429.s9NETr9Y070030@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201410231429.s9NETr9Y070030>