From nobody Sun May 24 18:40:58 2026 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69BB03B95F2 for ; Fri, 22 May 2026 09:17:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779441468; cv=none; b=WNr5KhC2MpFmwThFL5/YEB6u5J6l4qNLG5Sj7B+8LTtLOmZTtEjqYFRm8VgeKNNvjciD0DptWXa7TiwC8JJS2rA5ZPqCFaMgJAVTa/CFvdyIC69aLKgFJyDxaUZJ15HM8rkco3WEpVDiqbEHNNnxvymO+TZ7kPU3jSoN8dzNhew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779441468; c=relaxed/simple; bh=HJlZ8TI3+tSU99T/0bHZwWtEb0SFSnsG7S0YfidSIJ8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=oghPCTwkVkpJSgYrppj0c3X0QjNjI9pBtYQYUlqv8BZpnBDxdONFz1pNLGXlM8FlWEKZWuW8T5B3suQaQhqaP/nYsA+VvxOCwepb/Q9/ef1pI/xj9Ruso4+yG0OAMXja3yIvAqw99CB2omMZE+3yXigdRetN/NIuxD89HIpt0+k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hd/nvuFy; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hd/nvuFy" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-83f4991ac51so263801b3a.2 for ; Fri, 22 May 2026 02:17:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779441466; x=1780046266; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=lFK655wZK0lyhsPu8M6I8j5XnIjP+tTr87dEjsrnrnI=; b=hd/nvuFymTMMKN+p1x+ytJeFZ+DpN3csmGdMgP71hcH6mlHuCnRSwvglmt0adNL3Zp I5InicC6t3+kqNgMJ3ovgxk0XIDTZ3XolPSHJ/RZmt3PuVM73pfL5FBhOV3vnYtKgaaJ lfNzH4hVttJFnlBVvpuKY4hKbivYdNaWPT6OvmBgXafC74zbPnbf2bMyHRz0FTCKbicp gPbBH9ozR+YULYPebk7IqPH3qBitIyFi1gA910Vcp6fnBri0joy+gD7DtymaTtpGv0IX kkv+Yl4kiEqQLY197td4SYOruBP0c8UKsE+xF7GeQ4xH2sN3sWv5e00PkROm4VZnDhN2 sVkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779441466; x=1780046266; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=lFK655wZK0lyhsPu8M6I8j5XnIjP+tTr87dEjsrnrnI=; b=FxTaocKpgJvOnScg+02CCVrAEKWb4dXUhvGFZkdntGqOgnSxuYZNgxAjTBOj05Nv5J iOWRz1Iqsx7jF1tBGCL9cs2Vw61bJ5zIiPt1p9EwGyOJmSejT2rGiZNtt3uqpCdkPp+y hxO6faTNysg4P01HJj/eW4f0TEJLjrT8ksQysnp+Mn07+QECCGdYu9vR3S8nCqqTX2qK 0S/R0Gi8TXkk8nX+yV53/EKMxyny27zQPYwhOujbm28kt+pcJoviJlspqrmCcUnwU0/9 kUt0OpwEz2yA7U+9eZHt14Nii0CYqlPQLia+f3JcanKOPzuFjJwsViunHiFDFjRKFGJV 7cLg== X-Forwarded-Encrypted: i=1; AFNElJ8eyHQTVwm0+akms3ukTMPiDvg5PY0nXdxt3vfaF40TVm9os6D7CRLOxJGKZmwHs/JEw7vAKwzUYQbHjy0=@vger.kernel.org X-Gm-Message-State: AOJu0YxbwRky/+fxMvPWbzyxuWGxLqRFqk8oJpwMl2zv+l8mNMF/f6A0 wscjHGv+GOKB9fdr+442mJ38yICazQl7NfdsNSziVwgJZNMxPZv64kjEJ/qat2fa X-Gm-Gg: Acq92OFWSv5ANot2l6XITf5nI3pFDN/pv/gq0OUXoJzaDVYd8/WXkghhwo9EAyIGLkw yv7bLijuZfGPvLXJimn8oWPT1iXHmKEXRo6m8k/8IuyJhI8eKklkTicMUpVOMG/G6qQlKhTGZBg 69mG5c45jCGH4UEOdH58E7ZFUYR+3HiLvBLuswGRmC+l3UKSkRUairs4M2OliPvfiExNMd8zPF9 t2k/tDF8FKl7mtOCccPFiZrXZgpIgj/jCUQ5DWbDoCQQwGNt/pJcOHgsg4J00r13/BtOPsuh0bt uWbY70fD4DWIad44mdPHzfhr61IaozI+dBds6iy+hQziZVtab2Q/ORbJQscWdJvsXFeU/stOOr6 BTPEgTHzhRVq4LmWeLxnMynrruXHEjxFtU/NiSJFZv8c+2IKme6nm46Z5n90h6kJhmzt1OoYcgo 9aNP35nE80DF4wtv68NvEmbr/aidA= X-Received: by 2002:a05:6a00:2d07:b0:835:443e:4be5 with SMTP id d2e1a72fcca58-8415f40ccf0mr1605564b3a.1.1779441466347; Fri, 22 May 2026 02:17:46 -0700 (PDT) Received: from kali ([2402:e280:3d7c:a2:536a:b505:93f5:9d5d]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84164fb28d5sm1517038b3a.41.2026.05.22.02.17.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 02:17:45 -0700 (PDT) From: Pavitra Jha To: antonio@openvpn.net Cc: sd@queasysnail.net, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Pavitra Jha Subject: [PATCH v2] ovpn: fix peer refcount leak in TCP error paths Date: Fri, 22 May 2026 05:17:17 -0400 Message-ID: <20260522091718.270956-1-jhapavitra98@gmail.com> X-Mailer: git-send-email 2.53.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 Content-Type: text/plain; charset="utf-8" When either the TCP RX or TX error path calls ovpn_peer_hold() followed by schedule_work(&peer->tcp.defer_del_work), and the work item is already pending from the other path, schedule_work() returns false and the work runs only once. Since ovpn_tcp_peer_del_work() calls ovpn_peer_put() exactly once, the extra reference taken by the losing path is never dropped, leaking the peer object. The race window: CPU0 (strparser/RX error): CPU1 (tcp_tx_work/TX error): ovpn_peer_hold() <- refcnt+1 ovpn_peer_hold() <- refcnt+2 schedule_work() <- queued schedule_work() <- NO-OP (work already pending) ovpn_tcp_peer_del_work runs: ovpn_peer_del() ovpn_peer_put() <- refcnt+1 <- peer never freed Fix by checking the return value of schedule_work() in both paths and calling ovpn_peer_put() to drop the extra reference if the work was already pending. ovpn_peer_hold() is kept unconditional in the TX path as it cannot fail at that point. Fixes: a6a5e87b3ee4 ("ovpn: avoid sleep in atomic context in TCP RX error p= ath") Cc: stable@vger.kernel.org Signed-off-by: Pavitra Jha --- Changes since v1: - TX path: keep ovpn_peer_hold() unconditional per Antonio Quartulli's review; only check schedule_work() return value - Link: https://lore.kernel.org/netdev/20260521083739.65061-1-jhapavitra9= 8@gmail.com/ --- drivers/net/ovpn/tcp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/ovpn/tcp.c b/drivers/net/ovpn/tcp.c index d651ce85c..2c7d830e7 100644 --- a/drivers/net/ovpn/tcp.c +++ b/drivers/net/ovpn/tcp.c @@ -283,9 +283,9 @@ static void ovpn_tcp_send_sock(struct ovpn_peer *peer, = struct sock *sk) /* in case of TCP error we can't recover the VPN * stream therefore we abort the connection */ - if (ovpn_peer_hold(peer)) - if (!schedule_work(&peer->tcp.defer_del_work)) - ovpn_peer_put(peer); + ovpn_peer_hold(peer); + if (!schedule_work(&peer->tcp.defer_del_work)) + ovpn_peer_put(peer); =20 /* we bail out immediately and keep tx_in_progress set * to true. This way we prevent more TX attempts --=20 2.53.0