Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: kyuwoncho18@gmail.com
Cc: lucien.xin@gmail.com, marcelo.leitner@gmail.com,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, willemb@google.com,
	junvyyang@tencent.com, linux-sctp@vger.kernel.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v5] sctp: fail the association when the INIT-ACK cannot be processed
Date: Tue, 01 Dec 2026 19:46:29 +0000	[thread overview]
Message-ID: <179615438903.3146.1656176944205841909@kernel.org> (raw)
In-Reply-To: <179606760834.392646.8338794156534192538@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 1 · Low: 0

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).

- [High] The fix is incomplete.
- [Medium] Every sctp_process_init() failure in sctp_sf_do_5_1C_ack()
  (net/sctp/sm_statefuns.c, around lines 606-613) is now reported as an…

--

sctp: fail the association when the INIT-ACK cannot be processed

This patch calls sctp_process_init() and sctp_auth_asoc_init_active_key()
directly from sctp_sf_do_5_1C_ack() instead of queueing them as side-effect
commands. If either step fails, the association is aborted with
sctp_stop_t1_and_abort(). The now unused SCTP_CMD_PEER_INIT and
SCTP_CMD_ASSOC_SHKEY commands are removed.

> diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
> index 6a4205de0aa69..206fa0b6cd4b8 100644
> --- a/net/sctp/sm_statefuns.c
> +++ b/net/sctp/sm_statefuns.c
> @@ -603,13 +603,26 @@ enum sctp_disposition sctp_sf_do_5_1C_ack(struct net *net,
>  
>  	initchunk = (struct sctp_init_chunk *)chunk->chunk_hdr;
>  
> -	sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT,
> -			SCTP_PEER_INIT(initchunk));
> +	if (!sctp_process_init((struct sctp_association *)asoc, chunk,
> +			       sctp_source(chunk), initchunk, GFP_ATOMIC)) {
> +		if (err_chunk)
> +			sctp_chunk_free(err_chunk);
> +		return sctp_stop_t1_and_abort(net, commands,
> +					      SCTP_ERROR_NO_RESOURCE, ENOMEM,
> +					      asoc, chunk->transport);
> +	}

[Severity: Medium]
sctp_process_init() returns 0 for allocation failures and also for peer
or policy rejections. Does this report ENOMEM for failures that have
nothing to do with memory?

The non-memory cases are the !src_match check, sctp_process_param()
rejections, and the ASCONF-without-AUTH check. That last check is active
by default because addip_noauth is 0:

net/sctp/sm_make_chunk.c:sctp_process_init() {
    ...
	if (!asoc->base.net->sctp.addip_noauth &&
	    (asoc->peer.asconf_capable && !asoc->peer.auth_capable)) {
		...
		goto clean_up;
	}
    ...
}

In those cases sctp_cmd_set_sk_err() sets sk->sk_err = ENOMEM on
non-UDP-style sockets. That value is what SO_ERROR returns after a
non-blocking connect(), and later sock_error() callers see it too. The
SCTP_ASSOC_CHANGE / SCTP_CANT_STR_ASSOC notification also carries
SCTP_ERROR_NO_RESOURCE.

A blocking connect() still returns ECONNREFUSED or ETIMEDOUT from
sctp_wait_for_connect(), because that path ignores sk_err.

The verification failure path just above reports a similar peer-caused
rejection as ECONNREFUSED with SCTP_ERROR_INV_PARAM. Before this patch the
-ENOMEM from the interpreter was dropped, T1-init kept retransmitting, and
the application eventually saw ETIMEDOUT.

The commit message says the ASCONF-without-AUTH case now aborts at once,
but it doesn't say that userspace will see ENOMEM / NO_RESOURCE for it.
Could the non-memory rejections report a different error here?

The comment in sctp_process_init() also still says:

	 * also give us an option to silently ignore the packet, which
	 * is what we'll do here.

The INIT-ACK path is the only caller with a non-temporary association,
and it now tears the association down instead. Should this comment be
updated?

>  
>  	/* SCTP-AUTH: generate the association shared keys so that
>  	 * we can potentially sign the COOKIE-ECHO.
>  	 */
> -	sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_SHKEY, SCTP_NULL());
> +	if (sctp_auth_asoc_init_active_key((struct sctp_association *)asoc,
> +					   GFP_ATOMIC)) {
> +		if (err_chunk)
> +			sctp_chunk_free(err_chunk);
> +		return sctp_stop_t1_and_abort(net, commands,
> +					      SCTP_ERROR_NO_RESOURCE, ENOMEM,
> +					      asoc, chunk->transport);
> +	}

[Severity: High]
The commit message describes the bug as:

  with the peer marked AUTH capable and asoc->shkey still NULL, a
  chunk that the peer wants authenticated ... takes a reference on the
  NULL key

Can the COOKIE-ECHO restart and collision handlers still reach this state?
sctp_sf_do_dupcook_a() and sctp_sf_do_dupcook_b() both call
sctp_sf_do_assoc_update()->sctp_assoc_update(). That function commits the
peer's AUTH state before it installs the key:

net/sctp/associola.c:sctp_assoc_update() {
    ...
	asoc->peer.auth_capable = new->peer.auth_capable;
    ...
	kfree(asoc->peer.peer_chunks);
	asoc->peer.peer_chunks = new->peer.peer_chunks;
	new->peer.peer_chunks = NULL;
    ...
	return sctp_auth_asoc_init_active_key(asoc, GFP_ATOMIC);
}

sctp_auth_asoc_init_active_key() can fail with -ENOMEM when
sctp_auth_asoc_create_secret() fails, and then asoc->shkey is never set.
Suppose the existing association had a non-AUTH peer, or was still in
COOKIE_WAIT (the dupcook_b collision case). Then shkey stays NULL while
auth_capable is now 1 and peer_chunks can list ABORT.

sctp_sf_do_assoc_update() then builds an ABORT on that association right
away:

net/sctp/sm_statefuns.c:sctp_sf_do_assoc_update() {
	if (!sctp_assoc_update(asoc, new))
		return 0;

	abort = sctp_make_abort(asoc, NULL, sizeof(struct sctp_errhdr));
    ...
}

This looks like it ends at the same crash site as the KASAN report:

sctp_make_abort()
  sctp_make_control()
    _sctp_make_chunk()
      sctp_auth_send_cid(SCTP_CID_ABORT, asoc) -> retval->auth = 1
    sctp_control_set_owner_w()
      chunk->shkey = asoc->shkey;  /* NULL */
      sctp_auth_shkey_hold(chunk->shkey);

A remote peer can trigger this if ep->auth_enable is set locally and the
same GFP_ATOMIC failure that the reproducer relies on happens. The peer
restarts or collides with an INIT that advertises AUTH (RANDOM, HMAC-ALGO,
and CHUNKS including ABORT), then echoes the cookie.

Should sctp_assoc_update() commit auth_capable and peer_chunks only after
the key is installed? Alternatively, should the ABORT built in
sctp_sf_do_assoc_update() not be authenticated?

>  
>  	/* Reset init error count upon receipt of INIT-ACK.  */
>  	sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179606760834.392646.8338794156534192538%40gmail.com

      reply	other threads:[~2026-12-01 19:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 19:45 [PATCH net v5] sctp: fail the association when the INIT-ACK cannot be processed Kyuwon Cho
2026-12-01 19:46 ` netdev-bot+sashiko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179615438903.3146.1656176944205841909@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=junvyyang@tencent.com \
    --cc=kuba@kernel.org \
    --cc=kyuwoncho18@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sctp@vger.kernel.org \
    --cc=lucien.xin@gmail.com \
    --cc=marcelo.leitner@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox