Skip to contentSkip to conversation

ovpn: avoid nesting TCP transport socket locks

PATCH New Antonio Quartulli 1 participant 1 message Oct 31

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 ovpn: avoid nesting TCP transport socket locks

From: Antonio Quartulli <[email protected]>

ovpn_tcp_send_skb() and ovpn_tcp_release() transmit while holding the transport socket spinlock. If the outer packet is routed into an ovpn interface, ovpn_tcp_send_skb() takes the spinlock of the selected peer's socket while the first one is still held. This deadlocks when it is the same socket or when two peers are routed through each other.

Defer transmission to the TX worker when the skb comes from an ovpn TCP transport socket.

---

v3:
- queue new packets behind already deferred ones to preserve ordering (Sashiko)
v2: https://lore.kernel.org/all/[email protected]/

 drivers/net/ovpn/io.c   |   2 +-
 drivers/net/ovpn/peer.h |   2 +-
 drivers/net/ovpn/tcp.c  | 109 ++++++++++++++++++++++++++++++----------
 drivers/net/ovpn/tcp.h  |   2 +-
 4 files changed, 85 insertions(+), 30 deletions(-)
drivers/net/ovpn/io.c +1 -1
index f14eb4e6c46a..3282c3b0bf58 100644
@@ -284,7 +284,7 @@ void ovpn_encrypt_post(void *data, int ret)
 		ovpn_udp_send_skb(peer, sock->sk, skb);
 		break;
 	case IPPROTO_TCP:
-		ovpn_tcp_send_skb(peer, sock->sk, skb);
+		ovpn_tcp_send_skb(peer, sock, skb);
 		break;
 	default:
 		/* no transport configured yet */
drivers/net/ovpn/peer.h +1 -1
index 1879bfb76992..8256c628f769 100644
@@ -45,7 +45,7 @@ struct ovpn_route_key {
  * @tcp: keeps track of TCP specific state
  * @tcp.strp: stream parser context (TCP only)
  * @tcp.user_queue: received packets that have to go to userspace (TCP only)
- * @tcp.out_queue: packets on hold while socket is taken by user (TCP only)
+ * @tcp.out_queue: packets deferred for later transmission (TCP only)
  * @tcp.tx_in_progress: true if TX is already ongoing (TCP only)
  * @tcp.out_msg.skb: packet scheduled for sending (TCP only)
  * @tcp.out_msg.offset: offset where next send should start (TCP only)
drivers/net/ovpn/tcp.c +82 -27

157 lines not on this page · raw message

drivers/net/ovpn/tcp.h +1 -1
index a3aa3570ae5e..9f2b5efcbd3a 100644
@@ -30,7 +30,7 @@ void ovpn_tcp_socket_wait_finish(struct ovpn_socket *sock);
  * Required by the OpenVPN protocol in order to extract packets from
  * the TCP stream on the receiver side.
  */
-void ovpn_tcp_send_skb(struct ovpn_peer *peer, struct sock *sk,
+void ovpn_tcp_send_skb(struct ovpn_peer *peer, struct ovpn_socket *sock,
 		       struct sk_buff *skb);
 void ovpn_tcp_tx_work(struct work_struct *work);
 
Signature · 8 lines
2.56.0



_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel