opnsense-src/sys/compat/linuxkpi/common/src
Bjoern A. Zeeb fecc36e328 LinuxKPI: 802.11: improve key update locking to work around net80211
As indicated in 11db70b6057e there was another panic on key removal
which could no longer be reproduced.  As originally assumed the
problem was "hidden" by commit 9763fec11b83 as mentioned in
11db70b6057e.
Said commit had logic inverted and 27bf5c405bf2 fixed that and with
that the possible panic came back.

The problem exists because some code paths out of net80211 are
locked while others are not. This opens a possible race in
net80211 which was tracked by extra logging in
(*iv_key_update_begin)() (log lines shortend):
	key_update_begin: tid 100112 vap X nt Y unlocked
	key_update_begin: tid 100133 vap X nt Y locked
One thread can be wpa_supplicant, the other is driven from the
driver net80211 taskq.
Further LinuxKPI needs to unlock (conditionally in case the lock
is held) as a downcall to the driver/FW may sleep.  This opens up
possibilities for said race even further so that we observe it
more reliably.

This all leads to one thread calling down into the driver/firmware
(unlocked) while the other will get to the same place (after acquiring
the wiphy lock) before the nt re-lock happens and thus state checks
did not catch this either.

For LinuxKPI work around the problem utilizing
(*iv_key_update_begin/end)() and taking the wiphy_lock() there
holding it over the entire operation.
Given we still have to conditionally unlock we need to keep track
from _begin to _end on whether we have to re-lock.  The checks for
this need to be done under the wiphy_lock().
While a bool would suffice we use a refcount to make any future
debugging easier.

This isn't the most elegant solution but having the wiphy lock
covering the full operation allows the 2nd thread to later run through
the same code path and find the key gone (which we already checked).
It remains questionable if (*iv_key_update_begin/end)() is the
correct solution (as there are futher callers covering which would
not need the unlock cycle) or if it should be done in the current
code.  The former will allow us to cover a full key store which
we will need in case we will implement suspend/resume beyond what
is done in native drivers/net80211 currently, if we will factor
out the crypto locking for good, and fix the inconsistent locking
of the nt (NODE) lock in net80211.

Alternate solutions were discussed on freebsd-wireless today
(2025-03-06, in the thread "Re: HEADS UP! Do not update on main
currently (panic - on boot)").

Sponsored by:	The FreeBSD Foundation
X-MFC with:	27bf5c405bf2
Differential Revision: https://reviews.freebsd.org/D49256

(cherry picked from commit b8dfc3ecf7031a0a7764cdb67d85ebe0c03d5d93)
2025-03-19 22:22:15 +00:00
..
linux_80211.c LinuxKPI: 802.11: improve key update locking to work around net80211 2025-03-19 22:22:15 +00:00
linux_80211.h LinuxKPI: 802.11: improve key update locking to work around net80211 2025-03-19 22:22:15 +00:00
linux_80211_macops.c LinuxKPI: 802.11: hardware crypto offload improvements 2025-02-24 20:26:49 +00:00
linux_acpi.c LinuxKPI: Add acpi_dev_get_first_match_dev and acpi_device_handle 2024-08-02 00:15:51 +03:00
linux_aperture.c LinuxKPI: update linuxkpi_video to Linux 6.6 2024-08-11 13:12:38 +03:00
linux_cmdline.c LinuxKPI: update linuxkpi_video to Linux 6.6 2024-08-11 13:12:38 +03:00
linux_compat.c Fix "vrefact: wrong use count 0" with DRM 2025-01-17 18:43:42 +00:00
linux_current.c linuxkpi: correct zone item size for linux_mm_zone 2024-01-22 07:01:24 +02:00
linux_devres.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
linux_dmi.c sys: Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:11 -06:00
linux_domain.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
linux_firmware.c LinuxKPI: firmware: change order filenames trying to load firmware 2025-02-10 14:52:08 +00:00
linux_fpu.c LinuxKPI: Allow kmalloc to be called when FPU protection is enabled 2024-02-17 23:58:39 +03:00
linux_hdmi.c LinuxKPI: update linuxkpi_video to Linux 6.6 2024-08-11 13:12:38 +03:00
linux_hrtimer.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
linux_i2c.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
linux_i2cbb.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
linux_idr.c linuxkpi: Allow ida_destroy and idr_destroy to be called multiple times 2024-08-02 00:09:39 +03:00
linux_interrupt.c LinuxKPI: Remove sys/rman.h include from LKPI headers. 2024-02-17 23:58:36 +03:00
linux_kmod.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
linux_kobject.c linuxkpi: Move struct kobject code to linux_kobject.c 2024-02-17 23:58:35 +03:00
linux_kthread.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
linux_lock.c sys: Remove $FreeBSD$: two-line .h pattern 2023-08-16 11:54:11 -06:00
linux_mhi.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
linux_netdev.c LinuxKPI: netdevice: add alloc_netdev_dummy() 2024-10-31 14:33:56 +00:00
linux_page.c linuxkpi: Fix an assertion in linux_free_kmem() 2023-10-24 09:20:12 -04:00
linux_pci.c LinuxKPI: pci: rename PCI_IRQ_LEGACY to PCI_IRQ_INTX 2024-10-31 14:33:56 +00:00
linux_radix.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
linux_rcu.c LinuxKPI: update rcu_dereference_*() and lockdep_is_held() 2024-10-31 14:33:57 +00:00
linux_schedule.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
linux_seq_file.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
linux_shmemfs.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
linux_shrinker.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
linux_simple_attr.c LinuxKPI: Add DEFINE_DEBUGFS_ATTRIBUTE_SIGNED to linux/debugfs.h 2024-08-02 00:09:41 +03:00
linux_skbuff.c LinuxKPI: skbuff: add synchronization primitives and missing bits 2025-02-26 02:39:41 +00:00
linux_slab.c LinuxKPI: move __kmalloc from slab.h to slab.c 2024-09-28 10:35:12 +00:00
linux_tasklet.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
linux_usb.c sys: Remove $FreeBSD$: one-line .c comment pattern 2023-08-16 11:54:24 -06:00
linux_work.c LinuxKPI: Add cancel_work() function. 2024-02-17 23:58:38 +03:00
linux_xarray.c sys: Remove $FreeBSD$: one-line .c pattern 2023-08-16 11:54:36 -06:00
linuxkpi_hdmikmod.c linuxkpi: hdmi: Split the module declaration to a new file 2024-06-04 13:06:40 +02:00
linuxkpi_videokmod.c linuxkpi: Add linuxkpi_video module 2024-06-04 13:06:45 +02:00
lkpi_iic_if.m spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD 2023-05-12 10:44:03 -06:00