Skip to contentSkip to conversation

rxrpc: Fix kvec overflow when padding a path-MTU probe ACK

PATCH Applied Jun Yang 3 participants 3 messages Nov 25 – Dec 3

Subsystems (3)
lore
Share & tools
lore

Jun Yang

author
#0 lore raw

PATCH 1/1 rxrpc: Fix kvec overflow when padding a path-MTU probe ACK

From: Jun Yang <[email protected]>

rxrpc_send_ACK() pads a PMTUD PING ACK out to call->peer->pmtud_trial + sizeof(struct rxrpc_wire_header) by appending one PAGE_SIZE zeropage kvec per page. The table it fills is call->local->kvec[], sized
1 + RXRPC_MAX_NR_JUMBO == 47 entries so that it can also hold a maximum-size jumbo DATA packet. rxrpc_alloc_ack() has already used three entries, so only 44 zeropage entries fit, and the loop has no upper
bound: a probe larger than 44 * PAGE_SIZE writes past the end of the rxrpc_local allocation.

pmtud_trial can be driven that large because rxrpc_assess_MTU_size() takes the peer MTU straight from dst_mtu(). An IPv4 output XFRM policy with an unresolvable ESP template makes xfrm_lookup_route() return a blackhole dst; ipv4_blackhole_route() points it at the loopback device and dst_blackhole_mtu() returns dst_dev(dst)->mtu without the IP_MAX_MTU clamp that ip_dst_mtu_maybe_forward() applies to ordinary IPv4 dsts. With loopback's MTU raised inside a netns, peer->pmtud_bad = if_mtu - hdrsize + 1 becomes huge and the probe search in rxrpc_input_probe_for_pmtud() moves pmtud_trial far beyond 64K.

The XFRM policy only has to match the sport 7001 / dport 7000 that rxrpc_assess_MTU_size() hardcodes, so it blackholes the route assessment without affecting the call's own packets. CAP_NET_ADMIN in a new netns is enough, which an unprivileged user obtains with unshare(CLONE_NEWUSER|CLONE_NEWNET).

Clamp the route MTU to the maximum size of an IP datagram in rxrpc_assess_MTU_size(), which keeps pmtud_bad bounded, and skip the probe altogether in rxrpc_send_ACK() if its padding would not fit the kvec table.

BUG: KASAN: slab-out-of-bounds in rxrpc_send_ACK (net/rxrpc/output.c:333)
Write of size 8 at addr ffff8880312f3630 by task krxrpcio/0/10441

Call Trace:
 rxrpc_send_ACK (net/rxrpc/output.c:333)
 rxrpc_input_call_event (net/rxrpc/call_event.c:484)
Fixes eeaedc5449d9 ("rxrpc: Implement path-MTU probing using padded PING ACKs (RFC8899)")

---
A KASAN reproducer for this issue is available if requested.

 net/rxrpc/output.c      | 4 ++++
 net/rxrpc/peer_object.c | 6 +++++-
 2 files changed, 9 insertions(+), 1 deletion(-)
net/rxrpc/output.c +4 -0
index 88cad087f13b..57fae49e9ce8 100644
@@ -327,6 +327,10 @@ void rxrpc_send_ACK(struct rxrpc_call *call, u8 ack_reason,
 
 		if (len > probe_mtu)
 			goto skip;
+		/* The zeropage padding must fit in the kvec table. */
+		if (probe_mtu - len >
+		    (ARRAY_SIZE(call->local->kvec) - nr_kv) * PAGE_SIZE)
+			goto skip;
 		while (len < probe_mtu) {
 			size_t part = umin(probe_mtu - len, PAGE_SIZE);
 
net/rxrpc/peer_object.c +5 -1
index fa9a406e1168..310fe94d9f6c 100644
@@ -156,6 +156,7 @@ void rxrpc_assess_MTU_size(struct rxrpc_local *local, struct rxrpc_peer *peer)
 	struct rtable *rt;
 	struct flowi fl;
 	struct flowi4 *fl4 = &fl.u.ip4;
+	unsigned int max_mtu;
 #ifdef CONFIG_AF_RXRPC_IPV6
 	struct flowi6 *fl6 = &fl.u.ip6;
 #endif
@@ -179,6 +180,7 @@ void rxrpc_assess_MTU_size(struct rxrpc_local *local, struct rxrpc_peer *peer)
 			return;
 		}
 		dst = &rt->dst;
+		max_mtu = IP_MAX_MTU;
 		break;
 
 #ifdef CONFIG_AF_RXRPC_IPV6
@@ -195,6 +197,7 @@ void rxrpc_assess_MTU_size(struct rxrpc_local *local, struct rxrpc_peer *peer)
 			_leave(" [route err %d]", dst->error);
 			return;
 		}
+		max_mtu = IP6_MAX_MTU;
 		break;
 #endif
 
@@ -202,7 +205,8 @@ void rxrpc_assess_MTU_size(struct rxrpc_local *local, struct rxrpc_peer *peer)
 		BUG();
 	}
 
-	peer->if_mtu = dst_mtu(dst);
+	/* A blackhole dst reports the device MTU with no IP_MAX_MTU clamp. */
+	peer->if_mtu = umin(dst_mtu(dst), max_mtu);
 	peer->hdrsize += dst->header_len + dst->trailer_len;
 	peer->tx_seg_max = dst->dev->gso_max_segs;
 	dst_release(dst);

base-commit: c5de2ce2fccdb7d3b48946179634eaa3d7ce2e7e
prerequisite-patch-id: 73dc5424c05c31bf826b8438dff12ad2acee90e4

Signature · 1 line
2.56.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 39 lines · Jun Yang

From: Jun Yang <[email protected]>

rxrpc_send_ACK() pads a PMTUD PING ACK out to call->peer->pmtud_trial + sizeof(struct rxrpc_wire_header) by appending one PAGE_SIZE zeropage kvec per page. The table it fills is call->local->kvec[], sized
1 + RXRPC_MAX_NR_JUMBO == 47 entries so that it can also hold a maximum-size jumbo DATA packet. rxrpc_alloc_ack() has already used three entries, so only 44 zeropage entries fit, and the loop has no upper
bound: a probe larger than 44 * PAGE_SIZE writes past the end of the rxrpc_local allocation.

pmtud_trial can be driven that large because rxrpc_assess_MTU_size() takes the peer MTU straight from dst_mtu(). An IPv4 output XFRM policy with an unresolvable ESP template makes xfrm_lookup_route() return a blackhole dst; ipv4_blackhole_route() points it at the loopback device and dst_blackhole_mtu() returns dst_dev(dst)->mtu without the IP_MAX_MTU clamp that ip_dst_mtu_maybe_forward() applies to ordinary IPv4 dsts. With loopback's MTU raised inside a netns, peer->pmtud_bad = if_mtu - hdrsize + 1 becomes huge and the probe search in rxrpc_input_probe_for_pmtud() moves pmtud_trial far beyond 64K.

The XFRM policy only has to match the sport 7001 / dport 7000 that rxrpc_assess_MTU_size() hardcodes, so it blackholes the route assessment without affecting the call's own packets. CAP_NET_ADMIN in a new netns is enough, which an unprivileged user obtains with unshare(CLONE_NEWUSER|CLONE_NEWNET).

Clamp the route MTU to the maximum size of an IP datagram in rxrpc_assess_MTU_size(), which keeps pmtud_bad bounded, and skip the probe altogether in rxrpc_send_ACK() if its padding would not fit the kvec table.

BUG: KASAN: slab-out-of-bounds in rxrpc_send_ACK (net/rxrpc/output.c:333)
Write of size 8 at addr ffff8880312f3630 by task krxrpcio/0/10441

Call Trace:
 rxrpc_send_ACK (net/rxrpc/output.c:333)
 rxrpc_input_call_event (net/rxrpc/call_event.c:484)
Quoted 4 lines
Fixes eeaedc5449d9 ("rxrpc: Implement path-MTU probing using padded PING ACKs (RFC8899)")
#2 lore raw
In reply to Jun Yang
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 11 lines · On Wed, 25 Nov 2026 15:16:38 +0800 you wrote:

From: Jun Yang <[email protected]>

rxrpc_send_ACK() pads a PMTUD PING ACK out to call->peer->pmtud_trial + sizeof(struct rxrpc_wire_header) by appending one PAGE_SIZE zeropage kvec per page. The table it fills is call->local->kvec[], sized
1 + RXRPC_MAX_NR_JUMBO == 47 entries so that it can also hold a maximum-size jumbo DATA packet. rxrpc_alloc_ack() has already used three entries, so only 44 zeropage entries fit, and the loop has no upper
bound: a probe larger than 44 * PAGE_SIZE writes past the end of the rxrpc_local allocation.

Quoted 1 line

[...]

Here is the summary with links:
- [net] rxrpc: Fix kvec overflow when padding a path-MTU probe ACK

    https://git.kernel.org/netdev/net/c/90ae4042bd9f

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html