freebsd-dev/sys/net
Kristof Provost 92c23f6d9c vlan: fix setting flags on a QinQ interface
Setting vlan flags needlessly takes the exclusive VLAN_XLOCK().

If we have stacked vlan devices (i.e. QinQ) and we set vlan flags (e.g.
IFF_PROMISC) we call rtnl_handle_ifevent() to send a notification about
the interface.
This ends up calling SIOCGIFMEDIA, which requires the VLAN_SLOCK().
Trying to take that one with the VLAN_XLOCK() held deadlocks us.

There's no need for the exclusive lock though, as we're only accessing
parent/trunk information, not modifying it, so a shared lock is
sufficient.

While here also add a test case for this issue.

Backtrace:
	shared lock of (sx) vlan_sx @ /usr/src/sys/net/if_vlan.c:2192
	while exclusively locked from /usr/src/sys/net/if_vlan.c:2307
	panic: excl->share
	cpuid = 29
	time = 1683873033
	KDB: stack backtrace:
	db_trace_self_wrapper() at db_trace_self_wrapper+0x2b/frame 0xfffffe015d4ad4b0
	vpanic() at vpanic+0x152/frame 0xfffffe015d4ad500
	panic() at panic+0x43/frame 0xfffffe015d4ad560
	witness_checkorder() at witness_checkorder+0xcb5/frame 0xfffffe015d4ad720
	_sx_slock_int() at _sx_slock_int+0x67/frame 0xfffffe015d4ad760
	vlan_ioctl() at vlan_ioctl+0xf8/frame 0xfffffe015d4ad7c0
	dump_iface() at dump_iface+0x12f/frame 0xfffffe015d4ad840
	rtnl_handle_ifevent() at rtnl_handle_ifevent+0xab/frame 0xfffffe015d4ad8c0
	if_setflag() at if_setflag+0xf6/frame 0xfffffe015d4ad930
	ifpromisc() at ifpromisc+0x2a/frame 0xfffffe015d4ad960
	vlan_setflags() at vlan_setflags+0x60/frame 0xfffffe015d4ad990
	vlan_ioctl() at vlan_ioctl+0x216/frame 0xfffffe015d4ad9f0
	if_setflag() at if_setflag+0xe4/frame 0xfffffe015d4ada60
	ifpromisc() at ifpromisc+0x2a/frame 0xfffffe015d4ada90
	bridge_ioctl_add() at bridge_ioctl_add+0x499/frame 0xfffffe015d4adb10
	bridge_ioctl() at bridge_ioctl+0x328/frame 0xfffffe015d4adbc0
	ifioctl() at ifioctl+0x972/frame 0xfffffe015d4adcc0
	kern_ioctl() at kern_ioctl+0x1fe/frame 0xfffffe015d4add30
	sys_ioctl() at sys_ioctl+0x154/frame 0xfffffe015d4ade00
	amd64_syscall() at amd64_syscall+0x140/frame 0xfffffe015d4adf30
	fast_syscall_common() at fast_syscall_common+0xf8/frame 0xfffffe015d4adf30
	--- syscall (54, FreeBSD ELF64, ioctl), rip = 0x22b0f0ef8d8a, rsp = 0x22b0ec63f2c8, rbp = 0x22b0ec63f380 ---
	KDB: enter: panic
	[ thread pid 5715 tid 101132 ]

Sponsored by:	Rubicon Communications, LLC ("Netgate")
2023-05-12 11:12:51 +02:00
..
altq altq: ansify 2023-02-13 18:32:45 +00:00
route routing: add iterator-based nhop traversal KPI. 2023-04-25 10:55:16 +00:00
bpf_buffer.c
bpf_buffer.h
bpf_filter.c bpf(3): Grammar fix for a source code comment 2022-09-04 17:30:05 +02:00
bpf_jitter.c
bpf_jitter.h
bpf_zerocopy.c
bpf_zerocopy.h
bpf.c net: whack __mips__ leftovers 2023-03-01 11:07:32 +00:00
bpf.h bpf: Add "_if" tap APIs 2023-01-31 15:02:14 -05:00
bpfdesc.h bpf: Add an ioctl to set the VLAN Priority on packets sent by bpf 2021-07-26 23:13:31 +02:00
bridgestp.c ifnet/API: Move struct ifnet definition to a <net/if_private.h> 2023-01-24 14:36:30 -05:00
bridgestp.h
debugnet_inet.c ifnet/API: Move struct ifnet definition to a <net/if_private.h> 2023-01-24 14:36:30 -05:00
debugnet_int.h
debugnet.c ifnet/API: Move struct ifnet definition to a <net/if_private.h> 2023-01-24 14:36:30 -05:00
debugnet.h debugnet: Add ifnet accessor to set debugnet methods 2023-01-24 15:03:35 -05:00
dlt.h libpcap: Update to 1.10.3 2023-03-31 16:02:22 -03:00
ethernet.h bridge: Add support for emulated netmap mode 2023-04-10 12:14:11 -04:00
firewire.h IfAPI: Add l2com accessor for firewire. 2023-01-31 15:02:17 -05:00
ieee8023ad_lacp.c lacp: Use C99 bool for boolean return value 2023-04-01 01:48:36 +08:00
ieee8023ad_lacp.h lacp: Use C99 bool for boolean return value 2023-04-01 01:48:36 +08:00
ieee_oui.h Remove "All Rights Reserved" from FreeBSD Foundation sys/ copyrights 2021-08-08 10:42:24 -04:00
if_arp.h
if_bridge.c bridge: distinguish no vlan and vlan 1 2023-04-14 13:17:02 +02:00
if_bridgevar.h bridge: Add support for emulated netmap mode 2023-04-10 12:14:11 -04:00
if_clone.c netlink: add netlink interfaces to if_clone 2023-04-25 12:34:46 +00:00
if_clone.h netlink: add netlink interfaces to if_clone 2023-04-25 12:34:46 +00:00
if_dead.c ifnet/API: Move struct ifnet definition to a <net/if_private.h> 2023-01-24 14:36:30 -05:00
if_disc.c ifnet/API: Move struct ifnet definition to a <net/if_private.h> 2023-01-24 14:36:30 -05:00
if_dl.h
if_edsc.c ifnet/API: Move struct ifnet definition to a <net/if_private.h> 2023-01-24 14:36:30 -05:00
if_enc.c net: use pfil_mbuf_{in,out} where we always have an mbuf 2023-02-14 10:02:49 -08:00
if_enc.h
if_epair.c net: replace IFF_KNOWSEPOCH with IFF_NEEDSEPOCH 2023-04-17 09:08:35 -07:00
if_ethersubr.c net: replace IFF_KNOWSEPOCH with IFF_NEEDSEPOCH 2023-04-17 09:08:35 -07:00
if_fwsubr.c ifnet/API: Move struct ifnet definition to a <net/if_private.h> 2023-01-24 14:36:30 -05:00
if_gif.c ifnet/API: Move struct ifnet definition to a <net/if_private.h> 2023-01-24 14:36:30 -05:00
if_gif.h
if_gre.c ifnet/API: Move struct ifnet definition to a <net/if_private.h> 2023-01-24 14:36:30 -05:00
if_gre.h
if_infiniband.c net: replace IFF_KNOWSEPOCH with IFF_NEEDSEPOCH 2023-04-17 09:08:35 -07:00
if_ipsec.c ifnet/API: Move struct ifnet definition to a <net/if_private.h> 2023-01-24 14:36:30 -05:00
if_ipsec.h
if_lagg.c lagg(4): Correctly define some sysctl variables 2023-04-17 18:24:35 +08:00
if_lagg.h lagg: Various style fixes 2023-03-24 17:55:15 +08:00
if_llatbl.c netlink: fix IPv6 proxy ndp deletion. 2023-04-26 13:26:37 +00:00
if_llatbl.h netinet6: Fix mbuf leak in NDP 2022-05-31 21:06:14 +00:00
if_llc.h
if_loop.c ifnet/API: Move struct ifnet definition to a <net/if_private.h> 2023-01-24 14:36:30 -05:00
if_me.c ifnet/API: Move struct ifnet definition to a <net/if_private.h> 2023-01-24 14:36:30 -05:00
if_media.c ifnet/API: Move struct ifnet definition to a <net/if_private.h> 2023-01-24 14:36:30 -05:00
if_media.h
if_mib.c ifnet/API: Move struct ifnet definition to a <net/if_private.h> 2023-01-24 14:36:30 -05:00
if_mib.h
if_ovpn.c if_ovpn: notify userspace when we've used half of the sequence numbers 2023-05-08 16:43:25 +02:00
if_ovpn.h if_ovpn: notify userspace when we've used half of the sequence numbers 2023-05-08 16:43:25 +02:00
if_pflog.h pflog: align header to 4 bytes, not 8 2022-02-01 18:17:44 +01:00
if_pfsync.h pfsync: prepare code to accommodate AF_INET6 family 2022-11-09 21:06:07 +01:00
if_private.h IfAPI: Hide the macros that touch ifnet members 2023-04-24 09:54:23 -04:00
if_stf.c if_stf: Delete unreachable code 2023-04-23 12:47:57 +08:00
if_stf.h if_stf: make if_stf.h self-contained 2021-12-17 12:38:34 +01:00
if_tap.h
if_tun.h
if_tuntap.c ifnet/API: Move struct ifnet definition to a <net/if_private.h> 2023-01-24 14:36:30 -05:00
if_types.h Import the WireGuard driver from zx2c4.com. 2022-10-28 13:36:12 -07:00
if_var.h IfAPI: Add if_maddr_empty() to check for any maddrs 2023-05-02 14:34:47 -04:00
if_vlan_var.h bridge: distinguish no vlan and vlan 1 2023-04-14 13:17:02 +02:00
if_vlan.c vlan: fix setting flags on a QinQ interface 2023-05-12 11:12:51 +02:00
if_vxlan.c ifnet/API: Move struct ifnet definition to a <net/if_private.h> 2023-01-24 14:36:30 -05:00
if_vxlan.h
if.c IfAPI: Add if_maddr_empty() to check for any maddrs 2023-05-02 14:34:47 -04:00
if.h net: replace IFF_KNOWSEPOCH with IFF_NEEDSEPOCH 2023-04-17 09:08:35 -07:00
ifdi_if.m IfAPI: Explicitly include <net/if_private.h> in netstack 2023-01-31 15:02:16 -05:00
iflib_clone.c ifnet/API: Move struct ifnet definition to a <net/if_private.h> 2023-01-24 14:36:30 -05:00
iflib_private.h
iflib.c net: replace IFF_KNOWSEPOCH with IFF_NEEDSEPOCH 2023-04-17 09:08:35 -07:00
iflib.h iflib: Introduce v2 of TX Queue Select Functionality 2022-10-17 14:59:55 -07:00
ifq.c IfAPI: Explicitly include <net/if_private.h> in netstack 2023-01-31 15:02:16 -05:00
ifq.h ifnet/API: Privatize the implementation of the drbr_* APIs 2023-01-31 15:02:14 -05:00
infiniband.h infiniband: Convert BPF handling for IfAPI 2023-03-14 15:51:32 -04:00
mp_ring.c
mp_ring.h net: whack __mips__ leftovers 2023-03-01 11:07:32 +00:00
mppc.h
mppcc.c
mppcd.c
netisr_internal.h
netisr.c ifnet/API: Move struct ifnet definition to a <net/if_private.h> 2023-01-24 14:36:30 -05:00
netisr.h netisr: Remove the now-unused NETISR_EPAIR queue index 2023-04-05 11:46:42 -04:00
netmap_legacy.h
netmap_user.h netmap: fix refcount bug in netmap allocator 2022-03-06 16:39:16 +00:00
netmap_virt.h
netmap.h netmap(4): Fix a typo in a source code comment 2022-10-25 14:56:25 +02:00
paravirt.h
pfil.c pf: distinguish forwarding and output cases for pf_refragment6() 2023-03-16 10:59:04 +01:00
pfil.h pf: distinguish forwarding and output cases for pf_refragment6() 2023-03-16 10:59:04 +01:00
pfkeyv2.h net/pfkeyv2.h: fix typo, meNber 2023-05-11 02:52:39 +03:00
pfvar.h pf: fix a few more prototypes 2023-05-05 13:41:02 +02:00
ppp_defs.h
radix.c net: constantify radix.c functions 2022-08-01 07:32:40 +00:00
radix.h net: constantify radix.c functions 2022-08-01 07:32:40 +00:00
rndis.h
route.c netlink: add netlink KPI to the kernel by default 2023-03-27 13:55:44 +00:00
route.h netlink: add rtsock-compatible header to use with netlink snl(3). 2023-03-09 14:37:42 +00:00
rss_config.c Revert "wpa: Import wpa_supplicant/hostapd commit 14ab4a816" 2021-12-02 14:45:04 -08:00
rss_config.h
rtsock.c routing: add public rt_is_exportable() version to check if 2023-03-26 08:24:27 +00:00
sff8436.h
sff8472.h
slcompress.c
slcompress.h
toeplitz.c
toeplitz.h
vnet.c vnet: Fix a typo in a source code comment 2023-04-17 18:24:35 +08:00
vnet.h vnet: Make vnet_sys[un]init() static 2023-02-22 00:22:23 +08:00