* [BUG] sctp: auth: NULL asoc->shkey after a failed SCTP_CMD_ASSOC_SHKEY makes close() oops
@ 2026-11-19 3:04 Kyuwon Cho
2026-11-19 20:01 ` Xin Long
2026-11-23 3:26 ` [BUG] sctp: auth: NULL asoc->shkey after a failed SCTP_CMD_ASSOC_SHKEY makes close() oops netdev-bot+sashiko
0 siblings, 2 replies; 4+ messages in thread
From: Kyuwon Cho @ 2026-11-19 3:04 UTC (permalink / raw)
To: Marcelo Ricardo Leitner, Xin Long
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Simon Horman, Jun Yang, linux-sctp, netdev, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 3714 bytes --]
Hi Marcelo, Xin,
While testing v7.4-rc3 with an LLM-guided test generator that we are
developing as a research prototype, we found that an SCTP association
whose shared key could not be set up still builds authenticated chunks,
with a NULL key. Closing such a socket with SO_LINGER {1, 0} then
oopses in sctp_auth_shkey_hold(); here as an unprivileged user:
BUG: KASAN: null-ptr-deref in sctp_auth_shkey_hold (include/linux/refcount.h:366 net/sctp/auth.c:113)
Write of size 4 at addr 0000000000000018 by task test/115
CPU: 1 UID: 65534 PID: 115 Comm: test Not tainted 7.4.0-rc3 #1 PREEMPT(lazy)
Call Trace:
<TASK>
sctp_auth_shkey_hold (include/linux/refcount.h:366 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:1492 net/sctp/sm_make_chunk.c:953 net/sctp/sm_make_chunk.c:1016)
sctp_close (net/sctp/socket.c:1564)
inet_release (net/ipv4/af_inet.c:443)
__sock_release (net/socket.c:735)
sock_close (net/socket.c:1529)
__fput (fs/file_table.c:512)
fput_close_sync (fs/file_table.c:618)
__x64_sys_close (fs/open.c:1574 fs/open.c:1597 fs/open.c:1584)
do_syscall_64 (arch/x86/entry/syscall_64.c:61 arch/x86/entry/syscall_64.c:89)
entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
</TASK>
When the INIT-ACK arrives, sctp_sf_do_5_1C_ack() queues
SCTP_CMD_PEER_INIT, which records that the peer supports AUTH and which
chunks it wants authenticated, and then SCTP_CMD_ASSOC_SHKEY:
case SCTP_CMD_ASSOC_SHKEY:
error = sctp_auth_asoc_init_active_key(asoc,
GFP_ATOMIC);
break;
sctp_auth_asoc_init_active_key() returns -ENOMEM before it sets
asoc->shkey when the secret cannot be allocated:
secret = sctp_auth_asoc_create_secret(asoc, ep_key, gfp);
if (!secret)
return -ENOMEM;
...
asoc->shkey = ep_key;
sctp_cmd_interpreter() then drops the remaining commands, but the
association stays, with peer.auth_capable set and asoc->shkey NULL. If
the peer listed ABORT among the chunks to authenticate, the ABORT that
close() builds has chunk->auth set, and sctp_control_set_owner_w()
takes a reference on the NULL key:
if (chunk->auth) {
if (!chunk->shkey)
chunk->shkey = asoc->shkey;
sctp_auth_shkey_hold(chunk->shkey);
}
The peer can be remote; the local side needs one GFP_ATOMIC allocation
to fail while it processes the INIT-ACK. The reproducer makes it fail
with fail-nth (CONFIG_FAULT_INJECTION) and runs as an unprivileged user
(uid 65534) in its own user and network namespace: a listener on
127.0.0.1 with AUTH enabled and ABORT in its SCTP_AUTH_CHUNK list, and
a client that connects with fail-nth set to 1..60 and closes each
socket with SO_LINGER {1, 0}. On an x86_64 QEMU guest with 2 vCPUs and
KASAN (gcc 13.3), it oopses every time.
The reference on the shared key comes from 1b1e0bc99474 ("sctp: add
refcnt support for sh_key"). ad1320865b18 ("sctp: hold shkey across
socket migration") and 52ffeaa358d1 ("sctp: re-point retained control
chunks on association migration"), both in v7.4-rc3, handle the
migration paths and not this one.
Checked against v7.4-rc3 (aebb72744764); this code is the same in net
(2a324a58a084).
A patch is attached (git format-patch against v7.4-rc3; it applies to
net (2a324a58a084)):
0001-sctp-auth-don-t-authenticate-chunks-without-an-assoc.patch
It makes sctp_auth_send_cid() return false while asoc->shkey is NULL, so
chunks are not marked for authentication until the association has a
key. It was written with LLM assistance; we reviewed and tested it. With
it, the reproducer no longer triggers the report.
The reproducer (repro.c), the kernel config and the patch are attached.
Thanks,
Kyuwon Cho
[-- Attachment #2: repro.c --]
[-- Type: text/plain, Size: 2911 bytes --]
// KASAN: null-ptr-deref Write in sctp_auth_shkey_hold, from close() on an SCTP socket whose association
// shared key could not be set up.
// A listener on 127.0.0.1:9999 enables AUTH and lists ABORT among the chunks that must be authenticated, so its
// INIT-ACK asks the client to authenticate ABORT. Each client connect() fails its Nth allocation (fail-nth,
// CONFIG_FAULT_INJECTION); when the failed one is the association key secret of SCTP_CMD_ASSOC_SHKEY, the
// association keeps peer.auth_capable with asoc->shkey == NULL, and close() with SO_LINGER {1, 0} builds an
// authenticated ABORT that takes a reference on the NULL key.
// It runs in a new user and network namespace, so it works as an unprivileged user too.
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <fcntl.h>
#include <net/if.h>
#include <netinet/in.h>
#include <sched.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <unistd.h>
#define SOL_SCTP 132
#define SCTP_AUTH_CHUNK 21
#define SCTP_AUTH_SUPPORTED 129
static void write_file(const char *path, const char *s)
{
int f = open(path, O_WRONLY);
if (f >= 0 && write(f, s, strlen(s)) < 0)
perror(path);
close(f);
}
static void enter_netns_with_lo(void)
{
struct ifreq ifr = { .ifr_name = "lo", .ifr_flags = IFF_UP };
char map[32];
int s;
snprintf(map, sizeof(map), "0 %d 1", getuid());
if (unshare(CLONE_NEWUSER | CLONE_NEWNET))
perror("unshare");
write_file("/proc/self/setgroups", "deny");
write_file("/proc/self/uid_map", map);
snprintf(map, sizeof(map), "0 %d 1", getgid());
write_file("/proc/self/gid_map", map);
s = socket(AF_INET, SOCK_DGRAM, 0);
ioctl(s, SIOCSIFFLAGS, &ifr);
close(s);
}
static int sctp_auth_socket(void)
{
struct { int32_t assoc_id; uint32_t value; } on = { 0, 1 };
int s = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP);
setsockopt(s, SOL_SCTP, SCTP_AUTH_SUPPORTED, &on, sizeof(on));
return s;
}
int main(void)
{
struct sockaddr_in sa = { .sin_family = AF_INET, .sin_port = htons(9999) };
struct linger abort_on_close = { 1, 0 };
uint8_t abort_chunk = 6; /* SCTP_CID_ABORT */
int lst, fail;
enter_netns_with_lo();
lst = sctp_auth_socket();
fail = open("/proc/self/fail-nth", O_WRONLY);
inet_pton(AF_INET, "127.0.0.1", &sa.sin_addr);
setsockopt(lst, SOL_SCTP, SCTP_AUTH_CHUNK, &abort_chunk, sizeof(abort_chunk));
if (bind(lst, (struct sockaddr *)&sa, sizeof(sa)) || listen(lst, 128) || fail < 0) {
perror("setup");
return 1;
}
for (int n = 1; n <= 60; n++) {
int c = sctp_auth_socket();
char nth[16];
fcntl(c, F_SETFL, O_NONBLOCK);
pwrite(fail, nth, snprintf(nth, sizeof(nth), "%d", n), 0);
connect(c, (struct sockaddr *)&sa, sizeof(sa));
usleep(20000);
pwrite(fail, "0", 1, 0);
setsockopt(c, SOL_SOCKET, SO_LINGER, &abort_on_close, sizeof(abort_on_close));
close(c);
usleep(5000);
}
printf("done\n");
return 0;
}
[-- Attachment #3: config.gz --]
[-- Type: application/gzip, Size: 38966 bytes --]
[-- Attachment #4: 0001-sctp-auth-don-t-authenticate-chunks-without-an-assoc.patch --]
[-- Type: text/plain, Size: 1705 bytes --]
>From 2e554096914c2c0823d4f2e396cdf9fcece2663e Mon Sep 17 00:00:00 2001
From: Kyuwon Cho <kyuwoncho18@gmail.com>
Date: Thu, 19 Nov 2026 11:36:52 +0900
Subject: [PATCH net] sctp: auth: don't authenticate chunks without an
association key
When the INIT-ACK is processed, SCTP_CMD_PEER_INIT marks the peer as
AUTH capable and SCTP_CMD_ASSOC_SHKEY then sets up the association key.
If sctp_auth_asoc_init_active_key() fails to allocate the secret, it
returns -ENOMEM before setting asoc->shkey, but the association stays,
with peer.auth_capable set. A chunk that the peer wants authenticated,
such as the ABORT built by close() with SO_LINGER {1, 0}, then 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)
Don't mark chunks for authentication while the association has no key.
Fixes: 1b1e0bc99474 ("sctp: add refcnt support for sh_key")
Signed-off-by: Kyuwon Cho <kyuwoncho18@gmail.com>
---
net/sctp/auth.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/sctp/auth.c b/net/sctp/auth.c
index cbeb8a87a17a..5f8e110929d4 100644
--- a/net/sctp/auth.c
+++ b/net/sctp/auth.c
@@ -660,7 +660,7 @@ int sctp_auth_send_cid(enum sctp_cid chunk, const struct sctp_association *asoc)
if (!asoc)
return 0;
- if (!asoc->peer.auth_capable)
+ if (!asoc->peer.auth_capable || !asoc->shkey)
return 0;
return __sctp_auth_cid(chunk, asoc->peer.peer_chunks);
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [BUG] sctp: auth: NULL asoc->shkey after a failed SCTP_CMD_ASSOC_SHKEY makes close() oops
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 ` [PATCH net v2] sctp: fail the association when the INIT-ACK cannot be processed Kyuwon Cho
2026-11-23 3:26 ` [BUG] sctp: auth: NULL asoc->shkey after a failed SCTP_CMD_ASSOC_SHKEY makes close() oops netdev-bot+sashiko
1 sibling, 1 reply; 4+ messages in thread
From: Xin Long @ 2026-11-19 20:01 UTC (permalink / raw)
To: Kyuwon Cho
Cc: Marcelo Ricardo Leitner, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Jun Yang, linux-sctp,
netdev, linux-kernel
On Wed, Nov 18, 2026 at 10:04 PM Kyuwon Cho <kyuwoncho18@gmail.com> wrote:
>
> Hi Marcelo, Xin,
>
> While testing v7.4-rc3 with an LLM-guided test generator that we are
> developing as a research prototype, we found that an SCTP association
> whose shared key could not be set up still builds authenticated chunks,
> with a NULL key. Closing such a socket with SO_LINGER {1, 0} then
> oopses in sctp_auth_shkey_hold(); here as an unprivileged user:
>
> BUG: KASAN: null-ptr-deref in sctp_auth_shkey_hold (include/linux/refcount.h:366 net/sctp/auth.c:113)
> Write of size 4 at addr 0000000000000018 by task test/115
> CPU: 1 UID: 65534 PID: 115 Comm: test Not tainted 7.4.0-rc3 #1 PREEMPT(lazy)
> Call Trace:
> <TASK>
> sctp_auth_shkey_hold (include/linux/refcount.h:366 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:1492 net/sctp/sm_make_chunk.c:953 net/sctp/sm_make_chunk.c:1016)
> sctp_close (net/sctp/socket.c:1564)
> inet_release (net/ipv4/af_inet.c:443)
> __sock_release (net/socket.c:735)
> sock_close (net/socket.c:1529)
> __fput (fs/file_table.c:512)
> fput_close_sync (fs/file_table.c:618)
> __x64_sys_close (fs/open.c:1574 fs/open.c:1597 fs/open.c:1584)
> do_syscall_64 (arch/x86/entry/syscall_64.c:61 arch/x86/entry/syscall_64.c:89)
> entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)
> </TASK>
>
> When the INIT-ACK arrives, sctp_sf_do_5_1C_ack() queues
> SCTP_CMD_PEER_INIT, which records that the peer supports AUTH and which
> chunks it wants authenticated, and then SCTP_CMD_ASSOC_SHKEY:
>
> case SCTP_CMD_ASSOC_SHKEY:
> error = sctp_auth_asoc_init_active_key(asoc,
> GFP_ATOMIC);
> break;
>
> sctp_auth_asoc_init_active_key() returns -ENOMEM before it sets
> asoc->shkey when the secret cannot be allocated:
>
> secret = sctp_auth_asoc_create_secret(asoc, ep_key, gfp);
> if (!secret)
> return -ENOMEM;
> ...
> asoc->shkey = ep_key;
>
> sctp_cmd_interpreter() then drops the remaining commands, but the
> association stays, with peer.auth_capable set and asoc->shkey NULL. If
The association should NOT stay with a broken state, but be deleted in such
cases. But it seems we can't do it in the loop of sctp_cmd_interpreter().
Can you please try fixing it by directly calling sctp_process_init() and
sctp_auth_asoc_init_active_key() in sctp_sf_do_5_1C_ack()? like:
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.
*/
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;
}
instead of using SCTP_CMD_PEER_INIT and SCTP_CMD_ASSOC_SHKEY.
Then you can delete SCTP_CMD_PEER_INIT and SCTP_CMD_ASSOC_SHKEY commands
from sctp code, as they're no longer used.
Also, please use git-send-email to send your patch, not send it as an
attachment.
Thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH net v2] sctp: fail the association when the INIT-ACK cannot be processed
2026-11-19 20:01 ` Xin Long
@ 2026-11-20 4:55 ` Kyuwon Cho
0 siblings, 0 replies; 4+ messages in thread
From: Kyuwon Cho @ 2026-11-20 4:55 UTC (permalink / raw)
To: Xin Long
Cc: Marcelo Ricardo Leitner, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Willem de Bruijn,
Jun Yang, linux-sctp, netdev, linux-kernel
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [BUG] sctp: auth: NULL asoc->shkey after a failed SCTP_CMD_ASSOC_SHKEY makes close() oops
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-23 3:26 ` netdev-bot+sashiko
1 sibling, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 3:26 UTC (permalink / raw)
To: kyuwoncho18
Cc: marcelo.leitner, lucien.xin, davem, edumazet, kuba, pabeni,
horms, junvyyang, linux-sctp, netdev, linux-kernel
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 1 (1) · Medium: 0 · Low: 3
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.
- [Low] The changelog leaves out the directly related prior fix
a80c9d945aef55 ("sctp: move SCTP_CMD_ASSOC_SHKEY right after…
- [Low] The recorded commit message is the raw bug-report email, not the
patch changelog.
- [Low] The comment above sctp_auth_send_cid() in net/sctp/auth.c still
says "Check if peer requested that this chunk is authenticated".
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the same
'authenticated chunk with a NULL key' crash can be reached through a…
--
sctp: auth: NULL asoc->shkey after a failed SCTP_CMD_ASSOC_SHKEY makes close() oops
This patch makes sctp_auth_send_cid() return 0 when asoc->shkey is NULL.
Chunks are then not marked for authentication after
sctp_auth_asoc_init_active_key() fails while the INIT-ACK is processed.
The target is the NULL dereference in sctp_auth_shkey_hold() reached
from sctp_close()->sctp_make_abort_user() with SO_LINGER {1, 0}.
> sctp: auth: NULL asoc->shkey after a failed SCTP_CMD_ASSOC_SHKEY makes close() oops
>
> --===============7735770531491749088==
> Content-Type: text/plain; charset="us-ascii"
> Content-Transfer-Encoding: 7bit
>
> Hi Marcelo, Xin,
[Severity: Low]
This isn't a bug, but the recorded commit message looks like the raw
bug report email rather than the patch changelog. The subject describes
the symptom, not the change.
The body contains the salutation, MIME boundary lines, Content-Type
headers, the full repro.c and a base64-encoded config.gz attachment.
The real subject ("sctp: auth: don't authenticate chunks without an
association key"), the changelog, and the Fixes: and Signed-off-by:
trailers only appear inside the embedded format-patch attachment.
Could this be resent as a proper patch that uses the attached changelog
as the commit message?
[ ... ]
> The reference on the shared key comes from 1b1e0bc99474 ("sctp: add
> refcnt support for sh_key"). ad1320865b18 ("sctp: hold shkey across
> socket migration") and 52ffeaa358d1 ("sctp: re-point retained control
> chunks on association migration"), both in v7.4-rc3, handle the
> migration paths and not this one.
[Severity: Low]
Should this also mention a80c9d945aef55 ("sctp: move
SCTP_CMD_ASSOC_SHKEY right after SCTP_CMD_PEER_INIT")? That commit
handled the same failure: SHKEY fails, shkey stays NULL, auth_capable is
set, and a chunk is sent with auth=1.
That commit also reordered the commands in sctp_sf_do_5_1C_ack() so
that this one runs before TIMER_STOP/TIMER_START/NEW_STATE:
sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_SHKEY, SCTP_NULL());
Because of that ordering, the failed association stays in COOKIE_WAIT.
There AUTH is discarded, and T1-init retransmits INIT, so key setup is
retried. This patch appears to depend on that behaviour.
Trees without a80c9d945aef55 leave the failed association in
COOKIE_ECHOED with T1-cookie running. Backporters who follow only
"Fixes: 1b1e0bc99474" get no warning about this. Would it be worth
stating the dependency here, instead of the two migration-path commits?
> diff --git a/net/sctp/auth.c b/net/sctp/auth.c
> index cbeb8a87a17a7..5f8e110929d46 100644
> --- a/net/sctp/auth.c
> +++ b/net/sctp/auth.c
> @@ -660,7 +660,7 @@ int sctp_auth_send_cid(enum sctp_cid chunk, const struct sctp_association *asoc)
> if (!asoc)
> return 0;
>
> - if (!asoc->peer.auth_capable)
> + if (!asoc->peer.auth_capable || !asoc->shkey)
> return 0;
[Severity: High]
Is this check enough to cover the keyless state? After
SCTP_CMD_ASSOC_SHKEY fails in sctp_sf_do_5_1C_ack(), SCTP_CMD_PEER_INIT
has already set peer.auth_capable, peer_chunks, peer_hmacs and
c.peer_vtag. Both asoc->shkey and asoc->asoc_shared_key are still NULL.
This change only affects the transmit side.
During an INIT collision, the COOKIE_WAIT association can receive the
peer's COOKIE-ECHO. sctp_sf_do_5_2_4_dupcook() then gets action 'D' from
sctp_tietags_compare(), because PEER_INIT already set a non-zero
peer_vtag:
if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
(asoc->c.peer_vtag == new_asoc->c.peer_vtag))
return 'D';
If an AUTH chunk comes before the COOKIE-ECHO, sctp_sf_do_dupcook_d()
verifies it against the existing keyless association:
if (!sctp_auth_chunk_verify(net, chunk, asoc))
return SCTP_DISPOSITION_DISCARD;
The call chain
sctp_auth_chunk_verify()->sctp_sf_authenticate()->sctp_auth_calculate_hmac()
then uses the NULL key:
if (key_id == asoc->active_key_id)
asoc_key = asoc->asoc_shared_key;
...
hmac_sha1_usingrawkey(asoc_key->data, asoc_key->len,
Without that AUTH chunk, dupcook_d moves the association to ESTABLISHED
and never calls sctp_auth_asoc_init_active_key(), unlike dupcook_a and
dupcook_b. sctp_sf_eat_auth() checks only peer.auth_capable before it
calls sctp_sf_authenticate(). Any later AUTH chunk from the remote peer
then hits the same NULL asoc_shared_key dereference in the receive path.
The patch also changes behaviour in a way the changelog doesn't mention.
sctp_auth_send_cid() now returns 0 in this state. So DATA, ABORT and any
other chunk the peer listed in its CHUNKS parameter are sent without
AUTH. The peer silently drops them in sctp_assoc_bh_rcv():
if (sctp_auth_recv_cid(subtype.chunk, asoc) && !chunk->auth)
continue;
The association then looks established but delivers nothing.
Would it be better to stop a keyless auth-capable association from
leaving COOKIE_WAIT or processing AUTH? For example, dupcook_d could
initialise the key or fail, or AUTH could be rejected while
asoc_shared_key is NULL. That would replace the approach in
sctp_auth_send_cid() rather than add to it.
>
> return __sctp_auth_cid(chunk, asoc->peer.peer_chunks);
[Severity: Low]
The comment above sctp_auth_send_cid() still says:
/* Check if peer requested that this chunk is authenticated */
After this change, the function also returns 0 when the local
association key is not set up, even if the peer listed the chunk.
Callers rely on the documented meaning. sctp_datamsg_from_user() says
"If the peer requested that we authenticate DATA chunks", and
_sctp_make_chunk() says "Determine if the chunk needs to be
authenticated".
Should the comment be updated to mention the local key check?
[Severity: High]
This isn't a bug introduced by this patch, but the same crash (an
authenticated chunk with a NULL key) looks reachable through stream
interleaving. The new !asoc->shkey check does not cover that path.
sctp_datamsg_from_user() picks the per-chunk key by asking about DATA:
if (sctp_auth_send_cid(SCTP_CID_DATA, asoc)) {
...
shkey = asoc->shkey;
With interleaving, the chunk is built by
sctp_make_idatafrag_empty()->sctp_make_idata()->_sctp_make_chunk(asoc,
SCTP_CID_I_DATA, ...). That function sets the auth flag by asking about
I-DATA:
if (sctp_auth_send_cid(type, asoc))
retval->auth = 1;
If the peer lists I-DATA (0x40) but not DATA in its CHUNKS parameter,
every I-DATA chunk gets auth=1 with shkey=NULL. asoc->shkey itself is
valid in this case, so the new check does not apply. On transmit,
sctp_packet_append_chunk()->sctp_packet_bundle_auth() then dereferences
NULL:
auth = sctp_make_auth(asoc, chunk->shkey->key_id);
In the reverse case (DATA listed, I-DATA not), shkey is set and auth is
0. No AUTH chunk is ever bundled, so sctp_packet_will_fit() returns
SCTP_XMIT_PMTU_FULL every time, even for an empty packet:
if ((packet->auth && chunk->shkey != packet->auth->shkey) ||
(!packet->auth && chunk->shkey &&
chunk->chunk_hdr->type != SCTP_CID_AUTH))
return SCTP_XMIT_PMTU_FULL;
The I-DATA chunk is then never sent.
No fault injection is needed. The local side has to enable AUTH and
interleaving (SCTP_FRAGMENT_INTERLEAVE and SCTP_INTERLEAVING_SUPPORTED,
plus the net.sctp.intl_enable sysctl, which is off by default). The
first sendmsg() then triggers the NULL dereference.
Should the key selection in sctp_datamsg_from_user() use the same chunk
type as the chunk that make_datafrag builds?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179505710266.3511678.14017674052424733262%40gmail.com
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-23 3:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH net v2] sctp: fail the association when the INIT-ACK cannot be processed Kyuwon Cho
2026-11-23 3:26 ` [BUG] sctp: auth: NULL asoc->shkey after a failed SCTP_CMD_ASSOC_SHKEY makes close() oops 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
all inboxes | Powered by JetHome®