From 5fcb2832e34cb651b979746e4aff42a43b9a3201 Mon Sep 17 00:00:00 2001 From: "Alexander V. Chernikov" Date: Thu, 2 Jan 2020 09:08:45 +0000 Subject: [PATCH] Plug loopback idaddr refcount leak. Reviewed by: markj MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D22980 --- sys/net/if.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index f0281b358347..9c6b6db503a8 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1836,6 +1836,7 @@ ifa_maintain_loopback_route(int cmd, const char *otype, struct ifaddr *ifa, struct rt_addrinfo info; struct sockaddr_dl null_sdl; struct ifnet *ifp; + struct ifaddr *rti_ifa = NULL; ifp = ifa->ifa_ifp; @@ -1846,9 +1847,10 @@ ifa_maintain_loopback_route(int cmd, const char *otype, struct ifaddr *ifa, /* explicitly specify (loopback) ifa */ if (info.rti_ifp != NULL) { NET_EPOCH_ENTER(et); - info.rti_ifa = ifaof_ifpforaddr(ifa->ifa_addr, info.rti_ifp); - if (info.rti_ifa != NULL) - ifa_ref(info.rti_ifa); + rti_ifa = ifaof_ifpforaddr(ifa->ifa_addr, info.rti_ifp); + if (rti_ifa != NULL) + ifa_ref(rti_ifa); + info.rti_ifa = rti_ifa; NET_EPOCH_EXIT(et); } } @@ -1859,6 +1861,9 @@ ifa_maintain_loopback_route(int cmd, const char *otype, struct ifaddr *ifa, error = rtrequest1_fib(cmd, &info, NULL, ifp->if_fib); + if (rti_ifa != NULL) + ifa_free(rti_ifa); + if (error != 0 && !(cmd == RTM_ADD && error == EEXIST) && !(cmd == RTM_DELETE && error == ENOENT))