HomeFreeBSD

Fix ifa refcount leak in ifa_ifwithnet()

Description

Fix ifa refcount leak in ifa_ifwithnet()

In 4f6c66cc9c75c8, ifa_ifwithnet() was changed to no longer
ifa_ref() the returned ifaddr, and instead the caller was required
to stay in the net_epoch for as long as they wanted the ifaddr
to remain valid. However, this missed the case where an AF_LINK
lookup would call ifaddr_byindex(), which still does ifa_ref()
the ifaddr. This would cause a refcount leak.

Fix this by inlining the relevant parts of ifaddr_byindex() here,
with the ifa_ref() call removed. This also avoids an unnecessary
entry and exit from the net_epoch for this case.

I've audited all in-tree consumers of ifa_ifwithnet() that could
possibly perform an AF_LINK lookup and confirmed that none of them
will expect the ifaddr to have a reference that they need to
release.

MFC after: 2 months
Sponsored by: Dell Inc
Differential Revision: https://reviews.freebsd.org/D28705
Reviewed by: melifaro

(cherry picked from commit 5adea417d494b9c0e186cf2d06f98873d02d1834)

Details

Provenance
rstoneAuthored on Feb 11 2021, 4:17 PM
Reviewer
melifaro
Differential Revision
D28705: Fix ifa refcount leak in ifa_ifwithnet()
Parents
rGeb40c0f2f2ce: vt_vga: fix colour in pixel blocks with more than 4 colours
Branches
Unknown
Tags
Unknown