mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] rxrpc: Fix missing lower bound in rxrpc_resend_tlp()
@ 2026-11-22 13:55 Lin Ma
  2026-11-22 14:03 ` netdev-bot+sinfo
  2026-11-23 13:56 ` netdev-bot+sashiko
  0 siblings, 2 replies; 4+ messages in thread
From: Lin Ma @ 2026-11-22 13:55 UTC (permalink / raw)
  To: David Howells, Marc Dionne; +Cc: netdev, linux-afs, linux-kernel, Lin Ma

The fast path in rxrpc_resend_tlp() checks that tx_transmitted is before
the end of the tail Tx queue segment, but doesn't check that it is at or
after the segment's base.  If it is below the base, the wrong slot can be
selected and rxrpc_retransmit_data() may dereference a NULL txbuf.

This can happen when rxrpc_send_data_packet() fails to allocate its wire
header after rxrpc_transmit_fresh_data() has advanced tx_qtail and tx_top
but before tx_transmitted is updated.  A subsequent TLP probe can then
enter rxrpc_resend_tlp() in that state.

Add the missing lower-bound check, matching the slower queue walk.  The
reporter triggered this at runtime.

Fixes: 7c482665931b6 ("rxrpc: Implement RACK/TLP to deal with transmission stalls [RFC8985]")
Signed-off-by: Lin Ma <linma@zju.edu.cn>
---
 net/rxrpc/call_event.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/rxrpc/call_event.c b/net/rxrpc/call_event.c
index fec59d9338b9..4fca790a007f 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;


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] rxrpc: Fix missing lower bound in rxrpc_resend_tlp()
  2026-11-22 13:55 [PATCH net] rxrpc: Fix missing lower bound in rxrpc_resend_tlp() Lin Ma
@ 2026-11-22 14:03 ` netdev-bot+sinfo
  2026-11-23  3:40   ` Lin Ma
  2026-11-23 13:56 ` netdev-bot+sashiko
  1 sibling, 1 reply; 4+ messages in thread
From: netdev-bot+sinfo @ 2026-11-22 14:03 UTC (permalink / raw)
  To: Lin Ma; +Cc: David Howells, Marc Dionne, netdev, linux-afs, linux-kernel

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.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] rxrpc: Fix missing lower bound in rxrpc_resend_tlp()
  2026-11-22 14:03 ` netdev-bot+sinfo
@ 2026-11-23  3:40   ` Lin Ma
  0 siblings, 0 replies; 4+ messages in thread
From: Lin Ma @ 2026-11-23  3:40 UTC (permalink / raw)
  To: netdev-bot+sinfo
  Cc: David Howells, Marc Dionne, netdev, linux-afs, linux-kernel, Lin Ma

Hi,

Found by code inspection while reviewing the RACK/TLP retransmission
path, then reproduced on a KASAN kernel.

The symptom is a KASAN null-ptr-deref in the
rxrpc_resend_tlp() -> rxrpc_retransmit_data() path: a write of size 4 to
NULL+0x24 (txb->flags |= RXRPC_TXBUF_RESENT), because the TLP fast path
selects a slot below the tail queue segment's base.  That happens when
rxrpc_transmit_fresh_data() advances tx_qtail/tx_top and
rxrpc_send_data_packet() then fails to allocate its wire header before
tx_transmitted is updated.

Thanks,
Lin Ma


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net] rxrpc: Fix missing lower bound in rxrpc_resend_tlp()
  2026-11-22 13:55 [PATCH net] rxrpc: Fix missing lower bound in rxrpc_resend_tlp() Lin Ma
  2026-11-22 14:03 ` netdev-bot+sinfo
@ 2026-11-23 13:56 ` netdev-bot+sashiko
  1 sibling, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 13:56 UTC (permalink / raw)
  To: linma; +Cc: dhowells, marc.dionne, netdev, linux-afs, linux-kernel, kuba

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-23 13:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-22 13:55 [PATCH net] rxrpc: Fix missing lower bound in rxrpc_resend_tlp() Lin Ma
2026-11-22 14:03 ` netdev-bot+sinfo
2026-11-23  3:40   ` Lin Ma
2026-11-23 13:56 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®