From: Kyuwon Cho <kyuwoncho18@gmail.com>
To: Xin Long <lucien.xin@gmail.com>
Cc: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
Willem de Bruijn <willemb@google.com>,
Jun Yang <junvyyang@tencent.com>,
linux-sctp@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH net v2] sctp: fail the association when the INIT-ACK cannot be processed
Date: Fri, 20 Nov 2026 13:55:05 +0900 [thread overview]
Message-ID: <179514851805.604157.8527055700821138420@gmail.com> (raw)
In-Reply-To: <CADvbK_citvtZ4eumLcx_szUvth7sQMP1oKu0mLbo0a3bD-eSxQ@mail.gmail.com>
sctp_sf_do_5_1C_ack() queues SCTP_CMD_PEER_INIT and SCTP_CMD_ASSOC_SHKEY.
If either fails to allocate memory, sctp_cmd_interpreter() stops there,
but the association stays: with the peer marked AUTH capable and
asoc->shkey still NULL, a chunk that the peer wants authenticated, such
as the ABORT built by close() with SO_LINGER {1, 0}, takes a reference
on the NULL key:
BUG: KASAN: null-ptr-deref in sctp_auth_shkey_hold (net/sctp/auth.c:113)
Write of size 4 at addr 0000000000000018
Call Trace:
sctp_auth_shkey_hold (net/sctp/auth.c:113)
sctp_control_set_owner_w (net/sctp/sm_make_chunk.c:112)
sctp_make_abort_user (net/sctp/sm_make_chunk.c:1016)
sctp_close (net/sctp/socket.c:1564)
Process the INIT-ACK and set up the association key directly in
sctp_sf_do_5_1C_ack(), and fail the association if either step fails.
SCTP_CMD_PEER_INIT and SCTP_CMD_ASSOC_SHKEY have no other users, so
remove them.
Fixes: 1b1e0bc99474 ("sctp: add refcnt support for sh_key")
Suggested-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: Kyuwon Cho <kyuwoncho18@gmail.com>
---
v2:
- As Xin suggested, process the INIT-ACK and set up the association key
directly in sctp_sf_do_5_1C_ack() and fail the association with
SCTP_CMD_INIT_FAILED, instead of skipping AUTH in sctp_auth_send_cid().
Remove SCTP_CMD_PEER_INIT and SCTP_CMD_ASSOC_SHKEY.
v1: https://lore.kernel.org/netdev/179505710266.3511678.14017674052424733262@gmail.com/
The patch was written with LLM assistance; we reviewed and tested it.
With it, the reproducer from the report no longer triggers the report,
also when the injected failure hits sctp_process_init() instead of the
association key.
include/net/sctp/command.h | 4 ----
net/sctp/sm_sideeffect.c | 40 --------------------------------------
net/sctp/sm_statefuns.c | 15 +++++++++++---
3 files changed, 12 insertions(+), 47 deletions(-)
diff --git a/include/net/sctp/command.h b/include/net/sctp/command.h
index 2058fabffbf6..8596e96c321a 100644
--- a/include/net/sctp/command.h
+++ b/include/net/sctp/command.h
@@ -34,7 +34,6 @@ enum sctp_verb {
SCTP_CMD_GEN_SACK, /* Send a Selective ACK (maybe). */
SCTP_CMD_PROCESS_SACK, /* Process an inbound SACK. */
SCTP_CMD_GEN_INIT_ACK, /* Generate an INIT ACK chunk. */
- SCTP_CMD_PEER_INIT, /* Process a INIT from the peer. */
SCTP_CMD_GEN_COOKIE_ECHO, /* Generate a COOKIE ECHO chunk. */
SCTP_CMD_CHUNK_ULP, /* Send a chunk to the sockets layer. */
SCTP_CMD_EVENT_ULP, /* Send a notification to the sockets layer. */
@@ -86,7 +85,6 @@ enum sctp_verb {
SCTP_CMD_ASSOC_CHANGE, /* generate and send assoc_change event */
SCTP_CMD_ADAPTATION_IND, /* generate and send adaptation event */
SCTP_CMD_PEER_NO_AUTH, /* generate and send authentication event */
- SCTP_CMD_ASSOC_SHKEY, /* generate the association shared keys */
SCTP_CMD_T1_RETRAN, /* Mark for retransmission after T1 timeout */
SCTP_CMD_UPDATE_INITTAG, /* Update peer inittag */
SCTP_CMD_SEND_MSG, /* Send the whole use message */
@@ -117,7 +115,6 @@ union sctp_arg {
struct sctp_association *asoc;
struct sctp_transport *transport;
struct sctp_bind_addr *bp;
- struct sctp_init_chunk *init;
struct sctp_ulpevent *ulpevent;
struct sctp_packet *packet;
struct sctp_sackhdr *sackh;
@@ -158,7 +155,6 @@ SCTP_ARG_CONSTRUCTOR(CHUNK, struct sctp_chunk *, chunk)
SCTP_ARG_CONSTRUCTOR(ASOC, struct sctp_association *, asoc)
SCTP_ARG_CONSTRUCTOR(TRANSPORT, struct sctp_transport *, transport)
SCTP_ARG_CONSTRUCTOR(BA, struct sctp_bind_addr *, bp)
-SCTP_ARG_CONSTRUCTOR(PEER_INIT, struct sctp_init_chunk *, init)
SCTP_ARG_CONSTRUCTOR(ULPEVENT, struct sctp_ulpevent *, ulpevent)
SCTP_ARG_CONSTRUCTOR(PACKET, struct sctp_packet *, packet)
SCTP_ARG_CONSTRUCTOR(SACKH, struct sctp_sackhdr *, sackh)
diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
index 35f540fb15fc..a95bf10b852b 100644
--- a/net/sctp/sm_sideeffect.c
+++ b/net/sctp/sm_sideeffect.c
@@ -698,32 +698,6 @@ static void sctp_cmd_assoc_failed(struct sctp_cmd_seq *commands,
sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
}
-/* Process an init chunk (may be real INIT/INIT-ACK or an embedded INIT
- * inside the cookie. In reality, this is only used for INIT-ACK processing
- * since all other cases use "temporary" associations and can do all
- * their work in statefuns directly.
- */
-static int sctp_cmd_process_init(struct sctp_cmd_seq *commands,
- struct sctp_association *asoc,
- struct sctp_chunk *chunk,
- struct sctp_init_chunk *peer_init,
- gfp_t gfp)
-{
- int error;
-
- /* We only process the init as a sideeffect in a single
- * case. This is when we process the INIT-ACK. If we
- * fail during INIT processing (due to malloc problems),
- * just return the error and stop processing the stack.
- */
- if (!sctp_process_init(asoc, chunk, sctp_source(chunk), peer_init, gfp))
- error = -ENOMEM;
- else
- error = 0;
-
- return error;
-}
-
/* Helper function to break out starting up of heartbeat timers. */
static void sctp_cmd_hb_timers_start(struct sctp_cmd_seq *cmds,
struct sctp_association *asoc)
@@ -1397,16 +1371,6 @@ static int sctp_cmd_interpreter(enum sctp_event_type event_type,
SCTP_CHUNK(new_obj));
break;
- case SCTP_CMD_PEER_INIT:
- /* Process a unified INIT from the peer.
- * Note: Only used during INIT-ACK processing. If
- * there is an error just return to the outter
- * layer which will bail.
- */
- error = sctp_cmd_process_init(commands, asoc, chunk,
- cmd->obj.init, gfp);
- break;
-
case SCTP_CMD_GEN_COOKIE_ECHO:
/* Generate a COOKIE ECHO chunk. */
new_obj = sctp_make_cookie_echo(asoc, chunk);
@@ -1772,10 +1736,6 @@ static int sctp_cmd_interpreter(enum sctp_event_type event_type,
sctp_cmd_peer_no_auth(commands, asoc);
break;
- case SCTP_CMD_ASSOC_SHKEY:
- error = sctp_auth_asoc_init_active_key(asoc,
- GFP_ATOMIC);
- break;
case SCTP_CMD_UPDATE_INITTAG:
asoc->peer.i.init_tag = cmd->obj.u32;
break;
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index 64519fd8f943..598eafdc5261 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -603,13 +603,22 @@ 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)) {
+ sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
+ SCTP_U16(SCTP_ERROR_NO_RESOURCE));
+ return SCTP_DISPOSITION_CONSUME;
+ }
/* 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)) {
+ sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
+ SCTP_U16(SCTP_ERROR_NO_RESOURCE));
+ return SCTP_DISPOSITION_CONSUME;
+ }
/* Reset init error count upon receipt of INIT-ACK. */
sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
--
2.43.0
prev parent reply other threads:[~2026-11-20 4:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 3:04 [BUG] sctp: auth: NULL asoc->shkey after a failed SCTP_CMD_ASSOC_SHKEY makes close() oops Kyuwon Cho
2026-11-19 20:01 ` Xin Long
2026-11-20 4:55 ` Kyuwon Cho [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=179514851805.604157.8527055700821138420@gmail.com \
--to=kyuwoncho18@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=junvyyang@tencent.com \
--cc=kuba@kernel.org \
--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
all inboxes | Powered by JetHome®