[Openvpn-devel,ovpn-net-next] ovpn: only signal sk readable if user_queue has packets
| Message ID | 20251014101948.250823-1-ralf@mandelbit.com |
|---|---|
| State | Awaiting Upstream |
| Headers |
Return-Path: <openvpn-devel-bounces@lists.sourceforge.net>
Delivered-To: patchwork@openvpn.net
Received: by 2002:a05:7000:7d42:b0:72f:f16c:e055 with SMTP id
fr2csp2461595mab;
Tue, 14 Oct 2025 03:47:34 -0700 (PDT)
X-Forwarded-Encrypted: i=2;
AJvYcCUahJBXgGVZgWs1TLw5MiGFLFjfW93D+rc0r503cSASC38ZRuiCfVtBfpL8zdxa+Yf5HGkAb41r9XM=@openvpn.net
X-Google-Smtp-Source:
AGHT+IHPPKQw6qLOHyDO6CQnI5xfBzQ0QeZ7VdviR9PkMvP4JpyELSCdru0aUpW6EnFFj45bxU6p
X-Received: by 2002:a05:6871:e607:b0:3c2:a2ab:6aa with SMTP id
586e51a60fabf-3c2a2ab093cmr11524575fac.10.1760438853938;
Tue, 14 Oct 2025 03:47:33 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1760438853; cv=none;
d=google.com; s=arc-20240605;
b=CWX7Lnq62z88URzbG+g3EoQNEHc3LpTdR9rYjFN1ptMNVoDWKFoAQp2E/WjSRlAMz4
iocxKJo97tnc+thR8qlC1pGT5mNJgkNB7ShQmU1aGPZOX6N9hoEmW//jp1Zjb4C3HdC7
wt8h7ue7hDir+QKUB94zLxm27C/Ybncb9AB5EgxXJvBxXmbO5gfnv+FdCQdvjIu8mWnH
vzWgKxUWMCBLh77fGdht38ionMrz/kSiJjWhDH3/0XQs/NCLlyaUltlGYoSIfUEvLIQq
b7YLiyleWJ4FC/b2T95AArjELEFPVAABQFJktqm4U5xzQUvSp/z8TC3hA+3ERrAQos7B
bNhw==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com;
s=arc-20240605;
h=errors-to:content-transfer-encoding:cc: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=ksVrka25IWtNrEghnagTHp7iEhP50SPV1njkziGOIrA=;
fh=agGsPbf0F8Xu3A8IreqFjWMNgE/YObs6xKPKRP2oPTc=;
b=GC5EUbhDUgVLWTss4nfXCgmIPwpGbTblmQU61TvCB7Csd50XJ9tQh97aa2M2l26LfB
QRCbR3GKR6VI4Anec/qjvMzhDKOGOOuYWHOleIlJYMeegYMWvyEfFuwC8WRsPbBojq7F
HYXaYXov5e1gcP74QtEAoHD3Y5T5ffeJUzRv/yNMgb2RMcjtoOHObW1jqbDnzV1E5PJD
s4VSXJpJr8/VTzGIRvloCY/99h5FZJMeymGfBjvfZ2zvTVczBEMy0QBniwO4w2C76LCS
Su1W3C9hGyBwULyFDWS9C1pX8Cn6xZN40Dr1lvCqHBbnRxU5f3MWI57xknMDO/dd4GAt
Ibvw==;
dara=google.com
ARC-Authentication-Results: i=1; mx.google.com;
dkim=pass header.i=@lists.sourceforge.net header.s=beta
header.b=gkCvWi3h;
dkim=neutral (body hash did not verify) header.i=@sourceforge.net
header.s=x header.b=F+SCyMEw;
dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x
header.b=JPsbjXwG;
dkim=neutral (body hash did not verify) header.i=@mandelbit.com
header.s=google header.b="XrTa8/AF";
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;
dara=fail header.i=@openvpn.net
Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7])
by mx.google.com with ESMTPS id
586e51a60fabf-3c8c8b51bfasi3408140fac.49.2025.10.14.03.47.33
(version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128);
Tue, 14 Oct 2025 03:47:33 -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=gkCvWi3h;
dkim=neutral (body hash did not verify) header.i=@sourceforge.net
header.s=x header.b=F+SCyMEw;
dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x
header.b=JPsbjXwG;
dkim=neutral (body hash did not verify) header.i=@mandelbit.com
header.s=google header.b="XrTa8/AF";
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;
dara=fail header.i=@openvpn.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:Cc:
List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:
Subject:MIME-Version:Message-ID:Date:To:From:Sender:Reply-To:Content-ID:
Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc
:Resent-Message-ID:In-Reply-To:References:List-Owner;
bh=ksVrka25IWtNrEghnagTHp7iEhP50SPV1njkziGOIrA=; b=gkCvWi3hFzJYdEDXBC/kdPlOdU
0eTsjoxpiJaIpK6d3pnlfv+NIN//gfLhrSsmW9g/f5SsQka9/kuzaVT4LNCB3K1bpziiB2YNPGbil
iTzvx+W9qkvpo3dfCAF9bw4ONjyMocYzaReondUPMQMU/k3CYNSkFjtbYoW7M/85ct5A=;
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 <openvpn-devel-bounces@lists.sourceforge.net>)
id 1v8cYy-00049e-4a;
Tue, 14 Oct 2025 10:47:28 +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 <ralf@mandelbit.com>) id 1v8cYw-00049X-Ov
for openvpn-devel@lists.sourceforge.net;
Tue, 14 Oct 2025 10:47:27 +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=9drhrDO0nde6Qu6k9e0WJtId/BRjJQ0AAGpjYx8Rv68=; b=F+SCyMEwBCInDx/Ooi/N4SiIZJ
L5wEToe3JWIvyWYyTbHMC8ienkVqeGXhFLUOspOguXIJ5o9miMoOta6ForZzTbEifWvPmkH+72JRc
0TUIOIZW9kcSWY5tiTOVypj91GMsqLM0ekpsgvYAcygdJwghMYktBi3QIaf4lLZH6Ot8=;
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=9drhrDO0nde6Qu6k9e0WJtId/BRjJQ0AAGpjYx8Rv68=; b=J
PsbjXwGUJx1QHVO1mty5mZ3tkUDLp7Vcp3v368+iGOhoHYD8Y928dKt+sXuh/zFBPx1mCB3Koe65A
tRZfusa0i2JrE1nX1dI5jnnPEW0WoIyuneOgpKCTnEaEa4quVdnongSFTPeXVYEHhQmIOy+4Ubwnv
jPoqZ3kT5SeXqync=;
Received: from mail-wr1-f51.google.com ([209.85.221.51])
by sfi-mx-2.v28.lw.sourceforge.com with esmtps
(TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95)
id 1v8cYx-0005EJ-6j for openvpn-devel@lists.sourceforge.net;
Tue, 14 Oct 2025 10:47:27 +0000
Received: by mail-wr1-f51.google.com with SMTP id
ffacd0b85a97d-3ee64bc6b90so2986418f8f.0
for <openvpn-devel@lists.sourceforge.net>;
Tue, 14 Oct 2025 03:47:27 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=mandelbit.com; s=google; t=1760438835; x=1761043635;
darn=lists.sourceforge.net;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:from:to:cc:subject:date:message-id:reply-to;
bh=9drhrDO0nde6Qu6k9e0WJtId/BRjJQ0AAGpjYx8Rv68=;
b=XrTa8/AF3nSrsKJcvd4xa0iJPrGRHrqUWX/hJDY5jVDO+xI/l41lB7R3e7ilDAqm+C
ksteb46pL6BrgodqHSCzVm/E99O+Zern2AI27Otg1DVXdEDaqw0wnQXzkSElLNuJaimv
i3Ad3Jfif8dsUJJ5199Ec9h5qwRzaLYwTzBiUnfQ7u6nz5D4l1KzK23DVSUaEAEbHFA0
/iPnMI7lAonYBVNpAkDcVQdNSuJKZcTRUrRox667HIGbrnExIMdHu6t+HQ8u86rQhnWD
P7tWCQAB7b2q91WJ0z27a8WDUs14JRoV1eVt6pp5+FSJ/xdPKlDhf+aMrBp2I+HO3GQx
Nd4Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1760438835; x=1761043635;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:x-gm-message-state:from:to:cc:subject:date:message-id
:reply-to;
bh=9drhrDO0nde6Qu6k9e0WJtId/BRjJQ0AAGpjYx8Rv68=;
b=P1+N8NaoUz11C5LCXqzhAsThn7nlei71fdMEg3MsQt6iRrQXiL2Lbb6jf3GyhOfxbp
Uoa4+sWw0qp7aEja2YkUXh6PL5gRe2m7RTTnZ1zFM6dsfGM4Cad6Pv3jkzIrh+Pkfy3c
ARLcSnqAUeIxb6WsGtm3ET8n6n/5FEQQwDIYiojjPHxhA76YKHEysXzWcuCeZP0Mdknw
lw+Kq7UDMiTwmza/RotkXuEmg/qiFoUZxJm1eBisOTOXmzDzJgYf60f9psVv23jbOZd6
8SO0P6ti1ITfi3+nCthDkwCxDe1v8Y9s5J0dplLhNzXsUTH/lgfJh1OIGFQl44Tcfeui
ky2g==
X-Gm-Message-State: AOJu0YyLrjFg8Q/FDcldUS58vMZb6i6msdby741iffDpRkxHm8YHKf7+
WR7g60ohREV7yTsIqzfi6pWjTCeEsw3eibC4fnsiv6xG+qDYgZy9/ycv48RxKRnz7jMqWYOqh8m
FQiu0
X-Gm-Gg: ASbGncvoBj5sZkYijRnY5Hg1482K1KGthlMaIT3pFxKbXmkQRitQEoWTGCzRHSKphzn
d5ze82EiAbOnTTGOW9TpDKA4lGi2Tg77WNQTC+x2Vmuhud1brpIc60TKHgqdkutO6hL6WlPEsws
cwLcPggCW+8TaPpAjHDbF28ZTIwFvGPPl5+CHzdIKDrZz8VSvudXL7pKv1BqkUtYq3UB7S3Jzus
bTZvMUyw9p25HquwY55S00gh0uIwht2jEfyZ3GmJ53fzk6TElAFvnF67GnGQQeRe0Q/RjDuyZin
uLWAcjXbLbmRErP1EfSln5JjdB9qg+7Y9234jfTL6O9eljqeTk7ggA3428YD4Yln1sfqE4yeHXD
ck8R75cZeslhZIhyugD6lh7xlSBDFn8OevzEekaHQDEuj2Ts=
X-Received: by 2002:a05:6000:4382:b0:3e2:b2f0:6e57 with SMTP id
ffacd0b85a97d-4266e7d922cmr14713165f8f.36.1760437221687;
Tue, 14 Oct 2025 03:20:21 -0700 (PDT)
Received: from fedora ([2a01:e11:600c:d1a0:3dc8:57d2:efb7:51a8])
by smtp.gmail.com with ESMTPSA id
ffacd0b85a97d-426f3fa3bdasm411070f8f.46.2025.10.14.03.20.21
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Tue, 14 Oct 2025 03:20:21 -0700 (PDT)
From: Ralf Lici <ralf@mandelbit.com>
To: openvpn-devel@lists.sourceforge.net
Date: Tue, 14 Oct 2025 12:19:48 +0200
Message-ID: <20251014101948.250823-1-ralf@mandelbit.com>
X-Mailer: git-send-email 2.51.0
MIME-Version: 1.0
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: datagram_poll marks a socket as readable whenever there are
packets in the standard sk_receive_queue. However, with TCP encapsulation,
another queue is used to hold packets destined for userspace. To ensure
correct
EPOLLIN signaling, reset EPOLLIN and EPOLLRDNORM after calling datagram_poll,
and set them only if user_queue is not empty.
Content analysis details: (-0.2 points, 5.0 required)
pts rule name description
---- ----------------------
--------------------------------------------------
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_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.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2)
[209.85.221.51 listed in wl.mailspike.net]
X-Headers-End: 1v8cYx-0005EJ-6j
Subject: [Openvpn-devel] [PATCH ovpn-net-next] ovpn: only signal sk readable
if user_queue has packets
X-BeenThere: openvpn-devel@lists.sourceforge.net
X-Mailman-Version: 2.1.21
Precedence: list
List-Id: <openvpn-devel.lists.sourceforge.net>
List-Unsubscribe: <https://lists.sourceforge.net/lists/options/openvpn-devel>,
<mailto:openvpn-devel-request@lists.sourceforge.net?subject=unsubscribe>
List-Archive:
<http://sourceforge.net/mailarchive/forum.php?forum_name=openvpn-devel>
List-Post: <mailto:openvpn-devel@lists.sourceforge.net>
List-Help: <mailto:openvpn-devel-request@lists.sourceforge.net?subject=help>
List-Subscribe: <https://lists.sourceforge.net/lists/listinfo/openvpn-devel>,
<mailto:openvpn-devel-request@lists.sourceforge.net?subject=subscribe>
Cc: sd@queasysnail.net
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: openvpn-devel-bounces@lists.sourceforge.net
X-getmail-retrieved-from-mailbox: Inbox
X-GMAIL-THRID: =?utf-8?q?1845953931896636923?=
X-GMAIL-MSGID: =?utf-8?q?1845953931896636923?=
|
| Series |
[Openvpn-devel,ovpn-net-next] ovpn: only signal sk readable if user_queue has packets
|
|
Commit Message
Ralf Lici
Oct. 14, 2025, 10:19 a.m. UTC
datagram_poll marks a socket as readable whenever there are packets in
the standard sk_receive_queue. However, with TCP encapsulation, another
queue is used to hold packets destined for userspace.
To ensure correct EPOLLIN signaling, reset EPOLLIN and EPOLLRDNORM after
calling datagram_poll, and set them only if user_queue is not empty.
Signed-off-by: Ralf Lici <ralf@mandelbit.com>
---
drivers/net/ovpn/tcp.c | 5 +++++
1 file changed, 5 insertions(+)
Comments
2025-10-14, 12:19:48 +0200, Ralf Lici wrote: > datagram_poll marks a socket as readable whenever there are packets in > the standard sk_receive_queue. However, with TCP encapsulation, another > queue is used to hold packets destined for userspace. > > To ensure correct EPOLLIN signaling, reset EPOLLIN and EPOLLRDNORM after > calling datagram_poll, and set them only if user_queue is not empty. > > Signed-off-by: Ralf Lici <ralf@mandelbit.com> > --- > drivers/net/ovpn/tcp.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/drivers/net/ovpn/tcp.c b/drivers/net/ovpn/tcp.c > index 289f62c5d2c7..4dbdd59a0b1c 100644 > --- a/drivers/net/ovpn/tcp.c > +++ b/drivers/net/ovpn/tcp.c > @@ -563,6 +563,11 @@ static __poll_t ovpn_tcp_poll(struct file *file, struct socket *sock, > __poll_t mask = datagram_poll(file, sock, wait); > struct ovpn_socket *ovpn_sock; > > + /* Mark socket as readable for userspace only if there are packets in > + * the user_queue, not in sk_receive_queue. > + */ > + mask &= ~(EPOLLIN | EPOLLRDNORM); This would clear EPOLLIN and EPOLLRDNORM if they were set (alongside EPOLLRDHUP) because the socket was shutdown(): // https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/tree/net/core/datagram.c?h=v6.17#n952 shutdown = READ_ONCE(sk->sk_shutdown); if (shutdown & RCV_SHUTDOWN) mask |= EPOLLRDHUP | EPOLLIN | EPOLLRDNORM; which may not be desireable? Maybe another way to deal with it would be to add a variant of datagram_poll that takes the "real" RX queue as extra argument, and make datagram_poll a wrapper (using sk_receive_queue) around it. Then ovpn could use this new __datagram_poll helper with tcp.user_queue (but I'm not sure we can call datagram_poll under rcu_read_lock). > rcu_read_lock(); > ovpn_sock = rcu_dereference_sk_user_data(sock->sk); > if (ovpn_sock && ovpn_sock->peer && > -- > 2.51.0 >
On Tue, 2025-10-14 at 17:01 +0200, Sabrina Dubroca wrote: > This would clear EPOLLIN and EPOLLRDNORM if they were set (alongside > EPOLLRDHUP) because the socket was shutdown(): > > // > https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/tree/net/core/datagram.c?h=v6.17#n952 > shutdown = READ_ONCE(sk->sk_shutdown); > if (shutdown & RCV_SHUTDOWN) > mask |= EPOLLRDHUP | EPOLLIN | EPOLLRDNORM; > > which may not be desireable? > > > Maybe another way to deal with it would be to add a variant of > datagram_poll that takes the "real" RX queue as extra argument, and > make datagram_poll a wrapper (using sk_receive_queue) around it. Then > ovpn could use this new __datagram_poll helper with tcp.user_queue I totally agree. > (but I'm not sure we can call datagram_poll under rcu_read_lock). I see the problem may arise from the call to sock_poll_wait, which isn't safe inside an rcu_read_lock() section. Perhaps the __datagram_poll helper could delegate the responsibility of calling sock_poll_wait to the caller, allowing it to perform the rest of the polling logic safely within the RCU read-side critical section. >
On Tue, 2025-10-14 at 18:29 +0200, ralf@mandelbit.com wrote: > On Tue, 2025-10-14 at 17:01 +0200, Sabrina Dubroca wrote: > > (but I'm not sure we can call datagram_poll under rcu_read_lock). > > I see the problem may arise from the call to sock_poll_wait, which > isn't > safe inside an rcu_read_lock() section. Perhaps the __datagram_poll > helper could delegate the responsibility of calling sock_poll_wait to > the caller, allowing it to perform the rest of the polling logic > safely > within the RCU read-side critical section. > After discussing this with Antonio, we realized that we can safely take a reference to the queue and increment the peer's refcounter, allowing us to call __datagram_poll outside the RCU section. This approach lets us avoid modifying the original kernel function. I'll send a patch shortly. Thanks for your help!
diff --git a/drivers/net/ovpn/tcp.c b/drivers/net/ovpn/tcp.c index 289f62c5d2c7..4dbdd59a0b1c 100644 --- a/drivers/net/ovpn/tcp.c +++ b/drivers/net/ovpn/tcp.c @@ -563,6 +563,11 @@ static __poll_t ovpn_tcp_poll(struct file *file, struct socket *sock, __poll_t mask = datagram_poll(file, sock, wait); struct ovpn_socket *ovpn_sock; + /* Mark socket as readable for userspace only if there are packets in + * the user_queue, not in sk_receive_queue. + */ + mask &= ~(EPOLLIN | EPOLLRDNORM); + rcu_read_lock(); ovpn_sock = rcu_dereference_sk_user_data(sock->sk); if (ovpn_sock && ovpn_sock->peer &&