sctp: preserve the last transport during INIT error cleanup
Subsystems (3)
PATCH 1/1 sctp: preserve the last transport during INIT error cleanup
From: Lin Jiapeng <[email protected]>
On failure, sctp_process_init() removes all non-ACTIVE peer transports. An existing UNCONFIRMED transport is not promoted to ACTIVE by sctp_assoc_add_peer(), so cleanup can remove the last transport.
sctp_assoc_rm_peer() assumes another transport remains after removal. If the list becomes empty, it interprets the list head as a transport and passes the invalid replacement to sctp_assoc_set_primary() when removing the primary path, causing a NULL pointer dereference:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000045: 0000 [#1] SMP KASAN NOPTI KASAN: null-ptr-deref in range [0x0000000000000228-0x000000000000022f] RIP: 0010:sctp_ulpevent_notify_peer_addr_change+0x73/0xba0 Call Trace: <IRQ> sctp_assoc_rm_peer+0x186/0x9b0 sctp_process_init+0x1ff4/0x2810 sctp_do_sm+0x1c97/0x4560 sctp_assoc_bh_rcv+0x30b/0x630 sctp_rcv+0xb63/0x1220 Kernel panic - not syncing: Fatal exception in interrupt
Keep the last transport during cleanup so sctp_assoc_rm_peer() has a valid replacement. The retained transport is freed when the association is destroyed.
--- net/sctp/sm_make_chunk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/sctp/sm_make_chunk.c +2 -1
@@ -2528,7 +2528,8 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk,/* Release the transport structures. */ list_for_each_safe (pos, temp, &asoc->peer.transport_addr_list) { transport = list_entry(pos, struct sctp_transport, transports); -if (transport->state !=SCTP_ACTIVE ) +if (transport->state !=SCTP_ACTIVE && + !list_is_singular (&asoc->peer.transport_addr_list))sctp_assoc_rm_peer (asoc, transport); }
base-commit: 145480b28ca82e9fae789427cc4569e596515a32
Signature · 1 line
2.55.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
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).
- [Medium] When cleanup fails, the new !list_is_singular() guard in sctp_process_init() (net/sctp/sm_make_chunk.c) keeps whichever non-…
- [Low] The commit message says "The retained transport is freed when the association is destroyed", which suggests the kept non-ACTIVE…
- [Low] The comment at the clean_up label of sctp_process_init() (net/sctp/sm_make_chunk.c) still reads "/* Release the transport…
--
sctp: preserve the last transport during INIT error cleanup
This patch changes the clean_up path of sctp_process_init() so that the loop removing non-ACTIVE peer transports always keeps the last one. That stops sctp_assoc_rm_peer() from using the empty list head as the replacement transport and crashing in sctp_assoc_set_primary().
Quoted 3 lines
Keep the last transport during cleanup so
sctp_assoc_rm_peer()has a valid replacement. The retained transport is freed when the association is destroyed.
[Severity: Low]
Is this description accurate for the path in the oops trace above?
The trace shows sctp_do_sm()->sctp_process_init() with no sctp_sf_* frame. That is the SCTP_CMD_PEER_INIT path through sctp_cmd_process_init(). The sm_statefuns.c callers pass a new or temporary association and free it on failure. This caller instead runs on the live COOKIE_WAIT association:
net/sctp/sm_sideeffect.c:sctp_cmd_process_init() {
...
if (!sctp_process_init(asoc, chunk, sctp_source(chunk), peer_init, gfp))
error = -ENOMEM;
...
}In sctp_sf_do_5_1C_ack(), SCTP_CMD_PEER_INIT is queued before the TIMER_STOP(T1_INIT) and NEW_STATE(COOKIE_ECHOED) commands. Those commands are dropped when the interpreter bails out. The association stays in COOKIE_WAIT with T1-init armed, and primary_path, active_path and retran_path all point at the retained non-ACTIVE transport. Later T1-init retransmissions use that transport.
Before this patch, every transport left after a failed sctp_process_init() was ACTIVE.
Could the commit message describe this new state, where a live association keeps running on a single non-ACTIVE transport?
net/sctp/sm_make_chunk.c int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk, · line 2528
Quoted 6 lines
net/sctp/sm_make_chunk.c +0
-0@@ -2528,7 +2528,8 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk,/* Release the transport structures. */
[Severity: Low]
This isn't a bug, but the comment no longer matches the loop, which now keeps the last transport on purpose, whatever its state.
Could the comment say that one transport has to remain because sctp_assoc_rm_peer() takes the first list entry as the replacement path? Without that, the list_is_singular() check could later look redundant.
net/sctp/sm_make_chunk.c int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk, · line 2533
Quoted 6 lines
net/sctp/sm_make_chunk.c +2
-1list_for_each_safe (pos, temp, &asoc->peer.transport_addr_list) { transport = list_entry(pos, struct sctp_transport, transports); -if (transport->state !=SCTP_ACTIVE ) +if (transport->state !=SCTP_ACTIVE && + !list_is_singular (&asoc->peer.transport_addr_list))sctp_assoc_rm_peer (asoc, transport);
[Severity: Medium]
Does this keep the right transport? The guard keeps whichever non-ACTIVE transport the walk reaches last, which is the tail of asoc->peer.transport_addr_list. That is not necessarily the transport for peer_addr, the address the INIT-ACK came from.
For an existing peer, sctp_assoc_add_peer() only promotes SCTP_UNKNOWN:
net/sctp/associola.c:sctp_assoc_add_peer() {
...
if (peer->state == SCTP_UNKNOWN) {
peer->state = SCTP_ACTIVE;
}
return peer;
...
}New transports are appended with list_add_tail_rcu(), and sctp_process_param() adds the INIT-ACK address parameters as SCTP_UNCONFIRMED.
Consider this sequence:
1. The peer_addr transport X is UNCONFIRMED and is primary. This can happen through sctp_setsockopt_primary_addr() or through an INIT-ACK SET_PRIMARY parameter. A Stale Cookie error then runs sctp_cmd_del_non_primary(), which leaves only X and returns the association to COOKIE_WAIT.
2. A new INIT-ACK from X carries address parameters Y1 and Y2, which are appended as UNCONFIRMED. The list is now [X, Y1, Y2].
3. The packet reaches clean_up. One way is an address that collides with a transport of another association on the endpoint, so sctp_hash_transport() returns -EEXIST. Another is the ADD-IP without AUTH check.
The loop then removes X (primary moves to Y1), then Y1 (paths move to Y2), and keeps Y2. Y2 is an unverified address from the INIT-ACK that was just rejected.
sctp_assoc_rm_peer() has set init_last_sent_to to NULL, so when T1-init fires:
net/sctp/sm_sideeffect.c:sctp_cmd_interpreter() {
...
case SCTP_CMD_INIT_CHOOSE_TRANSPORT:
chunk = cmd->obj.chunk;
t = sctp_assoc_choose_alter_transport(asoc,
asoc->init_last_sent_to);
asoc->init_last_sent_to = t;
chunk->transport = t;
t->init_sent_count++;
/* Set the new transport as primary */
sctp_assoc_set_primary(asoc, t);
...
}INITs go to Y2 and Y2 becomes primary. Y2 also stays hashed in sctp_transport_hashtable, so packets from it still match this association. If X had been ACTIVE, X would have been kept and Y1 and Y2 removed instead.
Would it be more deterministic to keep the transport returned by the first sctp_assoc_add_peer(asoc, peer_addr, ...) call, or the current primary_path?
Quoted 2 lines
net/sctp/sm_make_chunk.c +0
-0}
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112092114.12458-1-ljp1205831794%40gmail.com
Xin Long
maintainerQuoted 140 lines · On Mon, Nov 16, 2026 at 4:22 AM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
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).
- [Medium] When cleanup fails, the new
!list_is_singular()guard insctp_process_init()(net/sctp/sm_make_chunk.c) keeps whichever non-…
- [Low] The commit message says "The retained transport is freed when the association is destroyed", which suggests the kept non-ACTIVE…
- [Low] The comment at theclean_uplabel ofsctp_process_init()(net/sctp/sm_make_chunk.c) still reads "/* Release the transport…--
sctp: preserve the last transport during INIT error cleanup
This patch changes the
clean_uppath ofsctp_process_init()so that the loop removing non-ACTIVE peer transports always keeps the last one. That stopssctp_assoc_rm_peer()from using the empty list head as the replacement transport and crashing insctp_assoc_set_primary().Quoted 3 lines
Keep the last transport during cleanup so
sctp_assoc_rm_peer()has a valid replacement. The retained transport is freed when the association is destroyed.[Severity: Low]
Is this description accurate for the path in the oops trace above?The trace shows sctp_do_sm()->sctp_process_init() with no sctp_sf_* frame. That is the
SCTP_CMD_PEER_INITpath throughsctp_cmd_process_init(). Thesm_statefuns.ccallers pass a new or temporary association and free it on failure. This caller instead runs on the liveCOOKIE_WAITassociation:net/sctp/sm_sideeffect.c:sctp_cmd_process_init() { ... if (!sctp_process_init(asoc, chunk, sctp_source(chunk), peer_init, gfp)) error = -ENOMEM; ... }In
sctp_sf_do_5_1C_ack(),SCTP_CMD_PEER_INITis queued before theTIMER_STOP(T1_INIT)andNEW_STATE(COOKIE_ECHOED)commands. Those commands are dropped when the interpreter bails out. The association stays inCOOKIE_WAITwith T1-init armed, andprimary_path,active_pathandretran_pathall point at the retained non-ACTIVE transport. Later T1-init retransmissions use that transport.Before this patch, every transport left after a failed
sctp_process_init()was ACTIVE.Could the commit message describe this new state, where a live association keeps running on a single non-ACTIVE transport?
net/sctp/sm_make_chunk.c int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk, · line 2528
Quoted 6 lines
net/sctp/sm_make_chunk.c +0
-0@@ -2528,7 +2528,8 @@ int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk,/* Release the transport structures. */ [Severity: Low]
This isn't a bug, but the comment no longer matches the loop, which now keeps the last transport on purpose, whatever its state.Could the comment say that one transport has to remain because
sctp_assoc_rm_peer()takes the first list entry as the replacement path? Without that, thelist_is_singular()check could later look redundant.net/sctp/sm_make_chunk.c int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk, · line 2533
Quoted 6 lines
net/sctp/sm_make_chunk.c +2
-1list_for_each_safe (pos, temp, &asoc->peer.transport_addr_list) { transport = list_entry(pos, struct sctp_transport, transports); -if (transport->state !=SCTP_ACTIVE ) +if (transport->state !=SCTP_ACTIVE && + !list_is_singular (&asoc->peer.transport_addr_list))sctp_assoc_rm_peer (asoc, transport);[Severity: Medium]
Does this keep the right transport? The guard keeps whichever non-ACTIVE transport the walk reaches last, which is the tail ofasoc->peer.transport_addr_list. That is not necessarily the transport forpeer_addr, the address the INIT-ACK came from.For an existing peer,
sctp_assoc_add_peer()only promotesSCTP_UNKNOWN:net/sctp/associola.c:sctp_assoc_add_peer() { ... if (peer->state == SCTP_UNKNOWN) { peer->state = SCTP_ACTIVE; } return peer; ... }New transports are appended with
list_add_tail_rcu(), andsctp_process_param()adds the INIT-ACK address parameters asSCTP_UNCONFIRMED.Consider this sequence:
1. The
peer_addrtransport X is UNCONFIRMED and is primary. This can happen throughsctp_setsockopt_primary_addr()or through an INIT-ACKSET_PRIMARYparameter. A Stale Cookie error then runssctp_cmd_del_non_primary(), which leaves only X and returns the association toCOOKIE_WAIT.2. A new INIT-ACK from X carries address parameters Y1 and Y2, which are appended as UNCONFIRMED. The list is now [X, Y1, Y2].
3. The packet reaches
clean_up. One way is an address that collides with a transport of another association on the endpoint, sosctp_hash_transport()returns-EEXIST. Another is the ADD-IP without AUTH check.The loop then removes X (primary moves to Y1), then Y1 (paths move to Y2), and keeps Y2. Y2 is an unverified address from the INIT-ACK that was just rejected.
sctp_assoc_rm_peer()has setinit_last_sent_toto NULL, so when T1-init fires:net/sctp/sm_sideeffect.c:sctp_cmd_interpreter() { ... case SCTP_CMD_INIT_CHOOSE_TRANSPORT: chunk = cmd->obj.chunk; t = sctp_assoc_choose_alter_transport(asoc, asoc->init_last_sent_to); asoc->init_last_sent_to = t; chunk->transport = t; t->init_sent_count++; /* Set the new transport as primary */ sctp_assoc_set_primary(asoc, t); ... }
Quoted 7 lines
INITs go to Y2 and Y2 becomes primary. Y2 also stays hashed in
sctp_transport_hashtable, so packets from it still match this association. If X had been ACTIVE, X would have been kept and Y1 and Y2 removed instead.Would it be more deterministic to keep the transport returned by the first
sctp_assoc_add_peer(asoc, peer_addr, ...)call, or the currentprimary_path?
Please try to fix it by using a check like:
!sctp_cmp_addr_exact(&transport->ipaddr, peer_addr)
instead of
!list_is_singular(&asoc->peer.transport_addr_list)
Thanks.
pw-bot: cr
Quoted 6 lines
net/sctp/sm_make_chunk.c int sctp_process_init(struct sctp_association *asoc, struct sctp_chunk *chunk, · line 2535
Quoted 3 lines
net/sctp/sm_make_chunk.c +0
-0}--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112092114.12458-1-ljp1205831794%40gmail.com