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. Reported-by: syzbot+0cd6f4783442ac67b56d@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=0cd6f4783442ac67b56d Fixes: eeaedc5449d9 ("rxrpc: Implement path-MTU probing using padded PING ACKs (RFC8899)") Signed-off-by: Gowtham S Bhushan --- 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/20261111144846.838278-1-gowtham398gs@gmail.com/ --- net/rxrpc/output.c | 12 +++++++++++- net/rxrpc/peer_object.c | 21 ++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/net/rxrpc/output.c b/net/rxrpc/output.c index 88cad087f13b..a9d083076a16 100644 --- a/net/rxrpc/output.c +++ b/net/rxrpc/output.c @@ -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)); diff --git a/net/rxrpc/peer_object.c b/net/rxrpc/peer_object.c index fa9a406e1168..32b75a7617f9 100644 --- a/net/rxrpc/peer_object.c +++ b/net/rxrpc/peer_object.c @@ -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); } -- 2.56.0