sctp: stop processing a packet once its association is deleted
Subsystems (3)
PATCH 1/1 sctp: stop processing a packet once its association is deleted
sctp_endpoint_bh_rcv() looks the association up only when chunk->asoc is NULL, and caches the result in chunk->asoc and chunk->transport without taking a reference.
A packet that matches no association is handed to the endpoint, so a peer can bundle COOKIE ECHO, SHUTDOWN and SHUTDOWN ACK in one packet. The COOKIE ECHO creates the association, the SHUTDOWN chunk caches it, and with the outqueue empty the SHUTDOWN ACK reaches sctp_sf_do_9_2_final(), so the association and its transports are freed.
The endpoint loop has no counterpart to the asoc->base.dead check in sctp_assoc_bh_rcv(). The next chunk writes to last_time_heard in the freed transport and is then passed to sctp_do_sm() with the freed association. The transport is freed through RCU, so this needs the packet to come off the socket backlog, where the loop runs in task context.
The endpoint loop cannot do the same check: it holds no reference on the association, so reading asoc->base.dead would itself be a use-after-free. Mark the packet for discard in the command interpreter, just before it deletes the association. That is also before sctp_inq_free() releases the chunk on the association receive path.
sctp_sf_do_5_2_4_dupcook() issues SCTP_CMD_DELETE_TCB for the temporary association, while the one the packet belongs to stays alive. A restarting peer can bundle DATA behind its COOKIE ECHO, so compare against chunk->asoc and leave that case alone.
--- net/sctp/sm_sideeffect.c | 4 ++++ 1 file changed, 4 insertions(+)
net/sctp/sm_sideeffect.c +4 -0
@@ -1332,6 +1332,10 @@ static int sctp_cmd_interpreter(enum sctp_event_type event_type,sctp_outq_uncork (&asoc->outqueue, gfp); local_cork =0 ; } +/* No chunk left in this packet may use this asoc. */ +if (event_type ==SCTP_EVENT_T_CHUNK && + chunk->asoc == asoc) + chunk->pdiscard =1 ;/* Delete the current association. */ sctp_cmd_delete_tcb (commands, asoc); asoc =NULL ;
Signature · 1 line
2.43.0
Quoted 51 lines · Hyunwoo Kim
sctp_endpoint_bh_rcv()looks the association up only whenchunk->asocis NULL, and caches the result inchunk->asocandchunk->transportwithout taking a reference.A packet that matches no association is handed to the endpoint, so a peer can bundle COOKIE ECHO, SHUTDOWN and SHUTDOWN ACK in one packet. The COOKIE ECHO creates the association, the SHUTDOWN chunk caches it, and with the outqueue empty the SHUTDOWN ACK reaches
sctp_sf_do_9_2_final(), so the association and its transports are freed.The endpoint loop has no counterpart to the
asoc->base.deadcheck insctp_assoc_bh_rcv(). The next chunk writes tolast_time_heardin the freed transport and is then passed tosctp_do_sm()with the freed association. The transport is freed through RCU, so this needs the packet to come off the socket backlog, where the loop runs in task context.The endpoint loop cannot do the same check: it holds no reference on the association, so reading
asoc->base.deadwould itself be a use-after-free. Mark the packet for discard in the command interpreter, just before it deletes the association. That is also beforesctp_inq_free()releases the chunk on the association receive path.
sctp_sf_do_5_2_4_dupcook()issuesSCTP_CMD_DELETE_TCBfor the temporary association, while the one the packet belongs to stays alive. A restarting peer can bundle DATA behind its COOKIE ECHO, so compare againstchunk->asocand leave that case alone.Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")Signed-off-by Hyunwoo Kim <[email protected]>--- net/sctp/sm_sideeffect.c | 4 ++++ 1 file changed, 4 insertions(+)net/sctp/sm_sideeffect.c +4
-1@@ -1332,6 +1332,10 @@ static int sctp_cmd_interpreter(enum sctp_event_type event_type,sctp_outq_uncork (&asoc->outqueue, gfp); local_cork =0 ; } +/* No chunk left in this packet may use this asoc. */ +if (event_type ==SCTP_EVENT_T_CHUNK && + chunk->asoc == asoc) + chunk->pdiscard =1 ;/* Delete the current association. */ sctp_cmd_delete_tcb (commands, asoc); asoc =NULL ; --
Quoted 2 lines
2.43.0
Note: I don't think the pre-existing issue reported in sashiko-gemini [1] can be reproduced, as the SCTP GSO packet can never bundle a chunk after SHUTDOWN_ACK.
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 11 lines · On Sat, 15 Aug 2026 07:36:18 +0900 you wrote:
sctp_endpoint_bh_rcv()looks the association up only whenchunk->asocis NULL, and caches the result inchunk->asocandchunk->transportwithout taking a reference.A packet that matches no association is handed to the endpoint, so a peer can bundle COOKIE ECHO, SHUTDOWN and SHUTDOWN ACK in one packet. The COOKIE ECHO creates the association, the SHUTDOWN chunk caches it, and with the outqueue empty the SHUTDOWN ACK reaches
sctp_sf_do_9_2_final(), so the association and its transports are freed.[...]
Here is the summary with links:
- [net] sctp: stop processing a packet once its association is deleted
https://git.kernel.org/netdev/net/c/47e15a8d12e3
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html