Skip to content

Commit d8d2b1f

Browse files
Pavel Zhigulinkuba-moo
authored andcommitted
net: cxgb4/ch_ipsec: fix potential use-after-free in ch_ipsec_xfrm_add_state() callback
In ch_ipsec_xfrm_add_state() there is not check of try_module_get return value. It is very unlikely, but try_module_get() could return false value, which could cause use-after-free error. Conditions: The module count must be zero, and a module unload in progress. The thread doing the unload is blocked somewhere. Another thread makes a callback into the module for some request that (for instance) would need to create a kernel thread. It tries to get a reference for the thread. So try_module_get(THIS_MODULE) is the right call - and will fail here. This fix adds checking the result of try_module_get call Fixes: 6dad4e8 ("chcr: Add support for Inline IPSec") Signed-off-by: Pavel Zhigulin <Pavel.Zhigulin@kaspersky.com> Link: https://patch.msgid.link/20251024161304.724436-1-Pavel.Zhigulin@kaspersky.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 36fedc4 commit d8d2b1f

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

  • drivers/net/ethernet/chelsio/inline_crypto/ch_ipsec

drivers/net/ethernet/chelsio/inline_crypto/ch_ipsec/chcr_ipsec.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,15 @@ static int ch_ipsec_xfrm_add_state(struct net_device *dev,
290290
return -EINVAL;
291291
}
292292

293+
if (unlikely(!try_module_get(THIS_MODULE))) {
294+
NL_SET_ERR_MSG_MOD(extack, "Failed to acquire module reference");
295+
return -ENODEV;
296+
}
297+
293298
sa_entry = kzalloc(sizeof(*sa_entry), GFP_KERNEL);
294299
if (!sa_entry) {
295300
res = -ENOMEM;
301+
module_put(THIS_MODULE);
296302
goto out;
297303
}
298304

@@ -301,7 +307,6 @@ static int ch_ipsec_xfrm_add_state(struct net_device *dev,
301307
sa_entry->esn = 1;
302308
ch_ipsec_setkey(x, sa_entry);
303309
x->xso.offload_handle = (unsigned long)sa_entry;
304-
try_module_get(THIS_MODULE);
305310
out:
306311
return res;
307312
}

0 commit comments

Comments
 (0)