Re: [PATCH net] rxrpc: Fix missing lower bound in rxrpc_resend_tlp()

From: netdev-bot+sashiko

Date: Mon Nov 23 2026 - 08:58:10 EST


Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 (1) · High: 1 · Medium: 0 · Low: 0

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).

- [High] The fix is incomplete.

Pre-existing issues:
- [Critical] This problem wasn't introduced by this patch, but
rxrpc_resend_tlp() can still pass a freed (NULL) txbuf slot to…

--

rxrpc: Fix missing lower bound in rxrpc_resend_tlp()

This adds a lower-bound check on the tail Tx queue segment in the fast
path of rxrpc_resend_tlp(), so that it matches the slower queue walk.
According to the commit message, the bad state comes from
rxrpc_send_data_packet() failing to allocate its wire header. By then
rxrpc_transmit_fresh_data() has advanced tx_qtail and tx_top, but
tx_transmitted has not been updated.

> diff --git a/net/rxrpc/call_event.c b/net/rxrpc/call_event.c
> index 21be9c86d7a74..e5578779b3f74 100644
> --- a/net/rxrpc/call_event.c
> +++ b/net/rxrpc/call_event.c
> @@ -141,6 +141,7 @@ void rxrpc_resend_tlp(struct rxrpc_call *call)
> /* There's a chance it'll be on the tail segment of the queue. */
> req.tq = READ_ONCE(call->tx_qtail);
> if (req.tq &&
> + after_eq(call->tx_transmitted, req.tq->qbase) &&
> before(call->tx_transmitted, req.tq->qbase + RXRPC_NR_TXQUEUE)) {
> rxrpc_retransmit_data(call, &req);
> return;

[Severity: High]
Does this fix the inconsistent state itself, or only one of the places that
consume it?

The commit message names the wire header allocation failure in
rxrpc_send_data_packet() as the trigger. rxrpc_transmit_fresh_data()
commits the new tail before it sends:

net/rxrpc/call_event.c:rxrpc_transmit_fresh_data() {
...
call->tx_qtail = tq;
call->tx_top = seq;

space -= req.n;
rxrpc_send_data_packet(call, &req);
...
}

rxrpc_send_data_packet() then returns before tx_transmitted is advanced:

net/rxrpc/output.c:rxrpc_send_data_packet() {
...
whdr = page_frag_alloc(&call->local->tx_alloc, sizeof(*whdr), GFP_NOFS);
if (!whdr)
return; /* Drop the packet if no memory. */
...
if (seq == call->tx_transmitted + 1)
call->tx_transmitted = seq + req->n - 1;
...
}

Nothing appears to bring tx_transmitted back in line with tx_top later, so
tx_top stays ahead of tx_transmitted.

On the next pass of the while (space > 0) loop in
rxrpc_transmit_fresh_data(), req.seq is still built from tx_transmitted:

struct rxrpc_send_data_req req = {
.now = ktime_get_real(),
.seq = call->tx_transmitted + 1,

But req.tq is taken from the segment holding tx_top + 1.
rxrpc_prepare_data_packet() then indexes that segment with the stale seq:

struct rxrpc_txbuf *txb = tq->bufs[seq & RXRPC_TXQ_MASK];

Here is an example with RXRPC_NR_TXQUEUE=64 and a jumbo limit of 4,
starting from tx_transmitted = tx_top = 60 and send_top = 70:

- batch 61..64 sets tx_qtail to segment B (qbase 64) and tx_top to 64,
then the wire header allocation fails
- the next pass uses req.seq = 61 with req.tq = B
- txb = B->bufs[61] is the slot for seq 125, which was never filled, so
it is NULL
- B's segment_lost, segment_xmit_ts[61] and segment_serial[61] are
updated for the wrong slot
- rxrpc_prepare_data_subpacket() then does
txb->data - sizeof(*jumbo) on the NULL txb

If the wrong slot happens to be filled, does another packet's payload
go out under this header's seq instead?

There also seems to be a case where the call stalls. The loop breaks
once tx_top reaches send_top. If the LAST txbuf was in the skipped range,
rxrpc_close_tx_phase() has already run and tx_qtail is NULL. Packets
tx_transmitted+1..send_top would then never be sent, because
rxrpc_resend() and TLP only look up to tx_transmitted.

Would it be better to keep tx_transmitted, tx_top and tx_qtail
consistent on the allocation failure path? One option is to not commit
tx_top and tx_qtail until the send succeeds, another is to roll them
back. Either would make this bounds check in a single consumer
unnecessary.

[Severity: Critical]
This isn't a bug introduced by this patch, but can rxrpc_resend_tlp()
still pass a freed txbuf slot to rxrpc_retransmit_data() even with the
new check?

A peer can send an ACKALL during the send phase. That is
CLIENT_SEND_REQUEST or SERVER_SEND_REPLY, before the LAST packet has
been queued (e.g. sendmsg with MSG_MORE):

net/rxrpc/input.c:rxrpc_input_ackall() {
...
if (rxrpc_rotate_tx_window(call, call->tx_transmitted, &summary))
rxrpc_end_tx_phase(call, false, rxrpc_eproto_unexpected_ackall);
}

rxrpc_rotate_tx_window() puts each txbuf up to tx_transmitted and sets
tq->bufs[ix] = NULL. It keeps the tail segment, so tx_qtail still covers
tx_transmitted.

Since rot_last is false, rxrpc_end_tx_phase() isn't called.
rack_timer_mode stays at RXRPC_CALL_RACKTIMER_TLP_PTO, rack_timo_at stays
armed, and acks_hard_ack isn't updated.

When the PTO fires, rxrpc_tlp_send_probe() checks the stale
acks_hard_ack:

if (after_eq(call->acks_hard_ack, call->tx_transmitted))
return; /* Everything we transmitted has been acked. */

tlp_serial is 0. tlp_rtt_taken never seems to be assigned, so it differs
from rtt_taken once an RTT sample has been taken. If send_top equals
tx_transmitted, or there is no window space, the else branch calls
rxrpc_resend_tlp().

In rxrpc_resend_tlp() both bounds checks pass, because the slot index
is correct and only the txbuf has been freed. rxrpc_retransmit_data()
then does this with txb == NULL:

struct rxrpc_txbuf *txb = tq->bufs[ix];
...
txb->flags |= RXRPC_TXBUF_RESENT;

Could the TLP guard check tx_bottom instead? Alternatively, the ACKALL
path could update acks_hard_ack and stop the RACK timer. A NULL txb check
in rxrpc_retransmit_data() would also cover this.

--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122135515.3989708-1-linma%40zju.edu.cn