rxrpc: Fix slab-out-of-bounds write in rxrpc_send_ACK() during PMTUD probing
Subsystems (3)
PATCH v2 1/1 rxrpc: Fix slab-out-of-bounds write in rxrpc_send_ACK() during PMTUD probing
When rxrpc initializes Path MTU Discovery (PMTUD) parameters for a peer, it computes the usable payload size as peer->if_mtu - peer->hdrsize. If an interface has an MTU smaller than the transport header size (such as a virtual interface configured with MTU 0), this unsigned subtraction underflows to a value near UINT_MAX.
As a result, peer->pmtud_bad and peer->pmtud_trial become excessively large. When rxrpc_send_ACK() builds a padded RXRPC_ACK_PING packet for PMTUD probing, it appends PAGE_SIZE zero-page entries to call->local->kvec inside a loop until len reaches probe_mtu. Because nr_kv is not checked against the fixed 47-element capacity of call->local->kvec, nr_kv advances past index 46 and triggers a KASAN slab-out-of-bounds write past the 1584-byte struct rxrpc_local object in the kmalloc-2k cache.
Fix this by guarding the subtraction against unsigned underflow when peer->if_mtu <= peer->hdrsize, clamping pmtud_good, pmtud_bad, and pmtud_trial to the usable payload limit, and only enabling pmtud_pending when the link supports more than the minimum floor. Additionally, ensure the padding loop in rxrpc_send_ACK() checks nr_kv < ARRAY_SIZE(call->local->kvec) before writing to the array.
---
Changes in v2:
- Derive peer->pmtud_bad from max_mtu rather than RXRPC_JUMBO(1) so jumbo DATA frames remain enabled.
- Cap max_mtu to the local->kvec payload limit so large legitimate MTUs cannot overflow local->kvec.
- Keep peer->pmtud_good at 500 and move variable declarations to the top of rxrpc_assess_MTU_size().
- Fix probe_mtu spelling in comments and clarify the PMTUD binary-search mechanism in the commit message.
v1-Link: https://lore.kernel.org/netdev/[email protected]/
--- net/rxrpc/output.c | 12 +++++++++++- net/rxrpc/peer_object.c | 21 ++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-)
net/rxrpc/output.c +11 -1
@@ -325,9 +325,19 @@ void rxrpc_send_ACK(struct rxrpc_call *call, u8 ack_reason,if (why == rxrpc_propose_ack_ping_for_mtu_probe) {size_t probe_mtu = call->peer->pmtud_trial +sizeof (struct rxrpc_wire_header ); +/* +* skip padding if the base ACK packets already meets/exceeds probe_mtu +*/ +if (len > probe_mtu) goto skip; -while (len < probe_mtu) { +/* +* pad the probe packet with zero pages up to probe_mtu, +* ensuring we never write past the fixed capacity of +* local->kvec. +*/ + +while (len < probe_mtu && nr_kv <ARRAY_SIZE (call->local->kvec)) {size_t part =umin (probe_mtu - len,PAGE_SIZE ); kv[nr_kv].iov_base =page_address (ZERO_PAGE (0 ));
net/rxrpc/peer_object.c +18 -3
@@ -156,6 +156,8 @@ 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, kvec_limit; +#ifdef CONFIG_AF_RXRPC_IPV6 struct flowi6 *fl6 = &fl.u.ip6;#endif
@@ -207,11 +209,24 @@ void rxrpc_assess_MTU_size(struct rxrpc_local *local, struct rxrpc_peer *peer) peer->tx_seg_max = dst->dev->gso_max_segs;dst_release (dst); - peer->max_data =umin (RXRPC_JUMBO (1 ), peer->if_mtu - peer->hdrsize); +/* +* Avoid unsigned underflow if the interface MTU is smaller than the +* transport header size (e.g., on virtual interfaces with MTU 0). +* Also cap the PMTUD upper bound to what local->kvec can hold when +* padding probes with PAGE_SIZE zero pages (3 header/SACK/trailer +* kvecs are reserved before the zero-page padding loop). +*/ + + max_mtu = peer->if_mtu > peer->hdrsize ? peer->if_mtu - peer->hdrsize :0 ; + kvec_limit = (ARRAY_SIZE (local->kvec) -3 ) *PAGE_SIZE - +sizeof (struct rxrpc_wire_header ); + max_mtu =umin (max_mtu, kvec_limit); + + peer->max_data =umin (RXRPC_JUMBO (1 ), max_mtu); peer->pmtud_good =500 ; - peer->pmtud_bad = peer->if_mtu - peer->hdrsize +1 ; + peer->pmtud_bad = max_mtu +1 ; peer->pmtud_trial =umin (peer->max_data, peer->pmtud_bad -1 ); - peer->pmtud_pending = true; + peer->pmtud_pending = max_mtu > peer->pmtud_good;_leave (" [if_mtu %u]" , peer->if_mtu); }
Signature · 1 line
2.56.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 (2) · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] The commit message's root-cause explanation does not match the code.
- [Low] In rxrpc_send_ACK() (net/rxrpc/output.c), the new comment above 'if (len > probe_mtu) goto skip;' says the code will 'skip padding if…
Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but the patch guards 'peer->if_mtu - peer->hdrsize' against unsigned underflow only…
- [Medium] This problem wasn't introduced by this patch, but rxrpc_init_peer() (peer_object.c:293) computes 'peer->max_data =…
--
rxrpc: Fix slab-out-of-bounds write in rxrpc_send_ACK() during PMTUD probing
In rxrpc_assess_MTU_size(), this patch guards the if_mtu - hdrsize subtraction against unsigned underflow. It also caps the PMTUD upper bound to what local->kvec can hold, and sets pmtud_pending only when the link is above the 500 byte floor. Separately, the zero-page padding loop in rxrpc_send_ACK() is now bounded by ARRAY_SIZE(call->local->kvec).
Quoted 4 lines
As a result,
peer->pmtud_badandpeer->pmtud_trialbecome excessively large. Whenrxrpc_send_ACK()builds a paddedRXRPC_ACK_PINGpacket for PMTUD probing, it appendsPAGE_SIZEzero-page entries tocall->local->kvecinside a loop until len reachesprobe_mtu.
[ ... ]
Quoted 4 lines
Fix this by guarding the subtraction against unsigned underflow when
peer->if_mtu<=peer->hdrsize, clampingpmtud_good,pmtud_bad, andpmtud_trialto the usable payload limit, and only enablingpmtud_pendingwhen the link supports more than the minimum floor.
[Severity: Medium]
Is this the mechanism behind the syzbot report? Before this patch, rxrpc_assess_MTU_size() already capped pmtud_trial:
peer->max_data = umin(RXRPC_JUMBO(1), peer->if_mtu - peer->hdrsize); ... peer->pmtud_trial = umin(peer->max_data, peer->pmtud_bad - 1);
RXRPC_JUMBO(1) is 28 + 1412 = 1440. So even if if_mtu - hdrsize underflows, the first probe_mtu is at most 1468 and needs only one padding kvec.
The only other place where pmtud_trial grows is rxrpc_input_probe_for_pmtud(), and it uses signed ints:
int good, trial, bad, jumbo;
good = peer->pmtud_good;
trial = peer->pmtud_trial;
bad = peer->pmtud_bad;
if (good >= bad - 1) {
...
return;
}As an int, an underflowed pmtud_bad is <= 0. This check returns at once, so trial never grows. rxrpc_adjust_mtu() only ever lowers pmtud_bad and pmtud_good.
The kvec_limit clamp also looks like a no-op for normal routes. dst_mtu() is limited to IP_MAX_MTU / IP6_MAX_MTU, which is well below the roughly 180KB needed to overrun 47 kvecs with 4K pages. The commit body never mentions this clamp. It is only described in the v2 changelog below the "---", which won't be committed.
So the write past local->kvec[] seems to be stopped only by the new nr_kv < ARRAY_SIZE(call->local->kvec) check in rxrpc_send_ACK(). A backport of just the rxrpc_assess_MTU_size() hunk would not stop the reported overflow.
Could the commit message identify what actually made probe_mtu large enough to overflow?
Separately, the message says pmtud_good is clamped to the usable payload limit, but the code still does:
peer->pmtud_good = 500;
When max_mtu is below 500, pmtud_good ends up larger than pmtud_bad. Should the description be updated, or is a clamp missing here?
Quoted 5 lines
net/rxrpc/output.c +0
-0
net/rxrpc/output.c void rxrpc_send_ACK(struct rxrpc_call *call, u8 ack_reason, · line 333
Quoted 9 lines
net/rxrpc/output.c +4
-0@@ -325,9 +325,19 @@ void rxrpc_send_ACK(struct rxrpc_call *call, u8 ack_reason,if (why == rxrpc_propose_ack_ping_for_mtu_probe) {size_t probe_mtu = call->peer->pmtud_trial +sizeof (struct rxrpc_wire_header ); +/* +* skip padding if the base ACK packets already meets/exceeds probe_mtu +*/ +if (len > probe_mtu) goto skip;
[Severity: Low]
Is this comment accurate? The skip label comes after the transmit:
trace_rxrpc_send_ack(call, why, ack_reason, ack_serial); rxrpc_send_ack_packet(call, nr_kv, len, ack_serial, why); skip: rxrpc_free_ack(call);
So the goto drops the whole ACK, not just the padding.
The "meets" case doesn't match either. When len == probe_mtu the branch isn't taken, the loop does nothing, and the ACK is sent.
[ ... ]
Quoted 4 lines
net/rxrpc/peer_object.c +0
-0
[ ... ]
Quoted 4 lines
net/rxrpc/peer_object.c +0
-0@@ -207,11 +209,24 @@ void rxrpc_assess_MTU_size(struct rxrpc_local *local, struct rxrpc_peer *peer) peer->tx_seg_max = dst->dev->gso_max_segs;dst_release (dst);
net/rxrpc/peer_object.c void rxrpc_assess_MTU_size(struct rxrpc_local *local, struct rxrpc_peer *peer) · line 220
Quoted 10 lines
net/rxrpc/peer_object.c +9
-1- peer->max_data =umin (RXRPC_JUMBO (1 ), peer->if_mtu - peer->hdrsize); +/* +* Avoid unsigned underflow if the interface MTU is smaller than the +* transport header size (e.g., on virtual interfaces with MTU 0). +* Also cap the PMTUD upper bound to what local->kvec can hold when +* padding probes with PAGE_SIZE zero pages (3 header/SACK/trailer +* kvecs are reserved before the zero-page padding loop). +*/ + + max_mtu = peer->if_mtu > peer->hdrsize ? peer->if_mtu - peer->hdrsize :0 ;
[Severity: Medium]
This isn't a bug introduced by this patch, but the same subtraction is still unguarded in two other places, and both put the result on the wire. In rxrpc_fill_out_ack():
if_mtu = call->peer->if_mtu - call->peer->hdrsize;
if (call->peer->ackr_adv_pmtud) {
max_mtu = umax(call->peer->max_data, rxrpc_rx_mtu);
} else {
if_mtu = umin(if_mtu, 1444);
max_mtu = if_mtu;
}
...
trailer->ifMTU = htonl(if_mtu);The connection-level final ACK in rxrpc_conn_retransmit_call() in conn_event.c does the same computation and fills trailer.ifMTU from it.
The new comment says if_mtu <= hdrsize can happen. In that case both sites wrap to about 0xFFFFFFxx. With ackr_adv_pmtud set, ifMTU tells the peer roughly 4G. Otherwise the ACK advertises 1444 for an interface that rxrpc_assess_MTU_size() now treats as having no usable payload.
Should these sites use the same guard, so all three agree on the value?
net/rxrpc/peer_object.c void rxrpc_assess_MTU_size(struct rxrpc_local *local, struct rxrpc_peer *peer) · line 225
Quoted 5 lines
net/rxrpc/peer_object.c +5
-0+ kvec_limit = (ARRAY_SIZE (local->kvec) -3 ) *PAGE_SIZE - +sizeof (struct rxrpc_wire_header ); + max_mtu =umin (max_mtu, kvec_limit); + + peer->max_data =umin (RXRPC_JUMBO (1 ), max_mtu);
[Severity: Medium]
This is a pre-existing issue, but this clamped assignment is skipped if the route lookup fails earlier in rxrpc_assess_MTU_size(). By that point peer->max_data may already have underflowed.
rxrpc_init_peer() runs while if_mtu is still 0 from kzalloc:
peer->hdrsize += sizeof(struct rxrpc_wire_header); peer->max_data = peer->if_mtu - peer->hdrsize;
So max_data starts out near 0xFFFFFFC8. The fallback at the top of rxrpc_assess_MTU_size() never fires for that value:
peer->if_mtu = 1500;
if (peer->max_data < peer->if_mtu - peer->hdrsize) {
...
peer->max_data = peer->if_mtu - peer->hdrsize;
}If hdrsize > 1500, the right-hand side wraps too.
If ip_route_output_ports() or ip6_route_output() then fails, the function returns with max_data still near UINT_MAX. It stays there until an ACK trailer or an ICMP message lowers it.
In that case pmtud_pending stays false, so this can't reach the kvec overflow. But with ackr_adv_pmtud set, rxrpc_fill_out_ack() advertises maxMTU = umax(max_data, rxrpc_rx_mtu). And the DF test in rxrpc_send_data_packet() can never be true:
len >= sizeof(struct rxrpc_wire_header) + call->peer->max_data) {Would it make sense to also give max_data a safe initial value in rxrpc_init_peer()?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119021202.525077-1-gowtham398gs%40gmail.com