Skip to contentSkip to conversation

sctp: keep chunk->transport in step with the list it is queued on

PATCH Applied Baul Lee 3 participants 3 messages Jul 29 – Aug 3

Subsystems (4)
lore
Share & tools
lore

Baul Lee

author
#0 lore raw

PATCH v3 1/1 sctp: keep chunk->transport in step with the list it is queued on

__sctp_outq_flush_rtx() moves a gap-acked chunk onto another transport's transmitted list without updating chunk->transport:

	if (chunk->tsn_gap_acked) {
		list_move_tail(&chunk->transmitted_list,
			       &transport->transmitted);
		continue;
	}

The chunk then sits on a live transport's list while chunk->transport still names a different one. If that transport is removed - sctp_assoc_rm_peer() from an ASCONF Delete-IP - sctp_transport_free() RCU-frees it and the chunk is left with a dangling pointer. sctp_assoc_rm_peer() scrubs peer->transmitted and asoc->outqueue.out_chunk_list, but the chunk is on neither.

The pointer is not followed while tsn_gap_acked is set. A SACK that reneges on the TSN clears the flag, and the next SACK reaches

	tchunk->transport->flight_size -= sctp_data_size(tchunk);

inside the freed transport. KASAN reports a slab-use-after-free read in sctp_check_transmitted(), freed from sctp_assoc_rm_peer(). Both the removal and the SACKs come from the association peer.

Set chunk->transport at the move. The ordinary resend path needs nothing:
it reaches its list_move_tail() only after sctp_packet_append_chunk() returned SCTP_XMIT_OK, and __sctp_packet_append_chunk() has rebound the chunk by then.

Discovered by XBOW, triaged by Baul Lee <[email protected]>

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")

---
v3:
- drop the redundant assignment on the ordinary resend path (Xin Long)
- trim the commit message

v2:
- fix the root cause in __sctp_outq_flush_rtx() rather than scrubbing the retransmit queue in sctp_assoc_rm_peer(), which cannot see chunks already migrated onto another transport's list
- correct the Fixes tag

Link to v1: https://lore.kernel.org/netdev/[email protected]/
Link to v2: https://lore.kernel.org/netdev/[email protected]/

 net/sctp/outqueue.c | 1 +
 1 file changed, 1 insertion(+)
net/sctp/outqueue.c +1 -0
index f6b8c13dafa4..e92fb9da4647 100644
@@ -650,6 +650,7 @@ static int __sctp_outq_flush_rtx(struct sctp_outq *q, struct sctp_packet *pkt,
 		if (chunk->tsn_gap_acked) {
 			list_move_tail(&chunk->transmitted_list,
 				       &transport->transmitted);
+			chunk->transport = transport;
 			continue;
 		}
 
Signature · 1 line
2.53.0
maintainer Acked-by on v3 1/1
#1 lore raw
Quoted 66 lines · Baul Lee

__sctp_outq_flush_rtx() moves a gap-acked chunk onto another transport's transmitted list without updating chunk->transport:

        if (chunk->tsn_gap_acked) {
                list_move_tail(&chunk->transmitted_list,
                               &transport->transmitted);
                continue;
        }

The chunk then sits on a live transport's list while chunk->transport still names a different one. If that transport is removed - sctp_assoc_rm_peer() from an ASCONF Delete-IP - sctp_transport_free() RCU-frees it and the chunk is left with a dangling pointer. sctp_assoc_rm_peer() scrubs peer->transmitted and asoc->outqueue.out_chunk_list, but the chunk is on neither.

The pointer is not followed while tsn_gap_acked is set. A SACK that reneges on the TSN clears the flag, and the next SACK reaches

        tchunk->transport->flight_size -= sctp_data_size(tchunk);

inside the freed transport. KASAN reports a slab-use-after-free read in sctp_check_transmitted(), freed from sctp_assoc_rm_peer(). Both the removal and the SACKs come from the association peer.

Set chunk->transport at the move. The ordinary resend path needs nothing:
it reaches its list_move_tail() only after sctp_packet_append_chunk() returned SCTP_XMIT_OK, and __sctp_packet_append_chunk() has rebound the chunk by then.

Discovered by XBOW, triaged by Baul Lee <[email protected]>

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")

---
v3:
- drop the redundant assignment on the ordinary resend path (Xin Long)
- trim the commit message

v2:
- fix the root cause in __sctp_outq_flush_rtx() rather than scrubbing the retransmit queue in sctp_assoc_rm_peer(), which cannot see chunks already migrated onto another transport's list
- correct the Fixes tag

Link to v1: https://lore.kernel.org/netdev/[email protected]/
Link to v2: https://lore.kernel.org/netdev/[email protected]/

 net/sctp/outqueue.c | 1 +
 1 file changed, 1 insertion(+)
net/sctp/outqueue.c +1 -1
index f6b8c13dafa4..e92fb9da4647 100644
@@ -650,6 +650,7 @@ static int __sctp_outq_flush_rtx(struct sctp_outq *q, struct sctp_packet *pkt,
                if (chunk->tsn_gap_acked) {
                        list_move_tail(&chunk->transmitted_list,
                                       &transport->transmitted);
+                       chunk->transport = transport;
                        continue;
                }
 
--
Quoted 2 lines

2.53.0

#2 lore raw
In reply to Baul Lee
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 10 lines · On Thu, 30 Jul 2026 01:00:28 +0900 you wrote:

__sctp_outq_flush_rtx() moves a gap-acked chunk onto another transport's transmitted list without updating chunk->transport:

	if (chunk->tsn_gap_acked) {
		list_move_tail(&chunk->transmitted_list,
			       &transport->transmitted);
		continue;
	}

[...]

Here is the summary with links:
- [net,v3] sctp: keep chunk->transport in step with the list it is queued on

    https://git.kernel.org/netdev/net/c/9f2cf069a9a7

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html