Skip to content

Commit 7d48224

Browse files
Bjoern A. ZeebBjoern A. Zeeb
Bjoern A. Zeeb
authored and
Bjoern A. Zeeb
committed
netlink: fix accessing freed memory
The check for if_addrlen in dump_iface() is not sufficient to determine if we still have a valid if_addr. Rather than directly accessing if_addr check the STAILQ (for the first entry). This avoids panics when destroying cloned interfaces as experienced with net80211 wlan ones. Sponsored by: The FreeBSD Foundation MFC after: 3 days Reviewed by: jhibbits (earlier version), kp Differential Revision: https://reviews.freebsd.org/D42027
1 parent 8b62217 commit 7d48224

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

sys/netlink/route/iface.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ static bool
292292
dump_iface(struct nl_writer *nw, if_t ifp, const struct nlmsghdr *hdr,
293293
int if_flags_mask)
294294
{
295+
struct epoch_tracker et;
295296
struct ifinfomsg *ifinfo;
296297

297298
NL_LOG(LOG_DEBUG3, "dumping interface %s data", if_name(ifp));
@@ -321,11 +322,15 @@ dump_iface(struct nl_writer *nw, if_t ifp, const struct nlmsghdr *hdr,
321322
nlattr_add_u8(nw, IFLA_PROTO_DOWN, val);
322323
nlattr_add_u8(nw, IFLA_LINKMODE, val);
323324
*/
324-
if (if_getaddrlen(ifp) != 0) {
325-
struct ifaddr *ifa = if_getifaddr(ifp);
325+
if (if_getaddrlen(ifp) != 0) {
326+
struct ifaddr *ifa;
326327

327-
dump_sa(nw, IFLA_ADDRESS, ifa->ifa_addr);
328-
}
328+
NET_EPOCH_ENTER(et);
329+
ifa = CK_STAILQ_FIRST(&ifp->if_addrhead);
330+
if (ifa != NULL)
331+
dump_sa(nw, IFLA_ADDRESS, ifa->ifa_addr);
332+
NET_EPOCH_EXIT(et);
333+
}
329334

330335
if ((if_getbroadcastaddr(ifp) != NULL)) {
331336
nlattr_add(nw, IFLA_BROADCAST, if_getaddrlen(ifp),

0 commit comments

Comments
 (0)