Re: [PATCH] net: fix potential use-after-free in ch_ipsec_xfrm_add_state() callback
From: Yanjun.Zhu
Date: Mon Oct 06 2025 - 14:27:58 EST
On 10/6/25 11:03 AM, Jakub Kicinski wrote:
On Fri, 3 Oct 2025 21:28:51 -0700 Zhu Yanjun wrote:
When the function ch_ipsec_xfrm_add_state is called, the kernel moduleThat was my intuition as well, but on a quick look module state is set
cannot be in the GOING or UNFORMED state.
to GOING before ->exit() is called. So this function can in fact fail
to acquire a reference.
Could you share your exact analysis?
I delved into this function ch_ipsec_xfrm_add_state.
Yes — your understanding is correct:
When a module begins unloading, the kernel sets its state to GOING before invoking its ->exit() method.
Any concurrent call to try_module_get() will fail after this point.
So try_module_get() can return false, even though it’s extremely rare.
Ignoring that failure means continuing to use data that may already be in teardown, creating a use-after-free hazard.
This commit properly closes that race window.
Yanjun.Zhu