From 61dc434406e8353b2efd301bb636ecb64e5381d5 Mon Sep 17 00:00:00 2001 From: "Andrey V. Elsukov" Date: Thu, 23 Oct 2014 14:29:52 +0000 Subject: [PATCH] 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 --- sys/net/if.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index a7fb2a95fee..8ba78eba994 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -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, int vmove) 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);