From 753b9262aef5a83539bb46197527566cfb7a146e Mon Sep 17 00:00:00 2001 From: bz Date: Sat, 16 Oct 2010 19:25:27 +0000 Subject: Close a race acquiring the IF_ADDR_LOCK() for each entry while iterating over all interfaces to make sure the address will neither change nor be freed while we are working on it. PR: kern/146250 Submitted by: Mikolaj Golub (to.my.trociny gmail.com) MFC after: 1 week --- sys/net/rtsock.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sys/net') diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index ae72bd9..f2b0369 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1473,6 +1473,7 @@ sysctl_iflist(int af, struct walkarg *w) TAILQ_FOREACH(ifp, &V_ifnet, if_link) { if (w->w_arg && w->w_arg != ifp->if_index) continue; + IF_ADDR_LOCK(ifp); ifa = ifp->if_addr; info.rti_info[RTAX_IFP] = ifa->ifa_addr; len = rt_msg2(RTM_IFINFO, &info, NULL, w); @@ -1530,10 +1531,13 @@ sysctl_iflist(int af, struct walkarg *w) goto done; } } + IF_ADDR_UNLOCK(ifp); info.rti_info[RTAX_IFA] = info.rti_info[RTAX_NETMASK] = info.rti_info[RTAX_BRD] = NULL; } done: + if (ifp != NULL) + IF_ADDR_UNLOCK(ifp); IFNET_RUNLOCK(); return (error); } -- cgit v1.1