Re: [BUG] sctp: auth: NULL asoc->shkey after a failed SCTP_CMD_ASSOC_SHKEY makes close() oops
From: netdev-bot+sashiko
Date: Sun Nov 22 2026 - 22:26:49 EST
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