From patchwork Thu Nov 26 14:45:09 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5797 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:91c9:10b0:11b:d6c:f273 with SMTP id tl9-n1csp7290290lad; Thu, 26 Nov 2026 06:45:40 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHa74wfvKYRZJ3NjxN/GTsaaequwBLw5Te1DEV/VUKkCnch3SaLi7Ygu01sCv0+T/oFiPTVEZLvobk=@openvpn.net X-Received: by 2002:a05:6a21:6b85:b0:40a:4b8e:b7f7 with SMTP id adf61e73a8af0-40a4b8ec379mr1559022637.45.1795704339631; Thu, 26 Nov 2026 06:45:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795704339; cv=none; d=google.com; s=arc-20260327; b=WWZNjjULUNKpOjZ6EBh9AY3Js67O3Lgbr/EXytsDM/9wvrp0cnUrZm8DbqD5uBF1jB KUCNs8rIRy4wxUq7gSeWmCXBACwa6oJumlFRY2l60pHjtETsuogQwkCTW+q0JVgRb4QA GPA7M+/gfsWFDWq71DF97pJ1UgX1k8bRobDYCJ/Ac7ElC+98+MDLpZHivHId51HH6rs6 0cQqplljxEyHTw1XWc1gi05+asROIIrRLk7wp7MryIhU6QkoKSeAL2DQb7Vk6husVADs xaJMesoo5TJtX+YB7QhsUoARFd/sfQ4RBQfEB8ib8Yx6DprqPI/kjS6TtcyuYqM0P8qc oddA== 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=br2RjapdmEXmxhQCw3VkiZ+zkBDmULz9fphJkXCReug=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=F9JC5B8j4IocAeBWLLL+SvBPWIZMpNBM1S7Gi5rFIhIeHhC5RGEwdFMuFBzn1xG2wq kJZhP80XT6wrFtNZgyI4Ql6NK0+qGkXRUKCoprh15iN1I75MVgI5rwdjCDNqPUngwUXb X9at2w4QgcyPdBu99Akkg1gmOQ9rPkG8LK8cNInN4qkC9or2doTSmJ1DvlhA/bw0zgov GI6hnF/iWbpCxst36ugADIcWj9mAoXAzD9vGaZDGagT1i4MtkER3emnKujhS2b/Y3x9O fwNavr1H1lPCNoDZBUVur1R0EvCFus5Ci1swCAH485j66nIIAwk7IG3NYbIVktqNELHo e3eA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=hoeSxCc4; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=W+OZguz5; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=TBADoS1x; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=NDgZMXNW; 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 41be03b00d2f7-cde6d0125c7si31294384a12.109.2026.11.26.06.45.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Nov 2026 06:45:39 -0800 (PST) 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=hoeSxCc4; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=W+OZguz5; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=TBADoS1x; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=NDgZMXNW; 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-Unsubscribe-Post: List-Owner; bh=br2RjapdmEXmxhQCw3VkiZ+zkBDmULz9fphJkXCReug=; b=hoeSxCc4iixcK8 5PxK6QEZ1mVwLow7nnCDX0OCs/LXI114hzAN288aLW8mbEviMxdvh9ZcSeS3AU5Gi/+d+3aa4hrEH Pu9m90kb2ZShWfTLfqLXJuGaHrCjHgbmvr1vnfHNqZHOwAp/9omb43SAPmFulEk1+DYMnOMAaWSZX SnE=; 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.100.1) (envelope-from ) id 1xWajC-000000004tW-1d3C; Thu, 26 Nov 2026 14:45:38 +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.100.1) (envelope-from ) id 1xWajA-000000004tE-09Ez for openvpn-devel@lists.sourceforge.net; Thu, 26 Nov 2026 14:45: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:To:From:Sender:Reply-To:Cc: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-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=0GiUkp4sKBvffAbm8LzEKrsFioHGHb8CGIcLMPYDKc0=; b=W+OZguz56R1gyTIUF7XkNjv5i3 YvCHjo0FK/fMl1Od6gntyYFlb1X+jrLy2rvxAzOvuyEoJb7WoNqg5CxIAZeGxZZdhiiboxOWThExh Ke5YlSQb8gDj69QVS9W6PLNIiFyQLTHzAvLY3Ob9cDnu0NMELufdI9nl8/iimZDa6OfI=; 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:To:From:Sender:Reply-To:Cc: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-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=0GiUkp4sKBvffAbm8LzEKrsFioHGHb8CGIcLMPYDKc0=; b=TBADoS1xLR0zHr1Z2FtORUge2o FALjbAJB0JLjAJPZe+nlfqgh18meOBu4/KyRDGeFj2wzATayaIrED9JUe72iQcmPb+dTWroERnPMH u/5A9YLOZEg9gglibTAVsyJUn5j1/tD13xmgmvAbOcV2c7CCYRDUiTT786vXIgc83hvE=; Received: from mout-b-105.mailbox.org ([195.10.208.50]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xWaj8-000000001wm-1TAX for openvpn-devel@lists.sourceforge.net; Thu, 26 Nov 2026 14:45:35 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-105.mailbox.org (Postfix) with ESMTPS id 4jZzqR0FRmz9sKM for ; Thu, 26 Nov 2026 15:45:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1795704323; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0GiUkp4sKBvffAbm8LzEKrsFioHGHb8CGIcLMPYDKc0=; b=NDgZMXNWeG8/lnysR0JzR1Dgn/T3pQPKCdm92GHI8i9bTIDKN4M+8Ss8snnxz2q+sKcBTI xbMq0QchH6IjKh36pa7Zr8knN6SldEfOJGoHYHJRO5JHoJy+xvPIJLXLUnE/fTdxv4nwL4 ZYG4PhgHZ7hP0KE2w8uWDRFtMnoEoV+53+KapctXsooUZ/N/eWLJQymmDizDPI5I8kX3b1 KXlSwE8XSICtr/0NR3tgI3qNbQf0DjC08W4i/g596noeYfteAtKvEdQx9G7ELh2MNOeRUw WI4R4kHUS+HbPZ32LKP8U0pCbh94A8DrffZfwQ1OsPX7uEnsk4p+Jy2vnfmAjw== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::1 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Thu, 26 Nov 2026 15:45:09 +0100 Message-ID: X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jZzqR0FRmz9sKM 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: When the peer endpoint changes, the new bind is published with RCU before the dst cache is reset. TX does not take peer->lock before the cache lookup, so a concurrent transmitter can pick up the new b [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -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 -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 X-Headers-End: 1xWaj8-000000001wm-1TAX Subject: [Openvpn-devel] [PATCH ovpn net 1/3] ovpn: reset dst cache before publishing a new bind 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: 1882932473788647309 X-GMAIL-MSGID: 1882932473788647309 When the peer endpoint changes, the new bind is published with RCU before the dst cache is reset. TX does not take peer->lock before the cache lookup, so a concurrent transmitter can pick up the new bind and still get a hit on the entry cached for the old one. The packet then goes out over the old route and cached source address but towards the new remote. On a cross-family float, dst_cache_get_ip4 or dst_cache_get_ip6 would also return a dst of the wrong family, which is then passed to the other family's xmit helper. Reset the cache before publishing the new bind, both when the endpoint is updated from RX and when it is changed via netlink. Both run under peer->lock, which a TX must hold to store a new dst, and the store requires the bind to still be the current one. Therefore, once the new bind is visible no stale entry can be repopulated. A failed bind update at worst costs one extra cache miss. Fixes: aea934a221ec ("ovpn: replace bind when learning local endpoint") Fixes: 1d36a36f6d53 ("ovpn: implement peer add/get/dump/delete via netlink") Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260921102215.3599702-1-antonio%40openvpn.net?part=5 Signed-off-by: Ralf Lici --- drivers/net/ovpn/netlink.c | 7 ++++++- drivers/net/ovpn/peer.c | 10 +++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/net/ovpn/netlink.c b/drivers/net/ovpn/netlink.c index 5432bc2eb8e8..6231d87304e1 100644 --- a/drivers/net/ovpn/netlink.c +++ b/drivers/net/ovpn/netlink.c @@ -333,6 +333,12 @@ static int ovpn_nl_peer_modify(struct ovpn_peer *peer, struct genl_info *info, */ local_ip = ovpn_nl_attr_local_ip(attrs); + /* reset the cache before publishing the new bind, so that + * concurrent TX cannot pair it with a route cached for the + * old one + */ + dst_cache_reset(&peer->dst_cache); + /* set peer sockaddr */ ret = ovpn_peer_reset_sockaddr(peer, &ss, local_ip); if (ret < 0) { @@ -341,7 +347,6 @@ static int ovpn_nl_peer_modify(struct ovpn_peer *peer, struct genl_info *info, ret); goto err_unlock; } - dst_cache_reset(&peer->dst_cache); } /* In a multipeer-to-multipeer setup we may have asymmetric peer IDs, diff --git a/drivers/net/ovpn/peer.c b/drivers/net/ovpn/peer.c index 2067825bb5b6..07f3fd9cbed6 100644 --- a/drivers/net/ovpn/peer.c +++ b/drivers/net/ovpn/peer.c @@ -294,16 +294,16 @@ void ovpn_peer_endpoints_update(struct ovpn_peer *peer, struct sk_buff *skb) goto unlock; } + /* reset the cache before publishing the new bind, so that concurrent TX + * cannot pair it with a route cached for the old one + */ + dst_cache_reset(&peer->dst_cache); + if (unlikely(ovpn_peer_reset_sockaddr(peer, (struct sockaddr_storage *)&ss, local_ip) < 0)) goto unlock; - /* reset the cache only after a successful bind update to avoid useless - * cache misses on concurrent TX - */ - dst_cache_reset(&peer->dst_cache); - /* if only the local address changed, bail out now */ if (!floated) goto unlock; From patchwork Thu Nov 26 14:45:10 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5796 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:91c9:10b0:11b:d6c:f273 with SMTP id tl9-n1csp7290275lad; Thu, 26 Nov 2026 06:45:39 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHM/ABL/lTKVS6xD53gXaxEc2zvJkoSV2lMCogQboEgQt+ib9K1vCr1fEzTCgy4VcuYNEcTEkkNLeI=@openvpn.net X-Received: by 2002:a05:693c:8955:10b0:386:9cae:abef with SMTP id 5a478bee46e88-386bf39f8b9mr8853619eec.36.1795704339001; Thu, 26 Nov 2026 06:45:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795704338; cv=none; d=google.com; s=arc-20260327; b=B+GSBg3T4yfKTX6jkInyqJFx6/h0YnBhjB8xo1M4juO73n0GOseCBkFLot7Df+vQ+H 5K2zSmscnXox+4SwsTf9jImrFjfuCcD+6jYYok8kSrkwSg7jsv9nC4rqQ7WYU5lGK5na hHTs8vCW7+pMCeTs4UBtwvftWEhuNd7XX334QMtTrAUyZaNeY7/uRw49cy2J2jgBusYs NNnca/2L/YSJPX9N2L/VBPf8xokcn0n6tzmC4k1zRbpW6rmX1nzuI1yqyw4tceE8Y28C 5eQw/OvyjVonqM3/I2E5gYS4oUYrfEPAHXf2rDr3q6GcNs9r9633YfUZIgEdKPMLqMmK VWTg== 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=U3gR5npFNvRHmVijsr7xCpIBkrlHKL8EuVynLIN5Ksg=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=hKq2+sbRS2gjIjSkq7kaX9N7BfeLmfGv2xmWeZIgbzQlZN401O1e/f3GOgpjR9idYQ IzGiX3cvpWKXrKlhbBNSyjF2z58tWMTZR7Q7lXZHKtLumV1APf9ZW0Cej6Z9JCJFeKFy nroeWrMXRiBlCCVtPc1QmvwiaTIBTdkY606LXUbYoCdP8vbDRcol31kYWuP745mdN0GD jumGsSYy4ITAe6r+v8FvppBynQh06q82hge8Pu8OLRNu1LzhaNiBmkicCGe8JhcbYnkH X1XZLrpFSonIYpZXTR0Hc9OQSyT57qJKVl55xzecGE5uMuQ+i69x6Gur4W17vyZUTqMD 7z/A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=UdF5E83i; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=bWmjijsx; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=USNLwC85; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=gPj2zirj; 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 5a478bee46e88-385680a729esi51326931eec.56.2026.11.26.06.45.38 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Nov 2026 06:45:38 -0800 (PST) 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=UdF5E83i; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=bWmjijsx; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=USNLwC85; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=gPj2zirj; 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-Unsubscribe-Post: List-Owner; bh=U3gR5npFNvRHmVijsr7xCpIBkrlHKL8EuVynLIN5Ksg=; b=UdF5E83il02uv0 hpnzj4nJXVktv935DWAPQhlYXrth3aQI5GexEXGSIf0J9w/y/f5jW4FYIfHRhCt/41yEkh+vge/xK UbM+CchVw2RwvO85I7q120Q96Wp1PB2n3dd8NqE7duh4BbZfxEaBy7huBvjiSIjp07q5q+ReI/K/s 43U=; 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.100.1) (envelope-from ) id 1xWajA-000000002pr-28nV; Thu, 26 Nov 2026 14:45:36 +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.100.1) (envelope-from ) id 1xWaj8-000000002pi-0d0x for openvpn-devel@lists.sourceforge.net; Thu, 26 Nov 2026 14:45:34 +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:To:From:Sender:Reply-To:Cc: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-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=el9Xe9Gn/y/JbaJ5pFwGrcCjlACs3B2V3KgD26ymDTo=; b=bWmjijsxVNN5y37zeW/2jvb4IH RSjlG7swjQRtxdT+24+l2Zo8X+CbQSWOYcx+5KipN+lpwlYqtYMReb5UQaeTK1CEnjHCD+CwFiOM4 CtbmFxxba63vPKuyodydzwEB/n0YE+WYUNazCzA4rXpB0vl7+2/6aDixvrBBlydLx9Ok=; 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:To:From:Sender:Reply-To:Cc: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-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=el9Xe9Gn/y/JbaJ5pFwGrcCjlACs3B2V3KgD26ymDTo=; b=USNLwC85KcKvdZdu8c49AEGd98 KoCWnRBZwt3UL6o7uysGFVsVe+xwmGVabhtiiP/+ofSmUUfJyomGQZczvktSdYDXb6Y3qISYa3Jsp HsXQxHuS3tKDg/e7v0mF/T3sTCzxgpnBexQy0lLH6X+7cWa/gzotoWkROejhxSLyKwHI=; 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.100.1) id 1xWaj6-000000005rz-0gAE for openvpn-devel@lists.sourceforge.net; Thu, 26 Nov 2026 14:45:34 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-112.mailbox.org (Postfix) with ESMTPS id 4jZzqR4d6Mz5wSY for ; Thu, 26 Nov 2026 15:45:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1795704323; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=el9Xe9Gn/y/JbaJ5pFwGrcCjlACs3B2V3KgD26ymDTo=; b=gPj2zirjihXKX8wy+1rhePUJm8o/MnP81Y5qXXr7JY6yicM2upd97PPvGtET0tyoTv0ft+ D4LP9HCBSupYL0R+W+CYGY4VbF2/vrX9vfy9OBeiWzj+wuF39ZxFRDsTnshXFuyhZv9wbt lcDvsNoN+ujBge1NW1+3+yXkk4npzxv8cp/llM4X7f8B8KFL0uqhq6Euvo462xt7PaAU+g frueIybgkVGebpQ/kBDyulwLmBbnIELNfFzPTSNZjSyh21ryEmrGpkHPs+LIJrcfM5cywE 28EAwutB5PyIPE2gD67kSUFLTqsgCsa64GrKnlotSpWqntp5bDnwrz82JBQ31w== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::1 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Thu, 26 Nov 2026 15:45:10 +0100 Message-ID: <79158eb33d6442ca84b03593596407cee8aaec0c.1795703343.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jZzqR4d6Mz5wSY 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_peer_release queues ovpn_peer_release_rcu, which frees the peer, and only then calls netdev_put, which still dereferences peer->ovpn and peer->dev_tracker. When the last reference is dropped from preemptible process context, for instance in a netlink handler, the task may be preempted right after call_rcu. If a grace period elapses before it runs again, [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -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 -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 X-Headers-End: 1xWaj6-000000005rz-0gAE Subject: [Openvpn-devel] [PATCH ovpn net 2/3] ovpn: release netdev reference from the peer RCU callback 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: 1882932473235006357 X-GMAIL-MSGID: 1882932473235006357 ovpn_peer_release queues ovpn_peer_release_rcu, which frees the peer, and only then calls netdev_put, which still dereferences peer->ovpn and peer->dev_tracker. When the last reference is dropped from preemptible process context, for instance in a netlink handler, the task may be preempted right after call_rcu. If a grace period elapses before it runs again, netdev_put operates on freed memory, and with CONFIG_NET_DEV_REFCNT_TRACKER ref_tracker_free also writes through the stale tracker pointer. Drop the netdev reference from the RCU callback instead, right before freeing the peer, so that the peer is not accessed once it has been queued for freeing. This also keeps the netdev, and therefore the module, pinned until the callback has run, as ovpn_cleanup expects when it waits for it with rcu_barrier. Simply calling netdev_put before call_rcu would let unregistration and module exit complete before the callback is even queued. Fixes: 80747caef33d ("ovpn: introduce the ovpn_peer object") Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260809212142.2249027-1-antonio%40openvpn.net?part=2 Signed-off-by: Ralf Lici --- drivers/net/ovpn/peer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/ovpn/peer.c b/drivers/net/ovpn/peer.c index 07f3fd9cbed6..7c3c33a6068b 100644 --- a/drivers/net/ovpn/peer.c +++ b/drivers/net/ovpn/peer.c @@ -352,6 +352,10 @@ static void ovpn_peer_release_rcu(struct rcu_head *head) * perform it in the RCU callback, when all contexts are done */ dst_cache_destroy(&peer->dst_cache); + /* drop the netdev reference only now, so that unregistration cannot + * complete before this callback has run + */ + netdev_put(peer->ovpn->dev, &peer->dev_tracker); kfree(peer); } @@ -366,7 +370,6 @@ static void ovpn_peer_release(struct ovpn_peer *peer) ovpn_bind_reset(peer, NULL); spin_unlock_bh(&peer->lock); call_rcu(&peer->rcu, ovpn_peer_release_rcu); - netdev_put(peer->ovpn->dev, &peer->dev_tracker); } /** From patchwork Thu Nov 26 14:45:11 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ralf Lici X-Patchwork-Id: 5798 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:91c9:10b0:11b:d6c:f273 with SMTP id tl9-n1csp7290293lad; Thu, 26 Nov 2026 06:45:40 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErE4o2FntRew8kUPxnjpxq0KAEipWWrCL3vrQ9r2F6RKLYj+oVrH6NX0Ws1MToHiYZ4519NNVA7GgYY=@openvpn.net X-Received: by 2002:a05:693c:87d6:20b0:386:bc19:6a30 with SMTP id 5a478bee46e88-386bc196d10mr10492508eec.20.1795704340070; Thu, 26 Nov 2026 06:45:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795704340; cv=none; d=google.com; s=arc-20260327; b=gJpePJ3t0JCnavtblDfVdhl9WEc84fENv3zYsQSsMYD9HfddEg3qVbZKSUmu05UUgZ 7m/aCx7wiJ6FDviCrUIlEEB19qIeNwbAKCJtpwDVjNB9X3GwWa6Vo2OGAsPa63IScrCc P9iEGS682SJ1+x/vBprhJTs8Zxz4s9f9S5WN4wOvoGy/Nxh5+Ls9Jwv8kumqFEwASV+D rc3w+T4YSv0lrIDX3W+kkQ4UzJH8UJu9TlR8UDHBYyVTu9PijqVGywXu+kzCV27JQQk1 PzDUbdq/ypCYYXXUjmvuwvkHr7Q3HeauyqRLJumJDKxVS+dtNF4XNuhCz/n86sGLiard ADnQ== 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=9sxKb5/6kWVbYGCn4VcHHXnFWSRJ3wWLxGxtA055vrk=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=Mf+xqcu+4pyl2PLVHMCzALU4X4Q8EbG8fCki2dhcRp38FuNPPFVXzpBvPKEM98sxmW 3JyeGqzLgfERYQguQ/I8OAJMLtbzBA3yHVp+tJpgBIWB7bRoVUlJwyZjGCTlO6DnAFuz 9ou8I1ce8icLXhmpl/wDXlhMFq3DP4j6H3glZy/cLtL0FDwvj0TPAJgXKBlGvp7fV/tV VhVXCZGDGJpeiIuTiChKHI8PGpyOPewvfMcGfzNYlXI36rFeU52RzDtD4kqfXUOJ6hG7 gI4JtZg1XWomUbn0iieu9W1SPRsqXmMzc3RkDV0rCfjTXSx6CA8oNt7r5n87W+DDKAaf fwKQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=FwMNtuYL; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=cvTaahzu; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=F8NENXUU; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=BKmaDFdc; 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 5a478bee46e88-386e563f90asi2509970eec.29.2026.11.26.06.45.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Nov 2026 06:45:39 -0800 (PST) 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=FwMNtuYL; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=cvTaahzu; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=F8NENXUU; dkim=neutral (body hash did not verify) header.i=@mandelbit.com header.s=MBO0001 header.b=BKmaDFdc; 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-Unsubscribe-Post: List-Owner; bh=9sxKb5/6kWVbYGCn4VcHHXnFWSRJ3wWLxGxtA055vrk=; b=FwMNtuYLkbwTaq 4QLe0fAiqgJxv22WTL4CMd+zw0VryjYbv+cTO1izup/hA5AOZpKVtg77a7Ft8SIQxcDcyR1xH3TLR YTHZHrtRlcyRsqvW2qF9JJSn2aJlFGh15jC/TjmDfvnEXnJtq5ECZMQ9aYyxCGhx9nEXqUjyRd9Zw TIo=; Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xWajA-0000000026I-1QPj; Thu, 26 Nov 2026 14:45:36 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xWaj8-0000000026A-3MAK for openvpn-devel@lists.sourceforge.net; Thu, 26 Nov 2026 14:45:34 +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:To:From:Sender:Reply-To:Cc: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-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=dvjJMThrQgVrj8I/heGGh11qur/Laj/reaj7pGoI8tQ=; b=cvTaahzuAcTnfZqfLGTcxr2fbb GhCK95a1k1Ybf/YQGHJOw0jU9dDPTTAelPHKOZr7iKXFZTOHzK3NQqNkRrHC2VLkcU0tPtk6Ild4i acJwnodiqpEmgYTrl5OIJ/c5hQ5hgF38aFtOwkH1BNhHcCaSIufw08LD3UIr3carsO68=; 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:To:From:Sender:Reply-To:Cc: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-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=dvjJMThrQgVrj8I/heGGh11qur/Laj/reaj7pGoI8tQ=; b=F8NENXUUeZ9YJKgdSrRYq72O3r 1ZWY8CSGJvCiZutBuGuerwOD2KTrRMeyL0THxDIPSiTxSn03zxZ/LKCgDNjGqIdQaoTVH4ZGl+VjO fZepEWXqJJ33XWjeEhuT/K0m5tdeUAonZ3aFLRrA7ytBbzf7oGOed8YXk5VfHLbJJP7k=; Received: from mout-b-110.mailbox.org ([195.10.208.55]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xWaj6-000000005s0-25pX for openvpn-devel@lists.sourceforge.net; Thu, 26 Nov 2026 14:45:34 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-b-110.mailbox.org (Postfix) with ESMTPS id 4jZzqR6hMgzNlc8 for ; Thu, 26 Nov 2026 15:45:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mandelbit.com; s=MBO0001; t=1795704324; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dvjJMThrQgVrj8I/heGGh11qur/Laj/reaj7pGoI8tQ=; b=BKmaDFdcIWEZDvGgxeNuJmOHphES8W2k1znoyK2xfd9FSEQPZzx95P/qF9Wqce3xI0hE4v VFQ74OD3VjT/lI+5gCHwYzTsWMZG8+hJMmGqfxeYERBZBI3V1jToj3+Y9TBkDM+6OCZtdP nobHuaUzFDdpSGq21HbgKN5dBpHFQDDU8Br5R6f3o/JGi+T+XecQPJDnO5JHqnBdUIU1Ji /rmeG5oKYFwXNWFdq2tGrd7iZoDuHNxbsCXoIA3umLYOL8Jr8vVcNOO83bn8vlhFXhyZj5 t8Fu/wOxbCyRSDkJndaLkAi+KriEM9pFruqzrGqEkuVPRjFYUaNjE38Z6wQKGw== Authentication-Results: outgoing_mbo_mout; dkim=none; spf=pass (outgoing_mbo_mout: domain of ralf@mandelbit.com designates 2001:67c:2050:b231:465::1 as permitted sender) smtp.mailfrom=ralf@mandelbit.com From: Ralf Lici To: openvpn-devel@lists.sourceforge.net Date: Thu, 26 Nov 2026 15:45:11 +0100 Message-ID: <4941179e211663717b4a91a7462238d6d7cbce95.1795703343.git.ralf@mandelbit.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Queue-Id: 4jZzqR6hMgzNlc8 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: The duplicate VPN address checks only verify that the command fails, so they also pass if it fails for an unrelated reason. The creation checks use OVPN_NUM_PEERS + 1 as the new peer ID, but the UDP server loads the whole peers file regardless of OVPN_NUM_PEERS. When the variable is overridden with a smaller value the ID i [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -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 -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 X-Headers-End: 1xWaj6-000000005s0-25pX Subject: [Openvpn-devel] [PATCH ovpn net 3/3] selftests: ovpn: check the error of duplicate VPN address tests 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: 1882932473632523984 X-GMAIL-MSGID: 1882932473632523984 The duplicate VPN address checks only verify that the command fails, so they also pass if it fails for an unrelated reason. The creation checks use OVPN_NUM_PEERS + 1 as the new peer ID, but the UDP server loads the whole peers file regardless of OVPN_NUM_PEERS. When the variable is overridden with a smaller value the ID is already in use, and ovpn_peer_add_mp fails with -EEXIST before looking at the VPN address. The update checks use peer 2, which does not exist in TCP mode with OVPN_NUM_PEERS=1, and would fail with -ENOENT. Use a fixed ID that never clashes with the peers files, skip the update checks when peer 2 is not configured, and make all of them require "Address already in use" in the command output so that they only pass on a real address conflict. Fixes: 006208026819 ("selftests: ovpn: validate peer VPN addresses") Link: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260921102215.3599702-1-antonio%40openvpn.net?part=11 Signed-off-by: Ralf Lici --- tools/testing/selftests/net/ovpn/common.sh | 21 +++++++++++++++++ tools/testing/selftests/net/ovpn/test.sh | 26 ++++++++++++++++------ 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/net/ovpn/common.sh b/tools/testing/selftests/net/ovpn/common.sh index da732c64ffea..7c8bf260a588 100644 --- a/tools/testing/selftests/net/ovpn/common.sh +++ b/tools/testing/selftests/net/ovpn/common.sh @@ -65,6 +65,19 @@ ovpn_cmd_run() { fi case "${mode}" in + fail:*) + # The mode is "fail:", as set by ovpn_cmd_fail_msg. Strip + # the "fail:" prefix with ${mode#fail:} to get the expected + # error message and look for it in the command output. + if [[ "${rc}" -eq 0 ]]; then + ret=1 + elif ! grep -qF "${mode#fail:}" "${output_file}"; then + cat "${output_file}" + printf '%s\n' \ + "${label}: expected error \"${mode#fail:}\": $*" + ret=1 + fi + ;; ok) if [[ "${rc}" -ne 0 ]]; then cat "${output_file}" @@ -100,6 +113,14 @@ ovpn_cmd_fail() { ovpn_cmd_run fail "$@" } +# like ovpn_cmd_fail, but the command must also print the given error message +ovpn_cmd_fail_msg() { + local msg="$1" + + shift + ovpn_cmd_run "fail:${msg}" "$@" +} + ovpn_run_bg() { local pid_var="$1" diff --git a/tools/testing/selftests/net/ovpn/test.sh b/tools/testing/selftests/net/ovpn/test.sh index 0762fa83e4b5..5bfa3c8a5fc2 100755 --- a/tools/testing/selftests/net/ovpn/test.sh +++ b/tools/testing/selftests/net/ovpn/test.sh @@ -74,7 +74,10 @@ ovpn_set_peer_vpn_addr() { ovpn_run_vpn_addr_validation() { local addr local peer1_addr4 - local test_peer_id=$((OVPN_NUM_PEERS + 1)) + # must not match any peer ID in the peers files, regardless of + # OVPN_NUM_PEERS, as peer ID conflicts are checked before VPN addresses + local test_peer_id=100 + local eaddrinuse="Address already in use" local test_peer_addr6="2001:db8::2" # Do not include 0.0.0.0 or :: here. They are invalid on creation, but # clear one address family on update and are valid if the other remains. @@ -98,7 +101,8 @@ ovpn_run_vpn_addr_validation() { ovpn_new_test_peer "${test_peer_id}" "${addr}" done - ovpn_cmd_fail "reject duplicate IPv4 address on peer creation" \ + ovpn_cmd_fail_msg "${eaddrinuse}" \ + "reject duplicate IPv4 address on peer creation" \ ovpn_new_test_peer "${test_peer_id}" "${peer1_addr4}" ovpn_cmd_fail "reject clearing the last peer VPN address" \ ovpn_set_peer_vpn_addr 1 0.0.0.0 @@ -108,15 +112,23 @@ ovpn_run_vpn_addr_validation() { ovpn_set_peer_vpn_addr 1 "${addr}" done - ovpn_cmd_fail "reject duplicate IPv4 address on peer update" \ - ovpn_set_peer_vpn_addr 2 "${peer1_addr4}" + # peer 2 only exists when at least two peers are configured + if [ "${OVPN_NUM_PEERS}" -ge 2 ]; then + ovpn_cmd_fail_msg "${eaddrinuse}" \ + "reject duplicate IPv4 address on peer update" \ + ovpn_set_peer_vpn_addr 2 "${peer1_addr4}" + fi ovpn_cmd_ok "add peer IPv6 address" \ ovpn_set_peer_vpn_addr 1 "${test_peer_addr6}" - ovpn_cmd_fail "reject duplicate IPv6 address on peer creation" \ + ovpn_cmd_fail_msg "${eaddrinuse}" \ + "reject duplicate IPv6 address on peer creation" \ ovpn_new_test_peer "${test_peer_id}" "${test_peer_addr6}" - ovpn_cmd_fail "reject duplicate IPv6 address on peer update" \ - ovpn_set_peer_vpn_addr 2 "${test_peer_addr6}" + if [ "${OVPN_NUM_PEERS}" -ge 2 ]; then + ovpn_cmd_fail_msg "${eaddrinuse}" \ + "reject duplicate IPv6 address on peer update" \ + ovpn_set_peer_vpn_addr 2 "${test_peer_addr6}" + fi ovpn_cmd_ok "clear peer IPv4 address" \ ovpn_set_peer_vpn_addr 1 0.0.0.0