opnsense-src/sys/dev/wg
Kyle Evans b08ee10c06 wg: fix a number of issues with module load failure handling
If MOD_LOAD fails, then MOD_UNLOAD will be called to unwind module
state, but wg_module_init() will have already deinitialized everything
it needs to in a manner that renders it unsafe to call MOD_UNLOAD
after (e.g., freed zone not reset to NULL, wg_osd_jail_slot not reset
to 0).  Let's simply stop trying to handle freeing everything in
wg_module_init() to simplify it; let the subsequent MOD_UNLOAD deal with
it, and let's make that robust against partially-constructed state.

jhb@ notes that MOD_UNLOAD being called if MOD_LOAD fails is kind of an
anomaly that doesn't match other paradigms in the kernel; e.g., if
device_attach() fails, we don't invoke device_detach().  It's likely
that a future commit will revert this and instead stop calling
MOD_UNLOAD if MOD_LOAD fails, expecting modules to clean up after
themselves in MOD_LOAD upon failure.  Some other modules already do this
and may see similar problems to the wg module (see: carp).  The proper
fix is decidedly a bit too invasive to do this close to 14 branching,
and it requires auditing all kmods (base + ports) for potential leaks.

PR:		272089
Reviewed by:	emaste
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D40708
2023-06-23 12:00:09 -05:00
..
compat.h wg: Drop the compat shim for sbcreatecontrol(). 2022-11-11 14:18:48 -08:00
crypto.h wg: Trim compat shims for versions older than current stable/13. 2022-10-28 13:36:13 -07:00
if_wg.c wg: fix a number of issues with module load failure handling 2023-06-23 12:00:09 -05:00
if_wg.h
version.h
wg_cookie.c wg: fix a number of issues with module load failure handling 2023-06-23 12:00:09 -05:00
wg_cookie.h
wg_crypto.c wg: Trim compat shims for versions older than current stable/13. 2022-10-28 13:36:13 -07:00
wg_noise.c wg: Retire now unused support.h. 2022-10-28 13:36:13 -07:00
wg_noise.h