Skip to contentSkip to conversation

rxrpc: fix encap_rcv skb accounting exhaustion

PATCH Superseded Zihan Xi 2 participants 4 messages Oct 8

Subsystems (3)

v8 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Zihan Xi

author
#0 lore raw

v8 cover rxrpc: fix encap_rcv skb accounting exhaustion

This resubmission rebases the RxRPC receive-buffer accounting fix onto net/main at 6d25ffca055a.

v7 Link: https://lore.kernel.org/all/[email protected]/
v6 Link: https://lore.kernel.org/all/[email protected]/

Zihan Xi (1):
rxrpc: fix encap_rcv skb accounting exhaustion

 net/rxrpc/ar-internal.h  |  1 +
 net/rxrpc/io_thread.c    | 77 ++++++++++++++++++++++++++++++++++++++--
 net/rxrpc/local_object.c | 24 +++++++++++--
 3 files changed, 98 insertions(+), 4 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH v8 1/1 rxrpc: fix encap_rcv skb accounting exhaustion

rxrpc_encap_rcv() queues encapsulated UDP packets on the RxRPC local queue without charging them to the UDP socket. If the I/O thread cannot keep up, the queue can therefore grow without bound.

Charge each packet against the tunnel socket before queueing it, while holding sk_receive_queue.lock, and drop it when socket rmem or protocol memory accounting fails. Size the socket from the advertised RxRPC receive window, retain headroom for control and error packets, and refresh the cap when the window grows without shrinking an existing buffer. The lock also serializes sk_forward_alloc updates with the destructor path.

Orphan charged PACKET skbs under the same lock when the I/O thread dequeues them. Keep the existing destructor for error skbs, clear skb->dev, drop the dst, and account drops with the corresponding UDP statistics and reasons.

Since skb_set_owner_r() does not hold a socket reference, clear sk_user_data under RCU and release the socket only after purging the local queues.

Fixes 446b3e14525b ("rxrpc: Move packet reception processing into I/O thread")
Assisted-by LLM

---
changes in v8:
- Rebase onto net/main at 6d25ffca055a.
- v7 Link: https://lore.kernel.org/all/[email protected]/
changes in v7:
- Rebase the fix onto net/main at a7bfaba4823e.
- v6 Link: https://lore.kernel.org/all/[email protected]/
changes in v6:
- refresh the tunnel socket receive-buffer cap when rxrpc_rx_window_size increases, without shrinking an existing socket
- distinguish socket receive-buffer exhaustion from protocol memory accounting failures in the drop reason and UDP statistics
- cap the window-derived value at sysctl_rmem_max and only grow an existing sk_rcvbuf; avoid the unexported sysctl_rmem_default
- v5 Link: https://lore.kernel.org/all/[email protected]/
changes in v5:
- size the tunnel sk_rcvbuf to one advertised window of ordinary DATA (RXRPC_JUMBO(1)), doubled for typical 2-4KiB skb truesize, plus 25% for ACKs/ICMP, capped by sysctl_rmem_max
- leave ICMP/error-queue headroom in the DATA rmem check
- count UDP RCVBUFERRORS/INERRORS and drop with SKB_DROP_REASON_SOCKET_RCVBUFF
- drop the dst instead of skb_dst_force(); keep skb->dev = NULL
- refresh the cover crash log from the latest unfixed net/main run; record the panic as a sender-path OOM, not an I/O-thread allocation
- note that sk_rcvbuf is sized at socket open and is not updated if rxrpc_rx_window_size later changes
- v4 Link: https://lore.kernel.org/all/[email protected]/
changes in v4:
- serialise UDP rmem charge/uncharge with sk->sk_receive_queue.lock
- use spin_lock() in encap_rcv() (BH) and spin_lock_bh() around skb_orphan() in the I/O thread
- do not enqueue encapsulated skbs on the UDP receive queue
- orphan only PACKET skbs charged in encap_rcv(); leave error-queue skb ownership alone
- restore the unprivileged namespace reproducer and document the AFS callback listener
- clarify in the cover that the recorded panic is a downstream OOM after extra I/O-thread contention, not the unprivileged flood alone
- include the full OOM Mem-Info in the cover crash log
- v3 Link: https://lore.kernel.org/all/[email protected]/
changes in v3:
- orphan the skb when the I/O thread dequeues it from the local queue so UDP rmem ownership does not follow packets onto call/conn queues
- mention both io_thread.c and local_object.c in the cover opening
- distinguish the unprivileged flood from extra steps used to record the panic
- attribute the OOM to skbuff growth rather than incoming-call setup
- describe the recorded panic as a downstream OOM after I/O-thread contention, not as an allocation at the encap_rcv enqueue site
- v2 Link: https://lore.kernel.org/all/[email protected]/
changes in v2:
- switch the drop path from atomic_inc(&udp_sk->sk_drops) to sk_drops_inc(udp_sk)
- retarget Fixes to 446b3e14525b, the first boundary where encap_rcv

    queued the skb onto local->rx_queue for later I/O-thread consumption

- rebase onto current net/main
- refresh the cover crash log from an unfixed 7.3.0-rc1+ net/main run and include the decoded stack
- explain in the cover why packetdrill was not used
- document the actual flood command in the cover
- v1 Link: https://lore.kernel.org/all/[email protected]/
---
changes in v8:
- Rebase onto net/main at 6d25ffca055a.
- Resend the fix after the previous posting became stale.
- v7 Link: https://lore.kernel.org/all/[email protected]/
changes in v7:
- Rebase the fix onto net/main at a7bfaba4823e.
- v6 Link: https://lore.kernel.org/all/[email protected]/
changes in v6:
- refresh the tunnel socket receive-buffer cap when rxrpc_rx_window_size increases, without shrinking an existing socket
- distinguish socket receive-buffer exhaustion from protocol memory accounting failures in the drop reason and UDP statistics
- cap the window-derived value at sysctl_rmem_max and only grow an existing sk_rcvbuf; avoid the unexported sysctl_rmem_default
- v5 Link: https://lore.kernel.org/all/[email protected]/
changes in v5:
- size the tunnel sk_rcvbuf to one advertised window of ordinary DATA (RXRPC_JUMBO(1)), doubled for typical 2-4KiB skb truesize, plus 25% for ACKs/ICMP, capped by sysctl_rmem_max
- leave ICMP/error-queue headroom in the DATA rmem check
- count UDP RCVBUFERRORS/INERRORS and drop with SKB_DROP_REASON_SOCKET_RCVBUFF
- drop the dst instead of skb_dst_force(); keep skb->dev = NULL
- refresh the cover crash log from the latest unfixed net/main run; record the panic as a sender-path OOM, not an I/O-thread allocation
- note that sk_rcvbuf is sized at socket open and is not updated if rxrpc_rx_window_size later changes
- v4 Link: https://lore.kernel.org/all/[email protected]/
changes in v4:
- serialise UDP rmem charge/uncharge with sk->sk_receive_queue.lock
- use spin_lock() in encap_rcv() (BH) and spin_lock_bh() around skb_orphan() in the I/O thread
- do not enqueue encapsulated skbs on the UDP receive queue
- orphan only PACKET skbs charged in encap_rcv(); leave error-queue skb ownership alone
- restore the unprivileged namespace reproducer and document the AFS callback listener
- clarify in the cover that the recorded panic is a downstream OOM after extra I/O-thread contention, not the unprivileged flood alone
- include the full OOM Mem-Info in the cover crash log
- v3 Link: https://lore.kernel.org/all/[email protected]/
changes in v3:
- orphan the skb when the I/O thread dequeues it from the local queue so UDP rmem ownership does not follow packets onto call/conn queues
- mention both io_thread.c and local_object.c in the cover opening
- distinguish the unprivileged flood from extra steps used to record the panic
- attribute the OOM to skbuff growth rather than incoming-call setup
- describe the recorded panic as a downstream OOM after I/O-thread contention, not as an allocation at the encap_rcv enqueue site
- v2 Link: https://lore.kernel.org/all/[email protected]/
changes in v2:
- switch the drop path from atomic_inc(&udp_sk->sk_drops) to sk_drops_inc(udp_sk)
- retarget Fixes to 446b3e14525b, the first boundary where encap_rcv

    queued the skb onto local->rx_queue for later I/O-thread consumption
  - rebase onto current net/main
  - refresh the cover crash log from an unfixed 7.3.0-rc1+ net/main run
    and include the decoded stack
  - explain in the cover why packetdrill was not used
  - document the actual flood command in the cover
  - v1 Link: https://lore.kernel.org/all/[email protected]/
---
 net/rxrpc/ar-internal.h  |  1 +
 net/rxrpc/io_thread.c    | 77 ++++++++++++++++++++++++++++++++++++++--
 net/rxrpc/local_object.c | 24 +++++++++++--
 3 files changed, 98 insertions(+), 4 deletions(-)
net/rxrpc/ar-internal.h +1 -0
index 865f05fe37ab9..b079ec98aaa74 100644
@@ -1323,6 +1323,7 @@ void rxrpc_send_version_request(struct rxrpc_local *local,
  * local_object.c
  */
 void rxrpc_local_dont_fragment(const struct rxrpc_local *local, bool set);
+void rxrpc_adjust_rcvbuf(struct sock *sk);
 struct rxrpc_local *rxrpc_lookup_local(struct net *, const struct sockaddr_rxrpc *);
 struct rxrpc_local *rxrpc_get_local(struct rxrpc_local *, enum rxrpc_local_trace);
 struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *, enum rxrpc_local_trace);
net/rxrpc/io_thread.c +75 -2

116 lines not on this page · raw message

net/rxrpc/local_object.c +22 -2
index 169f9dfdaa77f..f519a93059244 100644
@@ -22,6 +22,19 @@
 
 static void rxrpc_local_rcu(struct rcu_head *);
 
+void rxrpc_adjust_rcvbuf(struct sock *sk)
+{
+	u32 rcvbuf, old_rcvbuf;
+
+	rcvbuf = READ_ONCE(rxrpc_rx_window_size) *
+		SKB_TRUESIZE(RXRPC_JUMBO(1)) * 2;
+	rcvbuf += rcvbuf / 4;
+	rcvbuf = min_t(u32, rcvbuf, READ_ONCE(sysctl_rmem_max));
+	old_rcvbuf = READ_ONCE(sk->sk_rcvbuf);
+	if (rcvbuf > old_rcvbuf)
+		WRITE_ONCE(sk->sk_rcvbuf, rcvbuf);
+}
+
 /*
  * Handle an ICMP/ICMP6 error turning up at the tunnel.  Push it through the
  * usual mechanism so that it gets parsed and presented through the UDP
@@ -198,6 +211,9 @@ static int rxrpc_open_socket(struct rxrpc_local *local, struct net *net)
 
 	/* set the socket up */
 	usk = local->socket->sk;
+	spin_lock_bh(&usk->sk_receive_queue.lock);
+	rxrpc_adjust_rcvbuf(usk);
+	spin_unlock_bh(&usk->sk_receive_queue.lock);
 	usk->sk_error_report = rxrpc_error_report;
 
 	switch (srx->transport.family) {
@@ -437,8 +453,8 @@ void rxrpc_destroy_local(struct rxrpc_local *local)
 	if (socket) {
 		local->socket = NULL;
 		kernel_sock_shutdown(socket, SHUT_RDWR);
-		socket->sk->sk_user_data = NULL;
-		sock_release(socket);
+		rcu_assign_sk_user_data(socket->sk, NULL);
+		synchronize_rcu();
 	}
 
 	/* At this point, there should be no more packets coming in to the
@@ -448,6 +464,10 @@ void rxrpc_destroy_local(struct rxrpc_local *local)
 	rxrpc_purge_queue(&local->rx_delay_queue);
 #endif
 	rxrpc_purge_queue(&local->rx_queue);
+
+	if (socket)
+		sock_release(socket);
+
 	rxrpc_purge_client_connections(local);
 	page_frag_cache_drain(&local->tx_alloc);
 }
Signature · 1 line
2.43.0
#2 lore raw
In reply to Zihan Xi
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

author
#3 lore raw
Quoted 10 lines · On Thu, Oct 8, 2026 at 1:35 PM <[email protected]> wrote:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

Quoted 8 lines

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

Hi,

This v8 is a rebase and resubmission of the same patch. The detailed information requested here, including how the issue was identified, is already included in the v6 cover letter.