From: David Carlier <devnexen@gmail.com>
To: netdev@vger.kernel.org
Cc: David Carlier <devnexen@gmail.com>
Subject: [PATCH net v2 0/2] ovpn: fix TCP teardown UAF races
Date: Wed, 13 May 2026 11:55:19 +0100 [thread overview]
Message-ID: <20260513105521.21629-1-devnexen@gmail.com> (raw)
In-Reply-To: <20260512042036.19870-1-devnexen@gmail.com>
v1: https://lore.kernel.org/netdev/20260512042036.19870-1-devnexen@gmail.com/
Two distinct UAFs in the TCP transport teardown path, both inherited
from 11851cbd60ea ("ovpn: implement TCP transport"). They share a race
class with the already-merged 94560267d6c4 ("ovpn: tcp - don't deref
NULL sk_socket member after tcp_close()"), which fixed the detach-side
of the keepalive-vs-userspace-close race window; the two patches in
this series cover the other two victim sites in the same window.
Patch 1 fixes a UAF in ovpn_tcp_close(). The function loads the
ovpn_socket via rcu_dereference_sk_user_data(), caches sock->peer in a
local, drops rcu_read_lock, and then passes sock->peer (rather than
the cached local) to ovpn_peer_del(). Unlike ovpn_tcp_sendmsg() which
uses the same pattern but is protected by lock_sock, ovpn_tcp_close()
runs without the socket lock - inet_release() does not lock_sock
before calling sk_prot->close. A concurrent ovpn_socket_release() can
therefore complete kref_put -> detach -> synchronize_rcu -> kfree(sock)
in the window after rcu_read_unlock() but before the dangling
sock->peer dereference.
Patch 2 fixes the CMD_NEW_PEER error path in ovpn_nl_peer_new_doit(),
which calls ovpn_peer_release() directly rather than ovpn_peer_put(),
bypassing the kref. The accompanying "peer was not yet hashed, thus
not used in any context" comment is correct for UDP but wrong for TCP:
after ovpn_tcp_socket_attach() publishes ovpn_sock via
rcu_assign_sk_user_data(), the peer is reachable via sk_user_data ->
ovpn_sock->peer; userspace recvmsg/sendmsg/close/poll and the
strparser-driven ovpn_tcp_rcv() path can bump its refcount.
Both Fixes: 11851cbd60ea ("ovpn: implement TCP transport"). Not Cc'd
to stable - borderline practical reachability and reproducer is
non-trivial; maintainer judgement on backport.
Changes since v1:
- Patch 1: tighten the entry block to read sock->peer exactly once
into the cached peer local; route the hold check, ovpn_peer_del()
and prot->close() invocations through that local (Eric Dumazet).
The same multi-read pattern in ovpn_tcp_recvmsg(), ovpn_tcp_sendmsg(),
ovpn_tcp_data_ready() and ovpn_tcp_write_space() will be handled by
a dedicated helper in a follow-up net-next series (Sabrina Dubroca,
Antonio Quartulli).
- Patch 2: make ovpn_peer_release() static and drop its declaration
from peer.h, since the netlink callsite was the last external user
(Sabrina Dubroca, Antonio Quartulli).
- Both patches: add Reviewed-by from Sabrina Dubroca.
David Carlier (2):
ovpn: tcp - use cached peer pointer in ovpn_tcp_close()
ovpn: respect peer refcount in CMD_NEW_PEER error path
drivers/net/ovpn/netlink.c | 8 +++++---
drivers/net/ovpn/peer.c | 2 +-
drivers/net/ovpn/peer.h | 1 -
drivers/net/ovpn/tcp.c | 9 +++++++--
4 files changed, 13 insertions(+), 7 deletions(-)
--
2.53.0
next prev parent reply other threads:[~2026-05-13 10:55 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 4:19 [PATCH net 0/2] ovpn: fix TCP teardown UAF races David Carlier
2026-05-12 4:19 ` [PATCH net 1/2] ovpn: tcp - use cached peer pointer in ovpn_tcp_close() David Carlier
2026-05-12 4:29 ` Eric Dumazet
2026-05-12 4:56 ` David CARLIER
2026-05-12 7:29 ` Antonio Quartulli
2026-05-12 13:55 ` Antonio Quartulli
2026-05-12 14:11 ` Sabrina Dubroca
2026-05-12 14:17 ` Antonio Quartulli
2026-05-12 15:04 ` Sabrina Dubroca
2026-05-12 4:19 ` [PATCH net 2/2] ovpn: respect peer refcount in CMD_NEW_PEER error path David Carlier
2026-05-12 7:33 ` Antonio Quartulli
2026-05-12 15:13 ` Sabrina Dubroca
2026-05-13 9:10 ` Antonio Quartulli
2026-05-13 10:55 ` David Carlier [this message]
2026-05-13 10:55 ` [PATCH v2 1/2] ovpn: tcp - use cached peer pointer in ovpn_tcp_close() David Carlier
2026-05-13 10:55 ` [PATCH v2 2/2] ovpn: respect peer refcount in CMD_NEW_PEER error path David Carlier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260513105521.21629-1-devnexen@gmail.com \
--to=devnexen@gmail.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox