From nobody Sun Dec 7 21:14:45 2025 Received: from mx13.kaspersky-labs.com (mx13.kaspersky-labs.com [91.103.66.164]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97ADE274FC2; Mon, 6 Oct 2025 13:47:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.103.66.164 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759758476; cv=none; b=RoEly4VMuNDq3gU100PmmRi6mR2MEGNBfOsaxLr+w4K7xKw7WuIU9g8fjI3UrML0TFNfPH5GnDc73uxhoULypT6/YWKhcki0AFcgNhzTejhV+nfhSHcXGpj12D/WBo+f1ZJ/23Td4QGSeP3oU2A0/SiqJzdxc9iY3mCiYsunPec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759758476; c=relaxed/simple; bh=TAG55uiiUbhrwQ+QhBag41HYjSMXPzpiS1Ng4Z7Kgew=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=lc0vIBJC/Er50/hvUINfnPh7Uzt78luk7uftPQO2Vyn2r1+wYOgS2/jJ0oC6lf6qsS9y1qDWIBsHzFP8al+yfvFjsYbL5LBrF6JRm+W1OXF90qAvZAt3woHpaIoY1lyetCDuI4xJwy9h7VuQNJj6gPdZRLeBmxRUxPspBdSgup4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=kaspersky.com; spf=pass smtp.mailfrom=kaspersky.com; dkim=pass (2048-bit key) header.d=kaspersky.com header.i=@kaspersky.com header.b=mNOxjnud; arc=none smtp.client-ip=91.103.66.164 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=kaspersky.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kaspersky.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kaspersky.com header.i=@kaspersky.com header.b="mNOxjnud" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kaspersky.com; s=mail202505; t=1759758471; bh=JR8w+XJMq7rbMSTQ6INf3Mk3He6RC/flSOlBjnEJ1Jo=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=mNOxjnud2l2D1t8Tn/PftDr+3JEO/Ia7lHT4AGndBNClJuHML6bqgerjTKsNyBCHW n1lu3n+dGmHvHrNp5I6jbTyYJrzApsqBNYsv2JISgEA7rtyTOTAqTIeyg/aL9YxOVH P4W4q52mvD2qWzOM7O9RGxPalsVb3g3tdIAoxOdT1qHg3Y6qEXwvoplJ4GxNIiVNMT 7Iz7X0CjI1FQvQQGgYwHvGQKOXO04LPm9w9d96qzEcxkKyLYx6CcoE6mmrEhUrYoQu ULuwdbCaW8drNxrevNKyrE06Yft+rkrVoPWgDVwt3nirDbEt55FBRzcXfsaKZOjPm7 QSnx1ca4vT65A== Received: from relay13.kaspersky-labs.com (localhost [127.0.0.1]) by relay13.kaspersky-labs.com (Postfix) with ESMTP id 483B33E4517; Mon, 6 Oct 2025 16:47:51 +0300 (MSK) Received: from mail-hq2.kaspersky.com (unknown [91.103.66.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mail-hq2.kaspersky.com", Issuer "Kaspersky MailRelays CA G3" (verified OK)) by mailhub13.kaspersky-labs.com (Postfix) with ESMTPS id 0047E3E48AC; Mon, 6 Oct 2025 16:47:48 +0300 (MSK) Received: from zhigulin-p.avp.ru (10.16.104.190) by HQMAILSRV2.avp.ru (10.64.57.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1748.36; Mon, 6 Oct 2025 16:47:48 +0300 From: Pavel Zhigulin To: Zhu Yanjun CC: Pavel Zhigulin , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Leon Romanovsky , Steffen Klassert , Cosmin Ratiu , Ayush Sawal , Harsh Jain , Atul Gupta , Herbert Xu , Ganesh Goudar , , , Subject: [PATCH net v2] net: cxgb4/ch_ipsec: fix potential use-after-free in ch_ipsec_xfrm_add_state() callback Date: Mon, 6 Oct 2025 16:47:20 +0300 Message-ID: <20251006134726.1232320-1-Pavel.Zhigulin@kaspersky.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: HQMAILSRV4.avp.ru (10.64.57.54) To HQMAILSRV2.avp.ru (10.64.57.52) X-KSE-ServerInfo: HQMAILSRV2.avp.ru, 9 X-KSE-AntiSpam-Interceptor-Info: scan successful X-KSE-AntiSpam-Version: 6.1.1, Database issued on: 10/06/2025 13:28:38 X-KSE-AntiSpam-Status: KAS_STATUS_NOT_DETECTED X-KSE-AntiSpam-Method: none X-KSE-AntiSpam-Rate: 0 X-KSE-AntiSpam-Info: Lua profiles 196841 [Oct 06 2025] X-KSE-AntiSpam-Info: Version: 6.1.1.11 X-KSE-AntiSpam-Info: Envelope from: Pavel.Zhigulin@kaspersky.com X-KSE-AntiSpam-Info: LuaCore: 69 0.3.69 3c9ee7b2dda8a12f0d3dc9d3a59fa717913bd018 X-KSE-AntiSpam-Info: {Tracking_cluster_exceptions} X-KSE-AntiSpam-Info: {Tracking_real_kaspersky_domains} X-KSE-AntiSpam-Info: {Tracking_uf_ne_domains} X-KSE-AntiSpam-Info: {Tracking_from_domain_doesnt_match_to} X-KSE-AntiSpam-Info: kaspersky.com:5.0.1,7.1.1;zhigulin-p.avp.ru:5.0.1,7.1.1;lore.kernel.org:7.1.1;127.0.0.199:7.1.2;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1 X-KSE-AntiSpam-Info: {Tracking_white_helo} X-KSE-AntiSpam-Info: FromAlignment: s X-KSE-AntiSpam-Info: Rate: 0 X-KSE-AntiSpam-Info: Status: not_detected X-KSE-AntiSpam-Info: Method: none X-KSE-Antiphishing-Info: Clean X-KSE-Antiphishing-ScanningType: Deterministic X-KSE-Antiphishing-Method: None X-KSE-Antiphishing-Bases: 10/06/2025 13:30:00 X-KSE-AttachmentFiltering-Interceptor-Info: no applicable attachment filtering rules found X-KSE-Antivirus-Interceptor-Info: scan successful X-KSE-Antivirus-Info: Clean, bases: 10/6/2025 12:01:00 PM X-KSE-BulkMessagesFiltering-Scan-Result: InTheLimit X-KSE-AttachmentFiltering-Interceptor-Info: no applicable attachment filtering rules found X-KSE-BulkMessagesFiltering-Scan-Result: InTheLimit X-KSMG-AntiPhishing: NotDetected, bases: 2025/10/06 10:59:00 X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.1.8310, bases: 2025/10/06 03:36:00 #27884816 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: NotDetected, bases: 2025/10/06 10:59:00 X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 52 Content-Type: text/plain; charset="utf-8" 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 Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 6dad4e8ab3ec ("chcr: Add support for Inline IPSec") Signed-off-by: Pavel Zhigulin --- v2: Remove redundant headers. Provide better description. v1: https://lore.kernel.org/all/20251001111646.806130-1-Pavel.Zhigulin@kasp= ersky.com/ .../net/ethernet/chelsio/inline_crypto/ch_ipsec/chcr_ipsec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/chelsio/inline_crypto/ch_ipsec/chcr_ipsec= .c b/drivers/net/ethernet/chelsio/inline_crypto/ch_ipsec/chcr_ipsec.c index ecd9a0bd5e18..29dbc3b6e9e2 100644 --- a/drivers/net/ethernet/chelsio/inline_crypto/ch_ipsec/chcr_ipsec.c +++ b/drivers/net/ethernet/chelsio/inline_crypto/ch_ipsec/chcr_ipsec.c @@ -301,7 +301,8 @@ static int ch_ipsec_xfrm_add_state(struct net_device *d= ev, sa_entry->esn =3D 1; ch_ipsec_setkey(x, sa_entry); x->xso.offload_handle =3D (unsigned long)sa_entry; - try_module_get(THIS_MODULE); + if (unlikely(!try_module_get(THIS_MODULE))) + res =3D -ENODEV; out: return res; } -- 2.43.0