🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by Ji WANG Sat, 21 Nov 2026 13:42
[BUG] ovpn: TCP self-deadlock when transport packets loop into the ovpn dev
#20133
Author: Ji WANG
Date: Sat, 21 Nov 2026 13:42
384 lines
25993 bytes
Hi,

I hit a hard system freeze with ovpn (DCO) in TCP mode. All input
(USB and built-in keyboard) stopped responding, and the only way out
was a forced power-off. The kernel log shows soft lockups on several
CPUs, all spinning on the same sk->sk_lock.slock of the ovpn TCP
transport socket.

Kernel:   7.3.4-1-default (openSUSE Tumbleweed); also reproduced on
          net/main d5b89d55a (7.4-rc3+, 2026-11-20), see below
OpenVPN:  2.7.5 (DCO enabled)
Hardware: Xiaomi Redmi Book Pro 16 2024 (Meteor Lake), Intel AX211 WiFi
Mode:     client, split tunnel (server pushes several routes, no
          redirect-gateway), remote list = UDP v6, UDP v4, TCP v6, TCP v4

Root cause (as far as I can tell from the traces)
-------------------------------------------------
The CPU that holds the lock is CPU#5. Its trace shows ovpn_net_xmit()
being re-entered from inside ovpn_tcp_send_sock():

  udp_sendmsg (userspace app, kdeconnectd)
   -> routed to the ovpn device
   -> ovpn_net_xmit -> ovpn_send -> ovpn_encrypt_post -> ovpn_tcp_send_skb
      [takes sk_lock.slock of the transport socket]
   -> ovpn_tcp_send_sock -> __skb_send_sock -> tcp_sendmsg_locked
   -> tcp_write_xmit -> __ip_queue_xmit -> ip_finish_output2
   -> the encapsulated packet to the VPN server is routed back into the
      ovpn device
   -> ovpn_net_xmit -> ... -> ovpn_tcp_send_skb
      [spins on the same sk_lock.slock it already holds]  => deadlock

In other words, a routing loop: the outer TCP transport packets to the
server are routed back into the tunnel. In my setup the IPv4 server
address (x.y.226.105, TCP 443) is inside one of the pushed routes
(x.y.0.0/16 via tun0), and there is no host route for the IPv4 server
via the physical interface. (For the IPv6 server a host route via
the physical interface does exist.) The trigger was a network change: a
USB-C dock disconnected, WiFi re-associated, and the iwlwifi firmware
crashed and reset. OpenVPN then reconnected and fell back to the IPv4
TCP remote.

Note that this setup is not exotic: OpenVPN automatically adds a host
route to the remote when a pushed route-ipv6 overlaps the IPv6 server
address ("ROUTE6: ... overlaps IPv6 remote ..., adding host route to
VPN endpoint"), but does not do the same for pushed IPv4 routes in
split-tunnel mode. So falling back to an IPv4 remote that is covered by
a pushed route reliably creates the loop.

Strictly speaking, a routing loop like this is a misconfiguration.
Still, other tunnel drivers detect the recursion and drop the packet
("Dead loop on virtual device"). The generic xmit recursion limit
cannot help here, because ovpn deadlocks on the second level already,
while holding a spinlock.
After that, every other user of the socket spins on the same lock as
well: the TCP write timer in softirq (CPU#4), openvpn's close()
(CPU#11), and ovpn_peer_keepalive_work (CPU#17). The machine becomes
unusable.

Reproducer (verified)
---------------------
ovpn-repro.sh (inline at the end of this mail) creates two netns
joined by a veth pair, with an OpenVPN 2.7 server and client over TCP.
The client uses DCO.
The server pushes "route 10.99.0.0 255.255.255.128", which covers its
own address 10.99.0.1, and there is no host route to the server.
I ran it in a virtme-ng VM (4 vCPUs) on the same 7.3.4-1-default kernel
with OpenVPN 2.7.5:

  - DCO + routing loop:          soft lockups on all 4 CPUs within ~15s.
  - DCO + host route (no loop):  tunnel works, no lockup.
  - disable-dco + routing loop:  tunnel is broken, ping-restart after
                                 10s, no lockup.

Same results on net/main d5b89d55a ("net: qrtr: ns: keep notifying local
servers after a failed send", 7.4-rc3+), built with vng --build plus
CONFIG_OVPN=y. The DCO + loop case produced continuous soft lockups
(still stuck at 73s when the VM was killed), with the identical
tcp_write_timer -> ovpn_net_xmit -> ovpn_tcp_send_skb trace. The other
two cases were clean.

In the VM the lock owner enters from the TCP timer rather than from
sendmsg, but it is the same self-deadlock. The timer already holds the
socket spinlock while the transmit re-enters ovpn:

  tcp_write_timer -> tcp_send_loss_probe -> tcp_write_xmit
   -> __ip_queue_xmit -> ip_finish_output2 -> __dev_queue_xmit
   -> ovpn_net_xmit -> ovpn_send -> ovpn_encrypt_post
   -> ovpn_tcp_send_skb -> spin on sk_lock.slock (held by this CPU)

The other CPUs spin on the same lock in tcp_v4_rcv (softirq) and in
ovpn_peer_keepalive_send.

Possibly related: "[PATCH 1/1] ovpn: tcp - defer TX from softirq to
workqueue" (Dao Zhong Ma, 2026-05-01) reports a very similar soft
lockup on sk->sk_lock.slock after suspend/resume. A network change on
resume could produce exactly this loop. But I'm not sure.

Current status: drivers/net/ovpn is unchanged between v7.3.4 and v7.3.5.
torvalds/master (7.4-rc3+), net/main and net-next/main as of 2026-11-20
contain only cosmetic ovpn changes since then, with nothing in the TCP TX
path. So as far as I can tell, this is not fixed upstream. Note that
the existing re-entry guard (peer->tcp.tx_in_progress in
ovpn_tcp_send_sock()) is only checked after ovpn_tcp_send_skb() has
taken sk_lock.slock, so a re-entrant call spins before it reaches the
guard. In the timer path, the outer TCP code already holds the slock
via bh_lock_sock(). In other words, the recursion would have to be
detected before the spinlock is taken.

Workaround: "disable-dco" in the client config.

Traces (trimmed)
----------------
[  started ~13:20:43, right after "tun0: deleting peer with id 0, reason 2" ]

watchdog: BUG: soft lockup - CPU#5 stuck for 26s! [kdeconnectd:1835]
CPU: 5 UID: 1000 PID: 1835 Comm: kdeconnectd Tainted: G L 7.3.4-1-default #1
     PREEMPT(full) openSUSE Tumbleweed
RIP: 0010:native_queued_spin_lock_slowpath+0x6a/0x2c0
RDI: ffff89f8423aa74c R12: ffff89f8423aa600
Call Trace:
 <TASK>
 ovpn_tcp_send_skb+0x53/0x110 [ovpn]
 ovpn_encrypt_post+0x141/0x1d0 [ovpn]
 ovpn_send+0x180/0x240 [ovpn]
 ovpn_net_xmit+0x27b/0x530 [ovpn]
 dev_hard_start_xmit+0x63/0x1c0
 __dev_queue_xmit+0x777/0x1390
 ip_finish_output2+0x18d/0x5b0
 ip_output+0x63/0x100
 __ip_queue_xmit+0x16d/0x460
 __tcp_transmit_skb+0xc93/0x1170
 tcp_write_xmit+0x59d/0x1710
 __tcp_push_pending_frames+0x37/0x110
 tcp_sendmsg_locked+0xdf6/0x1300
 __skb_send_sock+0x15a/0x500
 ovpn_tcp_send_sock+0x82/0x210 [ovpn]
 ovpn_tcp_send_skb+0xc0/0x110 [ovpn]
 ovpn_encrypt_post+0x141/0x1d0 [ovpn]
 ovpn_send+0x180/0x240 [ovpn]
 ovpn_net_xmit+0x27b/0x530 [ovpn]
 dev_hard_start_xmit+0x63/0x1c0
 __dev_queue_xmit+0x777/0x1390
 ip_finish_output2+0x18d/0x5b0
 ip_do_fragment+0x249/0x590
 ip_send_skb+0x90/0xa0
 udp_send_skb+0x185/0x290
 udp_sendmsg+0x8f4/0xea0
 ____sys_sendmsg+0x350/0x3b0
 ___sys_sendmsg+0x7d/0xc0
 __sys_sendmsg+0x80/0x110
 do_syscall_64+0xbe/0x520
 entry_SYSCALL_64_after_hwframe+0x76/0x7e
 </TASK>

watchdog: BUG: soft lockup - CPU#4 stuck for 26s! [swapper/4:0]
RIP: 0010:native_queued_spin_lock_slowpath+0x25e/0x2c0
RCX: ffff89f8423aa74c
 <IRQ>
 tcp_write_timer+0x5c/0x100
 call_timer_fn+0x2a/0x140
 __run_timers+0x204/0x2b0
 run_timer_softirq+0x70/0xc0
 handle_softirqs+0xcc/0x270
 __irq_exit_rcu+0xaa/0x100
 sysvec_apic_timer_interrupt+0x71/0x90
 </IRQ>

watchdog: BUG: soft lockup - CPU#11 stuck for 26s! [openvpn:1256]
RIP: 0010:native_queued_spin_lock_slowpath+0x248/0x2c0
RBX: ffff89f8423aa600 RCX: ffff89f8423aa74c
 lock_sock_nested+0x45/0x80
 tcp_close+0x18/0x80
 ovpn_tcp_close+0x9b/0x140 [ovpn]
 inet_release+0x50/0xa0
 __sock_release+0x51/0xd0
 sock_close+0x15/0x20
 __fput+0xf6/0x2e0
 __x64_sys_close+0x47/0xa0

watchdog: BUG: soft lockup - CPU#17 stuck for 26s! [kworker/17:1:4784]
Workqueue: ovpn ovpn_peer_keepalive_work [ovpn]
RIP: 0010:native_queued_spin_lock_slowpath+0x248/0x2c0
RBX: ffff89f8423aa600 RCX: ffff89f8423aa74c
 lock_sock_nested+0x45/0x80
 ovpn_socket_release+0x33/0x1a0 [ovpn]
 unlock_ovpn+0x5b/0xb0 [ovpn]
 ovpn_peer_keepalive_work+0x13a/0x1e0 [ovpn]
 process_one_work+0x1d3/0x3c0
 worker_thread+0x1b1/0x310
 kthread+0xe6/0x120

All four CPUs spin on the same lock (ffff89f8423aa74c). CPU#11 and
CPU#17 are still stuck at 52s in the second watchdog report.

The reproducer script is included inline below.

I can provide the full untrimmed logs if needed.

Thanks,
Ji Wang

---8<--- ovpn-repro.sh ---8<---
#!/bin/bash
# ovpn (OpenVPN DCO) TCP self-deadlock reproducer
#
# WARNING: if the bug is present, this FREEZES THE WHOLE MACHINE
# (soft lockups, no input). Run it only in a throwaway VM.
#
# Scenario: the client talks to the server over TCP via ovpn/DCO. The
# server pushes a route that covers the server's own IPv4 address, and
# the client has no host route to the server via the physical link.
# Once that route is installed, the outer TCP transport packets are
# routed back into the ovpn device:
#   ovpn_net_xmit -> ovpn_tcp_send_skb [takes sk_lock.slock]
#     -> tcp_sendmsg_locked -> ip_output -> ovpn_net_xmit
#     -> ovpn_tcp_send_skb [spins on the same lock]  => deadlock
#
# Topology:
#   netns ovpnr-srv: veth 10.99.0.1/24, openvpn server (TCP 1194),
#                    tun 10.200.0.1/24
#   netns ovpnr-cli: veth 10.99.0.2/24, openvpn client (DCO),
#                    tun 10.200.0.x/24
#   pushed route:    10.99.0.0/25 via tun
#                    (covers the server 10.99.0.1, beats the /24 on veth)
#
# Requirements: root, kernel with the ovpn module, OpenVPN >= 2.6 built
# with DCO, iproute2, openssl.
#
# Usage:
#   I_UNDERSTAND_THIS_FREEZES=1 ./ovpn-repro.sh
#       trigger the bug
#   I_UNDERSTAND_THIS_FREEZES=1 ./ovpn-repro.sh --with-host-route
#       control run: host route 10.99.0.1/32 dev veth, so no loop
#   DISABLE_DCO=1 I_UNDERSTAND_THIS_FREEZES=1 ./ovpn-repro.sh
#       same loop with DCO disabled (workaround check)
#   ALLOW_BARE_METAL=1 ...
#       skip the VM check
#
# Tip (inside the VM): sysctl kernel.softlockup_panic=1 kernel.panic=10
# makes the VM panic and reboot by itself instead of hanging forever.

set -euo pipefail

SRV=ovpnr-srv
CLI=ovpnr-cli
WORK=$(mktemp -d /tmp/ovpn-repro.XXXXXX)
HOST_ROUTE=0
[[ "${1:-}" == "--with-host-route" ]] && HOST_ROUTE=1

die() { echo "ERROR: $*" >&2; exit 1; }

# ---- safety checks -------------------------------------------------------
[[ "${I_UNDERSTAND_THIS_FREEZES:-}" == "1" ]] || \
    die "This may hard-freeze the machine." \
        "Set I_UNDERSTAND_THIS_FREEZES=1 to run."
[[ $EUID -eq 0 ]] || die "must run as root"
if [[ "${ALLOW_BARE_METAL:-}" != "1" ]]; then
    virt=$(systemd-detect-virt 2>/dev/null || true)
    [[ -n "$virt" && "$virt" != "none" ]] || \
        die "not running in a VM (set ALLOW_BARE_METAL=1 to override)"
fi
for c in openvpn openssl ip; do
    command -v "$c" >/dev/null || die "missing: $c"
done
openvpn --version | head -1 | grep -q '\[DCO\]' || \
    die "openvpn built without DCO"
modprobe ovpn 2>/dev/null || [[ -d /sys/module/ovpn ]] || \
    die "cannot load ovpn module"
modprobe tun 2>/dev/null || true

cleanup() {
    for ns in $SRV $CLI; do
        ip netns pids "$ns" 2>/dev/null | xargs -r kill 2>/dev/null || true
    done
    sleep 1
    ip netns del $SRV 2>/dev/null || true
    ip netns del $CLI 2>/dev/null || true
    echo "logs kept in $WORK"
}
trap cleanup EXIT

# ---- certificates (self-signed, verified via peer-fingerprint) ------------
cd "$WORK"
for n in srv cli; do
    openssl req -x509 -newkey ec \
        -pkeyopt ec_paramgen_curve:prime256v1 -nodes \
        -keyout $n.key -out $n.crt -days 1 -subj "/CN=$n" 2>/dev/null
done
fp() { openssl x509 -in "$1" -noout -fingerprint -sha256 | cut -d= -f2; }
SRV_FP=$(fp srv.crt)
CLI_FP=$(fp cli.crt)

# ---- namespaces + veth ---------------------------------------------------
ip netns add $SRV
ip netns add $CLI
ip link add veth-srv netns $SRV type veth peer name veth-cli netns $CLI
ip -n $SRV addr add 10.99.0.1/24 dev veth-srv
ip -n $CLI addr add 10.99.0.2/24 dev veth-cli
for ns in $SRV $CLI; do
    ip -n $ns link set lo up
done
ip -n $SRV link set veth-srv up
ip -n $CLI link set veth-cli up
# Control run: pin the server address to veth with a host route
# (/32 beats the pushed /25).
if [[ $HOST_ROUTE -eq 1 ]]; then
    ip -n $CLI route add 10.99.0.1/32 dev veth-cli
fi

# ---- server --------------------------------------------------------------
cat > srv.conf <<EOF
dev tun
dev-type tun
proto tcp-server
local 10.99.0.1
port 1194
mode server
tls-server
topology subnet
server 10.200.0.0 255.255.255.0
cert $WORK/srv.crt
key  $WORK/srv.key
dh none
peer-fingerprint $CLI_FP
# The bug trigger: a pushed route that covers the server's own address.
push "route 10.99.0.0 255.255.255.128"
keepalive 2 10
verb 4
EOF

# ---- client --------------------------------------------------------------
cat > cli.conf <<EOF
client
dev tun
proto tcp-client
remote 10.99.0.1 1194
nobind
cert $WORK/cli.crt
key  $WORK/cli.key
peer-fingerprint $SRV_FP
verb 4
EOF
# DCO is the default when available. DISABLE_DCO=1 runs the same loop
# in userspace mode (workaround check).
if [[ "${DISABLE_DCO:-}" == "1" ]]; then
    echo "disable-dco" >> cli.conf
    echo "disable-dco" >> srv.conf
else
    grep -q disable-dco cli.conf && \
        die "cli.conf must not contain disable-dco"
fi

ip netns exec $SRV openvpn --config srv.conf --daemon \
    --log "$WORK/srv.log" --writepid "$WORK/srv.pid"
sleep 1
ip netns exec $CLI openvpn --config cli.conf --daemon \
    --log "$WORK/cli.log" --writepid "$WORK/cli.pid"

echo "waiting for the tunnel..."
for _ in $(seq 30); do
    grep -q "Initialization Sequence Completed" "$WORK/cli.log" && break
    sleep 1
done
grep -q "Initialization Sequence Completed" "$WORK/cli.log" || \
    die "tunnel did not come up, see $WORK/cli.log"
grep -qi "dco" "$WORK/cli.log" || \
    echo "warning: no DCO mention in client log, DCO may not be active"

echo "client routes:"
ip -n $CLI route
echo
echo "route to server from client:"
ip -n $CLI route get 10.99.0.1
echo
echo "sending traffic into the tunnel (this is where it should lock up)..."
sync
ip netns exec $CLI ping -c 5 -W 1 10.200.0.1 || true
ip netns exec $CLI ping -c 5 -W 1 10.99.0.100 || true

echo
echo "no lockup so far, check dmesg:"
dmesg | grep -E "soft lockup|ovpn" | tail -20 || true
---8<--- end ---8<---
Re: [BUG] ovpn: TCP self-deadlock when transport packets loop into the ovpn dev
#20215
Author: Antonio Quartulli
Date: Sat, 21 Nov 2026 19:49
36 lines
14922 bytes
Hi Ji,

On 21/11/2026 14:42, Ji WANG wrote:
> Hi,
> 
> I hit a hard system freeze with ovpn (DCO) in TCP mode. All input
> (USB and built-in keyboard) stopped responding, and the only way out
> was a forced power-off. The kernel log shows soft lockups on several
> CPUs, all spinning on the same sk->sk_lock.slock of the ovpn TCP
> transport socket.
> 

Thanks for your detailed report!

This issue was already reported by Bernhard[1] and I already provided a 
patch on the openvpn-devel mailing list that reached v3[2].

Unfortunately Sashiko claimed to have found something wrong[3] and so I 
need to spin a v4.
I should be able to do so next week. I'll keep you in CC so you can get 
notified when the patch lands.

Thanks a lot!
Regards,

[1] 
https://lore.kernel.org/openvpn-devel/auJj5Ld6uMjPb2eS@fliwatuet.svr02.mucip.net/
[2] 
https://lore.kernel.org/openvpn-devel/20261031225640.1436694-1-a@unstable.cc/
[3] https://sashiko.dev/#/patchset/20261031225640.1436694-1-a%40unstable.cc


-- 
Antonio Quartulli
OpenVPN Inc.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads