Skip to contentSkip to conversation

rxrpc: fix the test for a sequence number being in a Tx queue

PATCH In review Piyus Kedia 2 participants 2 messages Nov 27 – Dec 4

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rxrpc: fix the test for a sequence number being in a Tx queue

rxrpc_seq_in_txq() masks the sequence number down to the queue size and compares the result with tq->qbase, but qbase is a whole sequence number, not an index. A new queue is only allocated when send_top + 1 is a multiple of RXRPC_NR_TXQUEUE, so qbase is 0, 64, 128 and so on. That makes the test wrong in both directions: for the first queue it is true for every sequence that is a multiple of 64, and for every later queue it can never be true at all.

rxrpc_input_soft_ack_tq() uses it to decide whether the tail loss probe is in the queue it is looking at:

	if (call->tlp_serial &&
	    rxrpc_seq_in_txq(tq, call->tlp_seq) &&
	    test_bit(call->tlp_seq - tq->qbase, &new_acks))

new_acks is a single unsigned long, so when the probe is at sequence 64 and qbase is 0 the test_bit() reads the word past it. A peer that soft-acks without ever advancing firstPacket keeps the first queue alive while the call goes past sequence 64, and KASAN then reports:

  BUG: KASAN: stack-out-of-bounds in rxrpc_input_soft_ack_tq+0x467/0x530
  Read of size 8 at addr ffffc9001363f848 by task krxrpcio/0/9662
   rxrpc_input_soft_ack_tq+0x467/0x530 net/rxrpc/input.c:959
   rxrpc_input_soft_acks+0x2f0/0x4d0 net/rxrpc/input.c:1014
   rxrpc_input_ack+0x6c5/0x910 net/rxrpc/input.c:1199
   rxrpc_input_call_packet+0x1db/0x250 net/rxrpc/input.c:1290
   rxrpc_input_call_event+0x16d/0xc30 net/rxrpc/call_event.c:338
   rxrpc_io_thread+0x534/0x860 net/rxrpc/io_thread.c:531
  The buggy address belongs to stack of task krxrpcio/0/9662
   and is located at offset 40 in frame:
   rxrpc_input_soft_ack_tq+0x0/0x530
  This frame has 1 object:
   [32, 40) 'new_acks'

Compare the base of the queue instead of a masked sequence. The probe detection also starts working for queues other than the first.

We found this with a syzkaller-based fuzzing harness driven by an AI tool.

Fixes 7c482665931b ("rxrpc: Implement RACK/TLP to deal with transmission stalls [RFC8985]")

---
Tested on 7.4.0-rc1 (63fe746a609a) with KASAN, same config and image before and after, with only net/rxrpc rebuilt between the two. The fault needs the tail loss probe to land on a multiple of 64, so the reproducer walks the transfer size until it does and the rxrpc_tlp_probe tracepoint says where it landed:

  before   pq=0x40 (sequence 64)   KASAN: stack-out-of-bounds
  after    pq=0x40                 no report
 net/rxrpc/ar-internal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/rxrpc/ar-internal.h +1 -1
index 865f05fe37ab..cdf5736d88a4 100644
@@ -1580,7 +1580,7 @@
 
 static inline bool rxrpc_seq_in_txq(const struct rxrpc_txqueue *tq, rxrpc_seq_t seq)
 {
-	return (seq & (RXRPC_NR_TXQUEUE - 1)) == tq->qbase;
+	return (seq & ~(rxrpc_seq_t)RXRPC_TXQ_MASK) == tq->qbase;
 }
 
 static inline void rxrpc_queue_rx_call_packet(struct rxrpc_call *call, struct sk_buff *skb)
Signature · 1 line
2.43.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 49 lines · Piyus Kedia

rxrpc_seq_in_txq() masks the sequence number down to the queue size and compares the result with tq->qbase, but qbase is a whole sequence number, not an index. A new queue is only allocated when send_top + 1 is a multiple of RXRPC_NR_TXQUEUE, so qbase is 0, 64, 128 and so on. That makes the test wrong in both directions: for the first queue it is true for every sequence that is a multiple of 64, and for every later queue it can never be true at all.

rxrpc_input_soft_ack_tq() uses it to decide whether the tail loss probe is in the queue it is looking at:

	if (call->tlp_serial &&
	    rxrpc_seq_in_txq(tq, call->tlp_seq) &&
	    test_bit(call->tlp_seq - tq->qbase, &new_acks))

new_acks is a single unsigned long, so when the probe is at sequence 64 and qbase is 0 the test_bit() reads the word past it. A peer that soft-acks without ever advancing firstPacket keeps the first queue alive while the call goes past sequence 64, and KASAN then reports:

  BUG: KASAN: stack-out-of-bounds in rxrpc_input_soft_ack_tq+0x467/0x530
  Read of size 8 at addr ffffc9001363f848 by task krxrpcio/0/9662
   rxrpc_input_soft_ack_tq+0x467/0x530 net/rxrpc/input.c:959
   rxrpc_input_soft_acks+0x2f0/0x4d0 net/rxrpc/input.c:1014
   rxrpc_input_ack+0x6c5/0x910 net/rxrpc/input.c:1199
   rxrpc_input_call_packet+0x1db/0x250 net/rxrpc/input.c:1290
   rxrpc_input_call_event+0x16d/0xc30 net/rxrpc/call_event.c:338
   rxrpc_io_thread+0x534/0x860 net/rxrpc/io_thread.c:531
  The buggy address belongs to stack of task krxrpcio/0/9662
   and is located at offset 40 in frame:
   rxrpc_input_soft_ack_tq+0x0/0x530
  This frame has 1 object:
   [32, 40) 'new_acks'

Compare the base of the queue instead of a masked sequence. The probe detection also starts working for queues other than the first.

We found this with a syzkaller-based fuzzing harness driven by an AI tool.

Fixes 7c482665931b ("rxrpc: Implement RACK/TLP to deal with transmission stalls [RFC8985]")

---
Tested on 7.4.0-rc1 (63fe746a609a) with KASAN, same config and image before and after, with only net/rxrpc rebuilt between the two. The fault needs the tail loss probe to land on a multiple of 64, so the reproducer walks the transfer size until it does and the rxrpc_tlp_probe tracepoint says where it landed:

Quoted 2 lines
  before   pq=0x40 (sequence 64)   KASAN: stack-out-of-bounds
  after    pq=0x40                 no report