From patchwork Fri Jul 3 17:34:59 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5089 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:1887:b0:869:83bc:8c48 with SMTP id r7csp2437735max; Fri, 3 Jul 2026 10:35:44 -0700 (PDT) X-Forwarded-Encrypted: i=2; AFNElJ+7W/sTtWY30VC/ekMKWHTTgtdXv08uszynQTpmWBgH7kQVrDWpE/ewqPJlfOow7vesBxgeaySRmQo=@openvpn.net X-Received: by 2002:a05:6820:1611:b0:6a3:ce0:a349 with SMTP id 006d021491bc7-6a32f4c63d7mr88945eaf.24.1783100143902; Fri, 03 Jul 2026 10:35:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1783100143; cv=none; d=google.com; s=arc-20260327; b=P2G64kiKXhbNJwCJkrvy0N/hqy0E74j5vjJTJ9C8JPUM9jSojNeGz7nwtcKa1yGAlQ C806KypiLJimnfjhEDH3lmObzv6PFNNHYd45PSefaAnJe2FJ2bvv/QWtj/jhDSCbJTf9 Bu1N5nJfR0SQ70SPanuqCxfgqsoPE1jktPP5j3s6kALUIPxqReECAuJHzmuyWJcSJ1iI 2683p9vgcfHc0Xund1QsxGkJmk2HMJ9o8BuCoXRfsZeVqejzG1/e3kk8E+4k8NdOOa4+ 1f6tBuyMgZ8PsgRd9vZv5AKpHLoVKFfzCNCtgCy/0+hMSe/0/MPUumVDGtJE/teg1uCX YHnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:message-id:date:to:from:dkim-signature:dkim-signature :dkim-signature:dkim-signature; bh=JM0C4cbOx1NZNdRpih+i+8Vi/1qF61ziEHmu0ARQW1I=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=NyyI2xRhqAsTrdesluLhpJCWOfq9r6z9LFE+AvasKxAB2BYaLN/UxBMQfVs1RwVJvs x9N7l954DFbDcMn2p5Ydg+ZdLYGgCJixi/PTR+VUR0LERTWghmnXhO3/vnoAV0p5lRCW upGBkWdAJVA60hODECj0n5CDHpg1bqk9QCqaFSOOC3y6maZ41gZpp2ihrv8HhgsD4gIs OwkG0ScG8qQueiYOjyTKpgHcvSf+1IKUOsnrbW7Q/4bg4ygRUIDtGJCJUKgUrshwIG6g nVxFQOcjBOsHikgRhFLm8IJ+2K7VBEPgkw7qp9hDfKp6ys5bXQX04i4ZsdEnGrnkbtTi wtBA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=B5sN+2Cz; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=b3jz+1qd; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=UV9DDTWW; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=iRMYTRvT; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 006d021491bc7-6a30ffa4624si4897528eaf.17.2026.07.03.10.35.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Jul 2026 10:35:43 -0700 (PDT) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=B5sN+2Cz; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=b3jz+1qd; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=UV9DDTWW; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=iRMYTRvT; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:Message-ID:Date:To:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Owner; bh=JM0C4cbOx1NZNdRpih+i+8Vi/1qF61ziEHmu0ARQW1I=; b=B5sN+2CzMwAQM1gFn11k4hq13f /A+ud22w1lobOaqYfPWFUY8+CMdeu8JFHtNX1VqQ/d4Ts/ri2Xlww6hFakTIDgl1dZzSwBH37ba60 hgxgGbKy3mlbndLU8B1tuYThq4yK/j6M63tqmYOBc70p7g0QAHZ73pMJLpKKMfJHuD9M=; Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1wfhnb-0003rQ-FA; Fri, 03 Jul 2026 17:35:36 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1wfhnU-0003qb-Hd for openvpn-devel@lists.sourceforge.net; Fri, 03 Jul 2026 17:35:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=v41xdGIv7vutWRJ1QpWGGIOWO4aqmbLe4+0FDd/YstQ=; b=b3jz+1qdsdoNFI/Su8WA5v9WqA hqMeuLv5z+Q1dqWUHfL5NEnPNnNM0xARa3vFsfxS215DjPRho4I5GI2bBarp+DKadB3jM3SnHNVeU 6r4JHFfZizb6FCvaOlcG4KPQoP9wDd6wUY4I3T94RkJF8/l+FGV3daobjmIM1CNJxVKQ=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=v41xdGIv7vutWRJ1QpWGGIOWO4aqmbLe4+0FDd/YstQ=; b=U V9DDTWWcW/F9ZWi8ofq4GbX053St3KzXFpGdq91HAYXVywNcB9i5PaFyJVhVfFDLFc37dQWTpF9pN yfXF+THRp3XvTUiPcGEhfrMpWXJ7vPIKUowCdN+rLNIZKvVr0eZs2khMf2BuRdnCUC4iZO6cHG7qC E3Dh02nSU/zJ3eLY=; Received: from mout-b-112.mailbox.org ([195.10.208.42]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1wfhnS-00071m-Ek for openvpn-devel@lists.sourceforge.net; Fri, 03 Jul 2026 17:35:29 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-112.mailbox.org (Postfix) with ESMTPS id 4gsLVm4tjCzDx6P; Fri, 3 Jul 2026 19:35:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1783100112; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=v41xdGIv7vutWRJ1QpWGGIOWO4aqmbLe4+0FDd/YstQ=; b=iRMYTRvTUVaEfKKnGQNuZ9rsACcV4KR74XiIivAOF5/5/0XqU91QZjAAipOp5O24wIFBTe IAyXeKVE7lignDYCY1iwVgAO+4hVo+VvxpAWh6OJ7iQFKExL99sh42UDa4HiIq7f3/wBHi oKZ4c/683DMvFnmluzSfLwHT/plRofkYHmstJRMHl4JSV4592F476JAvYi3IwQ0Ro6d3dY CkR8QTwJk4oDEJcxI8HMRkqjhmQhxtFbEFXDptUlpvOmuJ86wElVadjnfKMsqMV/Ja1CC9 QJChZ7sZzRJMR3kdijUygQVaAlXb8vPyKPfmzYTy36AXZdC1d8WgB0KeP2/5MQ== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::102 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Fri, 3 Jul 2026 19:34:59 +0200 Message-ID: <981d2ea51cca45138210aa52c6e5a0e55c0da7a0.1783099626.git.ralf@mandelbit.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4gsLVm4tjCzDx6P X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-1.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Crypto completion callbacks hold both key-slot and peer references. The peer reference pins the netdev, and dropping the last peer reference can let netdev unregistration and module removal make progr [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 RCVD_IN_DNSWL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to DNSWL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#DnsBlocklists-dnsbl-block for more information. [195.10.208.42 listed in list.dnswl.org] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-Headers-End: 1wfhnS-00071m-Ek Subject: [Openvpn-devel] [PATCH ovpn net v4 1/3] ovpn: finish crypto callback cleanup before peer release X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1869716016208028238 X-GMAIL-MSGID: 1869716016208028238 Crypto completion callbacks hold both key-slot and peer references. The peer reference pins the netdev, and dropping the last peer reference can let netdev unregistration and module removal make progress. Do not release that peer reference before the callback has finished its own cleanup. If ovpn_crypto_key_slot_put runs after ovpn_peer_put, it can schedule an RCU callback backed by module text after ovpn_cleanup rcu_barrier has already run. The TX error path also freed the remaining skb after ovpn_peer_put, leaving callback cleanup outside the peer/netdev lifetime window. Release the key slot and free any remaining skb first, then drop the peer reference as the last callback action. Fixes: 8534731dbf2d ("ovpn: implement packet processing") Signed-off-by: Ralf Lici --- No changes since v3 https://lore.kernel.org/openvpn-devel/f367b736f2597edb1677794173997d5a0f9f599c.1783080055.git.ralf@mandelbit.com/ Changes since v2 https://lore.kernel.org/openvpn-devel/567de7a9371ce72b0632158799dd11bb543cae08.1783068961.git.ralf@mandelbit.com/ - Also free the remaining TX skb before dropping the peer reference, so crypto callbacks do not continue cleanup after peer release. drivers/net/ovpn/io.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/ovpn/io.c b/drivers/net/ovpn/io.c index a6b777a9c2d9..e5f2775392d7 100644 --- a/drivers/net/ovpn/io.c +++ b/drivers/net/ovpn/io.c @@ -204,10 +204,10 @@ void ovpn_decrypt_post(void *data, int ret) ovpn_dev_dstats_rx_dropped(peer->ovpn->dev); kfree_skb(skb); drop_nocount: - if (likely(peer)) - ovpn_peer_put(peer); if (likely(ks)) ovpn_crypto_key_slot_put(ks); + if (likely(peer)) + ovpn_peer_put(peer); } /* RX path entry point: decrypt packet and forward it to the device */ @@ -302,11 +302,11 @@ void ovpn_encrypt_post(void *data, int ret) err: if (unlikely(skb)) ovpn_dev_dstats_tx_dropped(peer->ovpn->dev); - if (likely(peer)) - ovpn_peer_put(peer); + kfree_skb(skb); if (likely(ks)) ovpn_crypto_key_slot_put(ks); - kfree_skb(skb); + if (likely(peer)) + ovpn_peer_put(peer); } static bool ovpn_encrypt_one(struct ovpn_peer *peer, struct sk_buff *skb) From patchwork Fri Jul 3 17:35:00 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5090 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:1887:b0:869:83bc:8c48 with SMTP id r7csp2437745max; Fri, 3 Jul 2026 10:35:44 -0700 (PDT) X-Forwarded-Encrypted: i=2; AHgh+RqG1FO+OsM9WNjF8ljYi7wjRA5BVOJcjVLlEv8Y80/8tJpUc62ubqX3DlhKRqE2+RDeYdA+94Tsv0g=@openvpn.net X-Received: by 2002:a05:6871:3a23:b0:447:2ca4:918 with SMTP id 586e51a60fabf-44d18432fd4mr211939fac.33.1783100144049; Fri, 03 Jul 2026 10:35:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1783100144; cv=none; d=google.com; s=arc-20260327; b=bRah25zRCOqCMFhuNmDbAFxJ0bCCwNvMxqxBl40JUG0fQ3dNd2QzDVI3MWdjM7PwCY GqHOrOXN5o2pI8qdx26BCeDVfNZooh0z2NXPHh+7oEXbnANJyI175lo5v3G1YutUVxLs FdqcRnIKNtKZg74v2VRNWCBp++bx/fhPtHzX6wOmp2b3Veh7IY74UGM6BdZMAs86RxHy JOXRTKLIHvuT+p41C80gBbqReM7lOk68OtEstc+omZY/uRVMXSP1et4P3rt7gpZm71y+ BxYVsTsy9Kr71335p2pgigheMLcQLVJbrdWQBG8GGB+DccvOeHq5tRjbax5ayJgjjz7t /AMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature:dkim-signature; bh=ygnNk7NscrXvvw0GfPQmsOzHQeFUZX2aUSXq4216ls4=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=KhMuVbfDbkGKL1lcyqj8K1Yq0Ev1J7/UIrKwxRZSScRU/1+zHeBSNnfnjHu9M9BJhR 4IwI79weq3SNQO98CHZ8owfP7fTBkJQRXJsdboMVOn0IuuK5hqcqFsUFzYeyOUYeGkVR oa1roau/1VGgGYYDm8beJxbyqwTk0OA8AQxaVdepL+1XMq5LKJ5xGaemGobBfibr+D7y 7B20E1d51GkOdmNiITFS6qAcVdMYstfTPhEzkr7vXr+bupGq+HQKzgIzkSBeYXQDFU0Q r/OdRbEthBO2RIEk/KCKEnRsKwC6EiCIA5vMQCBUMaJ7z0715/k5eUEJGudxDzBvU7Mu VhSA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=CY41Ls8h; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=btGkTR33; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=CCRJ8vlZ; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=lfhkTJSb; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 586e51a60fabf-44cfbb224c2si2061770fac.171.2026.07.03.10.35.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Jul 2026 10:35:44 -0700 (PDT) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=CY41Ls8h; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=btGkTR33; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=CCRJ8vlZ; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=lfhkTJSb; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ygnNk7NscrXvvw0GfPQmsOzHQeFUZX2aUSXq4216ls4=; b=CY41Ls8hdZxSjRROT0Mdq1x7ck KMKDxx5Wut/E+iefjMLwnnpfveM8dup8/vpSzl+uSgpo3DMJqbqVsr49y5PMdXFEZbhYdIRJPZnq6 feT1rSK0wBPgNdSz7NU0nf67DbBuoJCNCOMl6cJr/gTSLVWa4m/9vYMoZP1ispNHYqP8=; Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1wfhnf-00068k-9V; Fri, 03 Jul 2026 17:35:39 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1wfhnd-00068b-7T for openvpn-devel@lists.sourceforge.net; Fri, 03 Jul 2026 17:35:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=AL2ttyRF7x+2MOi01b0OtmwVVZQqH11xtCLGPHnMNjk=; b=btGkTR33cz//UAulg3ZhkV86sc BjvyESzcFH7BFnKz1FvMWR0WnPR5Y/TGU6EXFQ0vqHX+D7d2hYe6JLWTYgJiQubk4Gqw3RyDYZerW 5QRXyzOBSEB2bAM3V7XAHoyZ0j30qwNUDnwu3/8JQIDoXlVJKPtWVd1avbQ7VhqTyzLo=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=AL2ttyRF7x+2MOi01b0OtmwVVZQqH11xtCLGPHnMNjk=; b=CCRJ8vlZtDBxmAUYcZZ2CgL4ew brjj1Lp++y5ks9Lj7xrNtrKmgZT4jPxIC3SEoMYqrdrIqozINkoa1wO5I/mbH9s6NftH0y+Nek64l CjtxuR/9/UYCDpJSXUMMdbMPwTQ6DwV6k2Z17OTmL+cwmMnQ1icr9Cw8vpCOeqieOe70=; Received: from mout-b-105.mailbox.org ([195.10.208.50]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1wfhna-000734-UM for openvpn-devel@lists.sourceforge.net; Fri, 03 Jul 2026 17:35:37 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-105.mailbox.org (Postfix) with ESMTPS id 4gsLVp39VqzB0XZ; Fri, 3 Jul 2026 19:35:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1783100114; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AL2ttyRF7x+2MOi01b0OtmwVVZQqH11xtCLGPHnMNjk=; b=lfhkTJSbCP8k9euq98NSvcbvs0MJqD6A+jbtdMXPE84r1fSFWtllt939OolPNMr447HU++ 8JDfMqzk70HpudiEmumi96DA7qydRSutOFT5wCmdqFA4UfBtdEPMoYTRZzMphFmijADY7v ML3J0ErPqMSt2ZqLY3Lrq8RU6bbHdUX/djeL9Qw2FOmKwm+yAsiLGSQUlksLMCJsQJfHq6 GOsEl+ZhQP5pCwF8aFxuP2ZT21iCArltt/M5k2AzN2TxIqTCoU3vriHCx4YL98/SH4IGLp XmWQHxWHqhPz68eI3AXNaIGppTukeBBis+sfsVagZv+xHBuwS503P6OzbJeMeA== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::102 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Fri, 3 Jul 2026 19:35:00 +0200 Message-ID: <6edfcc51e0855bfd34286b86d4e7f26bb3bcd3f7.1783099626.git.ralf@mandelbit.com> In-Reply-To: <981d2ea51cca45138210aa52c6e5a0e55c0da7a0.1783099626.git.ralf@mandelbit.com> References: <981d2ea51cca45138210aa52c6e5a0e55c0da7a0.1783099626.git.ralf@mandelbit.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4gsLVp39VqzB0XZ X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-2.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: ovpn queues several work items whose callbacks execute module text. These works currently run on the global system workqueues, so module exit has no driver-owned drain point that guarantees the callba [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-Headers-End: 1wfhna-000734-UM Subject: [Openvpn-devel] [PATCH ovpn net v4 2/3] ovpn: run deferred work on a module-owned workqueue X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1869716016653255244 X-GMAIL-MSGID: 1869716016653255244 ovpn queues several work items whose callbacks execute module text. These works currently run on the global system workqueues, so module exit has no driver-owned drain point that guarantees the callbacks have fully returned before the module text can be freed. Object references protect the objects used by the callbacks, but they do not prove that a workqueue function has returned. In particular, a worker can drop the final reference that unblocks device teardown while it is still executing ovpn code. Add a module-owned workqueue and queue all ovpn work items on it. Destroy the workqueue during module exit, after unregistering the rtnl link ops and netlink family and before the final RCU barrier, so no ovpn work item can outlive the module text. The per-device delayed keepalive work remains explicitly disabled during netdev teardown (disable_delayed_work_sync in ndo_uninit), since destroy_workqueue does not flush delayed work that is still only pending on its timer. Fixes: 3ecfd9349f40 ("ovpn: implement keepalive mechanism") Fixes: 11851cbd60ea ("ovpn: implement TCP transport") Signed-off-by: Ralf Lici --- Changes since v3 https://lore.kernel.org/openvpn-devel/49f38f89340e18ed30543d3990a7a7e20595b6af.1783080055.git.ralf@mandelbit.com/ - Replace the RCU-deferred peer netdev reference release with a module-owned workqueue that drains all ovpn work callbacks before module text can be freed. drivers/net/ovpn/main.c | 20 ++++++++++++++++++-- drivers/net/ovpn/ovpnpriv.h | 4 ++++ drivers/net/ovpn/peer.c | 8 ++++---- drivers/net/ovpn/tcp.c | 9 ++++----- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/drivers/net/ovpn/main.c b/drivers/net/ovpn/main.c index 9993c1dfe471..984b35398c36 100644 --- a/drivers/net/ovpn/main.c +++ b/drivers/net/ovpn/main.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +27,9 @@ #include "tcp.h" #include "udp.h" +/* module-owned workqueue on which all ovpn-specific work is queued */ +struct workqueue_struct *ovpn_wq; + static void ovpn_priv_free(struct net_device *net) { struct ovpn_priv *ovpn = netdev_priv(net); @@ -233,11 +237,18 @@ static struct rtnl_link_ops ovpn_link_ops = { static int __init ovpn_init(void) { - int err = rtnl_link_register(&ovpn_link_ops); + int err; + ovpn_wq = alloc_workqueue("ovpn", 0, 0); + if (!ovpn_wq) { + pr_err("ovpn: cannot allocate workqueue\n"); + return -ENOMEM; + } + + err = rtnl_link_register(&ovpn_link_ops); if (err) { pr_err("ovpn: can't register rtnl link ops: %d\n", err); - return err; + goto destroy_wq; } err = ovpn_nl_register(); @@ -252,6 +263,9 @@ static int __init ovpn_init(void) unreg_rtnl: rtnl_link_unregister(&ovpn_link_ops); +destroy_wq: + destroy_workqueue(ovpn_wq); + ovpn_wq = NULL; return err; } @@ -259,6 +273,8 @@ static __exit void ovpn_cleanup(void) { ovpn_nl_unregister(); rtnl_link_unregister(&ovpn_link_ops); + destroy_workqueue(ovpn_wq); + ovpn_wq = NULL; rcu_barrier(); } diff --git a/drivers/net/ovpn/ovpnpriv.h b/drivers/net/ovpn/ovpnpriv.h index 5898f6adada7..84499140e4bd 100644 --- a/drivers/net/ovpn/ovpnpriv.h +++ b/drivers/net/ovpn/ovpnpriv.h @@ -15,6 +15,10 @@ #include #include +struct workqueue_struct; + +extern struct workqueue_struct *ovpn_wq; + /** * struct ovpn_peer_collection - container of peers for MultiPeer mode * @by_id: table of peers index by ID diff --git a/drivers/net/ovpn/peer.c b/drivers/net/ovpn/peer.c index a09d61296425..976a5de13c80 100644 --- a/drivers/net/ovpn/peer.c +++ b/drivers/net/ovpn/peer.c @@ -61,7 +61,7 @@ void ovpn_peer_keepalive_set(struct ovpn_peer *peer, u32 interval, u32 timeout) /* now that interval and timeout have been changed, kick * off the worker so that the next delay can be recomputed */ - mod_delayed_work(system_percpu_wq, &peer->ovpn->keepalive_work, 0); + mod_delayed_work(ovpn_wq, &peer->ovpn->keepalive_work, 0); } /** @@ -1285,7 +1285,7 @@ static time64_t ovpn_peer_keepalive_work_single(struct ovpn_peer *peer, netdev_dbg(peer->ovpn->dev, "sending keepalive to peer %u\n", peer->id); - if (schedule_work(&peer->keepalive_work)) + if (queue_work(ovpn_wq, &peer->keepalive_work)) ovpn_peer_hold(peer); } @@ -1377,8 +1377,8 @@ void ovpn_peer_keepalive_work(struct work_struct *work) netdev_dbg(ovpn->dev, "scheduling keepalive work: now=%llu next_run=%llu delta=%llu\n", next_run, now, next_run - now); - schedule_delayed_work(&ovpn->keepalive_work, - (next_run - now) * HZ); + queue_delayed_work(ovpn_wq, &ovpn->keepalive_work, + (next_run - now) * HZ); } unlock_ovpn(ovpn, &release_list); } diff --git a/drivers/net/ovpn/tcp.c b/drivers/net/ovpn/tcp.c index 433bd07a4f1b..475f560ca5b1 100644 --- a/drivers/net/ovpn/tcp.c +++ b/drivers/net/ovpn/tcp.c @@ -151,7 +151,7 @@ static void ovpn_tcp_rcv(struct strparser *strp, struct sk_buff *skb) /* take reference for deferred peer deletion. should never fail */ if (WARN_ON(!ovpn_peer_hold(peer))) goto err_nopeer; - schedule_work(&peer->tcp.defer_del_work); + queue_work(ovpn_wq, &peer->tcp.defer_del_work); ovpn_dev_dstats_rx_dropped(peer->ovpn->dev); err_nopeer: kfree_skb(skb); @@ -283,12 +283,11 @@ static void ovpn_tcp_send_sock(struct ovpn_peer *peer, struct sock *sk) * stream therefore we abort the connection */ ovpn_peer_hold(peer); - schedule_work(&peer->tcp.defer_del_work); + queue_work(ovpn_wq, &peer->tcp.defer_del_work); /* we bail out immediately and keep tx_in_progress set * to true. This way we prevent more TX attempts - * which would lead to more invocations of - * schedule_work() + * which would lead to more invocations of queue_work() */ return; } @@ -485,7 +484,7 @@ static void ovpn_tcp_write_space(struct sock *sk) rcu_read_lock(); sock = rcu_dereference_sk_user_data(sk); if (likely(sock && sock->peer)) { - schedule_work(&sock->tcp_tx_work); + queue_work(ovpn_wq, &sock->tcp_tx_work); sock->peer->tcp.sk_cb.sk_write_space(sk); } rcu_read_unlock(); From patchwork Fri Jul 3 17:35:01 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5088 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:1887:b0:869:83bc:8c48 with SMTP id r7csp2437734max; Fri, 3 Jul 2026 10:35:43 -0700 (PDT) X-Forwarded-Encrypted: i=2; AHgh+RqvNnsv1tvlFQhdvwZqt2lkrUTf93Bwn44EPjDMV4JBRVBypSJIYQoP6x19+9/CoulwuC4yxuzPdUM=@openvpn.net X-Received: by 2002:a05:6870:174c:b0:447:1dd3:19bc with SMTP id 586e51a60fabf-44d17fbd96emr228668fac.2.1783100143737; Fri, 03 Jul 2026 10:35:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1783100143; cv=none; d=google.com; s=arc-20260327; b=NHUB9M5UuvrLLhQE6cBNQiNv8Odqeyga4x9h8/Qmoe1PYbatz5YhJGhGJRB0w6fOG0 NUFa4VEzdKbn1Gf7utZGSdJYCtVZCnDU8lOqQJgL9iXXFHeSWl6A+xN3oQ3TtcgWUpCM nK5CJpGgmxwdwqnHXNLKoJGHFHHSnb5EPd+RttWknvDa1Zel9PwQMmEfQrXdXqReNh0p bla7iqMYZHV95pinrzKFNLN7WhaeMZNKYfWP7lKqnEfc9Y5TB8+TOx4ZujgAmE0cwRbb VoP9P1BrKgQTZJLwV4I9jKtcGs7QKqZ5gZTrBgx5FXG8R4RvwxgAvxvi5aM2GCGSuQXX ZW7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature:dkim-signature; bh=LKwHAwHtmvsCye6DR/czDK1wKfzOpyqDyTZqMZV8ORQ=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=FXSLDTR+zxmiuzpjdPn0u3V0xIYif+wiBNlxvxSq3uU8JqrZxAjRrJCNaw5fMEtifh Ddtys0/edtCqTO25EtiRLI3EId0I2A3y8NsmnaZ3vGgYqFaSKHVgppffbgQY4Nsl3t7R lBm2Hosgj2nQ4c3p3V43koZk/RdmnypOut4nzZCycczdzRL8B4g3xqJhvBlbqryduNON B+beALpIfjN4q/NYIutnKse2MsZu5upJ5nsyVRRxW5ILrP1WThw9heYBSu9wuO3werlo KdioPN1HBH4N17FRjzsklcL/JcPPi9/hyCL4/jdYRiDiDr84qokam2wOi3rCO6G1cnZV Y43g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=ASm5o38c; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=Y1zXr0DA; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=hukpvvMf; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=IAoPUpEp; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 586e51a60fabf-44cfb5d666fsi2006427fac.25.2026.07.03.10.35.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Jul 2026 10:35:43 -0700 (PDT) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=ASm5o38c; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=Y1zXr0DA; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=hukpvvMf; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=IAoPUpEp; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=LKwHAwHtmvsCye6DR/czDK1wKfzOpyqDyTZqMZV8ORQ=; b=ASm5o38cqMOL4dcdBW1yKS39E6 rx5abeDZ0oBN8f6eOo5LCgaG2cXChRq4eb/ZsQgRgmaSC2QbTG/pKs+cUJiC2m414bh39VdC6l4sX AmDu7jdHesMtYjjEaH8v6nqbDPnjRGvvFUBOLLyxsIqwI881elcCJGRpyxmOOsHhTUEM=; Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1wfhnd-0001yw-Nz; Fri, 03 Jul 2026 17:35:38 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1wfhnb-0001yl-PH for openvpn-devel@lists.sourceforge.net; Fri, 03 Jul 2026 17:35:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=SXbWfecXPFHVGMvXgqIb/ZHORrJiGaLCkiYspXYormc=; b=Y1zXr0DAjhBOLl/cz0weENh2/F Ncmfl96B1Y9qXQBIBYgHjdsrEp3IqoAxiHlz176sP90MBitSBaCSD5B1p5KioZ3NeUL1CQGskV7+w M8VdvppSSAnaPFblrWFPHiuqQ1e0GdnUev+i5tiwMX8dCtO+DO1RMC5JUcvJyak9VJ70=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=SXbWfecXPFHVGMvXgqIb/ZHORrJiGaLCkiYspXYormc=; b=hukpvvMfA1bKp4ruXJGJsZrByo Fa4TQVOtvhJE3bYpmph+PQTOTFrDf0i4VNiQVOG9qgICr89J1/3cTU02/2cNkiF0W5I28Vnhjbzlm RUblX9FxaSa2BGEvt7ObdtpKtqAw5bxxkGUDplA7yc9IEKdIk8KyQb51+3q7wjI5davc=; Received: from mout-b-112.mailbox.org ([195.10.208.42]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1wfhnW-00072g-HF for openvpn-devel@lists.sourceforge.net; Fri, 03 Jul 2026 17:35:31 +0000 Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-112.mailbox.org (Postfix) with ESMTPS id 4gsLVq70BXzDx6b; Fri, 3 Jul 2026 19:35:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1783100116; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SXbWfecXPFHVGMvXgqIb/ZHORrJiGaLCkiYspXYormc=; b=IAoPUpEpTN9m85qs2CXRNgW4EWaMrqTA1xZUc9z9vcba9MucZsqvNGRjXmQV6mgnKy6wJv 9q6uGCL148G8mPg/if08lMJYpUAUP/J0vLahhcZx+bhPuvXbafp3sp2JnmbD6ZC9d7bIoZ D+iqImdIJm9EJ6EBcJEZ5RcXrvVeJQtHnHq8ssiQB+X+FEng9iZyUq0qHS2Z+Tfzq7RZBh aGr/Yu7D3xnGtdIDzpT1Mu4tKp8phUE0Gr+ct2t/CfMmv99UZEWkb6TGRmUS+Boybkq80o W4RHLEfZIGJnK6b4XjOseFXhx8DmK5dUQnRFTMO6iAGZHWAC7sUEQLPMzym6Cg== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::102 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Fri, 3 Jul 2026 19:35:01 +0200 Message-ID: In-Reply-To: <981d2ea51cca45138210aa52c6e5a0e55c0da7a0.1783099626.git.ralf@mandelbit.com> References: <981d2ea51cca45138210aa52c6e5a0e55c0da7a0.1783099626.git.ralf@mandelbit.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4gsLVq70BXzDx6b X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-1.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Key slots are released through a kref and the existing release path frees the AEAD transforms from an RCU callback. That is not safe for all crypto implementations: crypto_free_aead can sleep, for exa [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-Headers-End: 1wfhnW-00072g-HF Subject: [Openvpn-devel] [PATCH ovpn net v4 3/3] ovpn: defer key slot crypto freeing to workqueue X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1869716016275381279 X-GMAIL-MSGID: 1869716016275381279 Key slots are released through a kref and the existing release path frees the AEAD transforms from an RCU callback. That is not safe for all crypto implementations: crypto_free_aead can sleep, for example when an async or hardware implementation has teardown work to complete. The AEAD transforms are only used while a key-slot reference is held, so the final kref put is enough to prove that no transform user remains. Queue the final crypto teardown on the ovpn workqueue, where sleeping is allowed, and keep the slot memory itself RCU-freed after the transforms have been released. ovpn_crypto_config_get was the remaining lockless reader of transform state through ovpn_aead_crypto_alg. Make it take a key-slot reference before reading that state, so the transform lifetime is consistently tied to key-slot references. The previous patch drains ovpn_wq during module exit, so queued key-slot teardown work cannot outlive module text. Fixes: 8534731dbf2d ("ovpn: implement packet processing") Signed-off-by: Ralf Lici --- Changes since v3 https://lore.kernel.org/openvpn-devel/ac2842c8e759849c51447126343376dcc793c7ae.1783080055.git.ralf@mandelbit.com/ - Reuse the module-owned ovpn workqueue introduced by patch 2 instead of allocating a crypto-specific workqueue for key-slot teardown. Changes since v2 https://lore.kernel.org/openvpn-devel/b5dfebec718f230783ff47aa354c3b3fa1aa2ed7.1783068961.git.ralf@mandelbit.com/ - Reword the message to note the dependency on patch 1. Changes since v1 https://lore.kernel.org/openvpn-devel/350f6b48c363dde5a8d0bdf7a1b9fd2abb8b1034.1783057762.git.ralf@mandelbit.com/ - Fix a potential AEAD transform UAF in ovpn_crypto_config_get by holding a slot kref while reading the cipher algorithm. drivers/net/ovpn/crypto.c | 15 ++++----------- drivers/net/ovpn/crypto.h | 3 +++ drivers/net/ovpn/crypto_aead.c | 20 ++++++++++++++------ drivers/net/ovpn/crypto_aead.h | 1 - 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/drivers/net/ovpn/crypto.c b/drivers/net/ovpn/crypto.c index 8cb7078a1d93..63efbca64eab 100644 --- a/drivers/net/ovpn/crypto.c +++ b/drivers/net/ovpn/crypto.c @@ -18,20 +18,12 @@ #include "crypto_aead.h" #include "crypto.h" -static void ovpn_ks_destroy_rcu(struct rcu_head *head) -{ - struct ovpn_crypto_key_slot *ks; - - ks = container_of(head, struct ovpn_crypto_key_slot, rcu); - ovpn_aead_crypto_key_slot_destroy(ks); -} - void ovpn_crypto_key_slot_release(struct kref *kref) { struct ovpn_crypto_key_slot *ks; ks = container_of(kref, struct ovpn_crypto_key_slot, refcount); - call_rcu(&ks->rcu, ovpn_ks_destroy_rcu); + queue_work(ovpn_wq, &ks->free_work); } /* can only be invoked when all peer references have been dropped (i.e. RCU @@ -201,14 +193,15 @@ int ovpn_crypto_config_get(struct ovpn_crypto_state *cs, rcu_read_lock(); ks = rcu_dereference(cs->slots[idx]); - if (!ks) { + if (!ks || !ovpn_crypto_key_slot_hold(ks)) { rcu_read_unlock(); return -ENOENT; } + rcu_read_unlock(); keyconf->cipher_alg = ovpn_aead_crypto_alg(ks); keyconf->key_id = ks->key_id; - rcu_read_unlock(); + ovpn_crypto_key_slot_put(ks); return 0; } diff --git a/drivers/net/ovpn/crypto.h b/drivers/net/ovpn/crypto.h index 0e284fec3a75..85834bbd3ec9 100644 --- a/drivers/net/ovpn/crypto.h +++ b/drivers/net/ovpn/crypto.h @@ -10,6 +10,8 @@ #ifndef _NET_OVPN_OVPNCRYPTO_H_ #define _NET_OVPN_OVPNCRYPTO_H_ +#include + #include "pktid.h" #include "proto.h" @@ -45,6 +47,7 @@ struct ovpn_crypto_key_slot { struct ovpn_pktid_recv pid_recv ____cacheline_aligned_in_smp; struct ovpn_pktid_xmit pid_xmit ____cacheline_aligned_in_smp; + struct work_struct free_work; struct kref refcount; struct rcu_head rcu; }; diff --git a/drivers/net/ovpn/crypto_aead.c b/drivers/net/ovpn/crypto_aead.c index 8f07c418622b..332975527734 100644 --- a/drivers/net/ovpn/crypto_aead.c +++ b/drivers/net/ovpn/crypto_aead.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -380,14 +381,19 @@ static struct crypto_aead *ovpn_aead_init(const char *title, return ERR_PTR(ret); } -void ovpn_aead_crypto_key_slot_destroy(struct ovpn_crypto_key_slot *ks) +static void ovpn_aead_crypto_key_slot_free(struct ovpn_crypto_key_slot *ks) { - if (!ks) - return; - crypto_free_aead(ks->encrypt); crypto_free_aead(ks->decrypt); - kfree(ks); +} + +static void ovpn_aead_crypto_key_slot_free_work(struct work_struct *work) +{ + struct ovpn_crypto_key_slot *ks; + + ks = container_of(work, struct ovpn_crypto_key_slot, free_work); + ovpn_aead_crypto_key_slot_free(ks); + kfree_rcu(ks, rcu); } struct ovpn_crypto_key_slot * @@ -420,6 +426,7 @@ ovpn_aead_crypto_key_slot_new(const struct ovpn_key_config *kc) ks->encrypt = NULL; ks->decrypt = NULL; + INIT_WORK(&ks->free_work, ovpn_aead_crypto_key_slot_free_work); kref_init(&ks->refcount); ks->key_id = kc->key_id; @@ -453,7 +460,8 @@ ovpn_aead_crypto_key_slot_new(const struct ovpn_key_config *kc) return ks; destroy_ks: - ovpn_aead_crypto_key_slot_destroy(ks); + ovpn_aead_crypto_key_slot_free(ks); + kfree(ks); return ERR_PTR(ret); } diff --git a/drivers/net/ovpn/crypto_aead.h b/drivers/net/ovpn/crypto_aead.h index 65a2ff307898..fae3b585a43b 100644 --- a/drivers/net/ovpn/crypto_aead.h +++ b/drivers/net/ovpn/crypto_aead.h @@ -22,7 +22,6 @@ int ovpn_aead_decrypt(struct ovpn_peer *peer, struct ovpn_crypto_key_slot *ks, struct ovpn_crypto_key_slot * ovpn_aead_crypto_key_slot_new(const struct ovpn_key_config *kc); -void ovpn_aead_crypto_key_slot_destroy(struct ovpn_crypto_key_slot *ks); enum ovpn_cipher_alg ovpn_aead_crypto_alg(struct ovpn_crypto_key_slot *ks);