]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
sctp: fix use-after-free of cached ASCONF chunk
authorYuxiang Yang <yangyx22@mails.tsinghua.edu.cn>
Sun, 9 Aug 2026 04:38:06 +0000 (12:38 +0800)
committerJakub Kicinski <kuba@kernel.org>
Thu, 13 Aug 2026 00:54:42 +0000 (17:54 -0700)
addip_last_asconf caches the outstanding outbound ASCONF chunk. The normal
ASCONF-ACK completion path releases the chunk and clears the pointer.

However, sctp_asconf_queue_teardown() releases the cached chunk without
clearing addip_last_asconf. During peer restart handling,
sctp_sf_do_dupcook_a() queues SCTP_CMD_PURGE_ASCONF_QUEUE, which invokes
sctp_asconf_queue_teardown() while the association remains alive and leaves
the pointer dangling.

A delayed authenticated ASCONF-ACK can then reach sctp_sf_do_asconf_ack(),
which accesses the stale chunk and passes it to sctp_process_asconf_ack(),
causing a use-after-free and a second release.

Clearing the pointer exposes a race with T4 expiry. Peer restart handling
queues the timer stop before the purge, but SCTP_CMD_TIMER_STOP uses
timer_delete(), which does not wait for a callback already running on
another CPU. Such a callback can reach sctp_sf_t4_timer_expire() after
the purge and dereference NULL.

Clear addip_last_asconf after releasing the cached chunk, and make
sctp_sf_t4_timer_expire() consume a stale T4 expiry if no outstanding
ASCONF remains.

Fixes: a000c01e60e4 ("sctp: stop pending timers and purge queues when peer restart asoc")
Cc: stable@vger.kernel.org
Suggested-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: Yuxiang Yang <yangyx22@mails.tsinghua.edu.cn>
Acked-by: Xin Long <lucien.xin@gmail.com>
Link: https://patch.msgid.link/20260809043806.2768302-1-yangyx22@mails.tsinghua.edu.cn
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/sctp/associola.c
net/sctp/sm_statefuns.c

index c65c83638ccebeeeda4cafa660c5f6a09ab61688..5be0bed2685ee5a9763b428a320d8924f6095d82 100644 (file)
@@ -1716,6 +1716,8 @@ void sctp_asconf_queue_teardown(struct sctp_association *asoc)
        sctp_assoc_free_asconf_queue(asoc);
 
        /* Free any cached ASCONF chunk. */
-       if (asoc->addip_last_asconf)
+       if (asoc->addip_last_asconf) {
                sctp_chunk_free(asoc->addip_last_asconf);
+               asoc->addip_last_asconf = NULL;
+       }
 }
index 708fa07d5fffc7e716d342a72981ec1d16594bea..3a8e16b29660cf86b131e1f0c95ffdd4fead1bb8 100644 (file)
@@ -6145,8 +6145,12 @@ enum sctp_disposition sctp_sf_t4_timer_expire(
                                        struct sctp_cmd_seq *commands)
 {
        struct sctp_chunk *chunk = asoc->addip_last_asconf;
-       struct sctp_transport *transport = chunk->transport;
+       struct sctp_transport *transport;
+
+       if (!chunk)
+               return SCTP_DISPOSITION_CONSUME;
 
+       transport = chunk->transport;
        SCTP_INC_STATS(net, SCTP_MIB_T4_RTO_EXPIREDS);
 
        /* ADDIP 4.1 B1) Increment the error counters and perform path failure