if_foreach_group() holds the ifnet lock shared while it walks the
groups. Since 2f8f892ca344 dump_iface() calls it, and dump_iface()
also builds the RTM_NEWLINK notification that rt_ifmsg() sends on
every interface flag change, whether or not anyone listens. The ifnet
lock is now taken under whatever lock the caller of if_setflag() holds.
carp_alloc_if() makes the interface promiscuous with carp_sx held,
which adds carp_sx -> ifnet_sx. With in_control -> carp_sx
(carp_attach() from in_control()) and ifnet_sx -> in_control
(in_ifscrub_all() at vnet teardown) that is a cycle, reported when a
CARP address is added:
lock order reversal:
1st in_control (in_control, sx) @ sys/netinet/in.c:391
2nd carp_sx (carp_sx, sx) @ sys/netinet/ip_carp.c:2262
All lock orders from carp_sx -> in_control:
"carp_sx" -> "ifnet_sx" -> "in_control"
Group list entries and groups are freed only after NET_EPOCH_WAIT(),
so walk the list in the net epoch, as if_foreach_lladdr() does for the
address list. The only consumer, dump_group_cb(), writes into a
netlink buffer allocated M_NOWAIT and does not sleep.
Fixes: 2f8f892ca344 ("rtnetlink: Add FreeBSD-specific IFLAF_GROUP...")
MFC after: 1 week
Sponsored by: Rubicon Communications, LLC ("Netgate")