Re: [PATCH net] sctp: preserve the last transport during INIT error cleanup
From: Xin Long
Date: Mon Nov 16 2026 - 20:59:28 EST
On Mon, Nov 16, 2026 at 4:22 AM <netdev-bot+sashiko@xxxxxxxxxx> 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 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?
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
>
> > }
> >
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261112092114.12458-1-ljp1205831794%40gmail.com