* [PATCH net] sctp: preserve the last transport during INIT error cleanup
@ 2026-11-12 9:20 Lin Jiapeng
2026-11-16 9:22 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: Lin Jiapeng @ 2026-11-12 9:20 UTC (permalink / raw)
To: netdev
Cc: Lin Jiapeng, Marcelo Ricardo Leitner, Xin Long, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Vlad Yasevich, linux-sctp, linux-kernel
From: Lin Jiapeng <jiapenglin@tencent.com>
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.
Fixes: add52379dde2 ("sctp: Fix oops when INIT-ACK indicates that peer doesn't support AUTH")
Cc: stable@vger.kernel.org
Reported-by: TencentOS Corvus AI <corvus@tencent.com>
Signed-off-by: Lin Jiapeng <jiapenglin@tencent.com>
---
net/sctp/sm_make_chunk.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index 15c2d87575a8..e4b7dacf174e 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -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
--
2.55.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] sctp: preserve the last transport during INIT error cleanup
2026-11-12 9:20 [PATCH net] sctp: preserve the last transport during INIT error cleanup Lin Jiapeng
@ 2026-11-16 9:22 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-16 9:22 UTC (permalink / raw)
To: ljp1205831794
Cc: netdev, jiapenglin, marcelo.leitner, lucien.xin, davem, edumazet,
kuba, pabeni, horms, vladislav.yasevich, linux-sctp, linux-kernel
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().
> 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?
> diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
> index 15c2d87575a8a..e4b7dacf174e6 100644
> --- a/net/sctp/sm_make_chunk.c
> +++ b/net/sctp/sm_make_chunk.c
> @@ -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.
> 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);
[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?
> }
>
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112092114.12458-1-ljp1205831794%40gmail.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-16 9:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 9:20 [PATCH net] sctp: preserve the last transport during INIT error cleanup Lin Jiapeng
2026-11-16 9:22 ` 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