Skip to contentSkip to conversation

sctp: re-point retained control chunks on association migration

PATCH Applied Jun Yang 3 participants 5 messages Oct 9 – Oct 16

Subsystems (3)
lore
Share & tools
lore

Jun Yang

author
#0 lore raw

v4 cover sctp: re-point retained control chunks on association migration

This series fixes ownership of retained SCTP control chunks during socket migration. Patch 1 carries David Lee's shared-key prerequisite.

Changes since v3 [1], following Xin Long's review:
- Add David Lee's and the forwarding submitter's sign-offs to patch 1.
- Restore sctp_process_tx_chunk() to skip duplicate visits.
- Preserve a control chunk's existing shared key across migration.

[1] https://lore.kernel.org/netdev/[email protected]/

David Lee (1):
sctp: hold shkey across socket migration

Jun Yang (1):
sctp: re-point retained control chunks on association migration

 include/net/sctp/sm.h    |  1 +
 net/sctp/sm_make_chunk.c |  5 +++--
 net/sctp/socket.c        | 57 +++++++++++++++++++++++++++++++++++++++---------
 3 files changed, 51 insertions(+), 12 deletions(-)

base-commit: a7bfaba4823e3c165bb2004c74eff7c096672bc7

author
#1 lore raw

PATCH v4 1/2 sctp: hold shkey across socket migration

From: David Lee <[email protected]>

sctp_sock_migrate() transfers queued DATA skbs from the old socket to the new one. skb_orphan() invokes sctp_wfree() during that transfer and drops the skb-owned shared-key reference.

If userspace has removed that key from the association, this can be the final reference. The following sctp_set_owner_w() then dereferences the freed chunk->shkey while trying to take the new owner reference.

Take a temporary shared-key reference before orphaning the skb and release it after the new owner has taken its reference. This preserves the selected authentication key throughout the ownership transfer.

Bug found and triaged by OpenAI Security Research and validated by Trail of Bits.

Fixes 1b1e0bc99474 ("sctp: add refcnt support for sh_key")
Assisted-by Codex:gpt-5.6-sol gpt-5.5-cyber

---
v4:
- Add David Lee's and the forwarding submitter's sign-offs.

Original submission:
https://lore.kernel.org/netdev/[email protected]/

 net/sctp/socket.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
net/sctp/socket.c +11 -1
index c7b9e325ec1c..4a08023d52aa 100644
@@ -147,9 +147,19 @@ static inline void sctp_set_owner_w(struct sctp_chunk *chunk)
 
 static void sctp_clear_owner_w(struct sctp_chunk *chunk)
 {
+	/* Keep the shkey alive until the new owner takes its reference. */
+	if (chunk->shkey)
+		sctp_auth_shkey_hold(chunk->shkey);
 	skb_orphan(chunk->skb);
 }
 
+static void sctp_set_owner_w_migrate(struct sctp_chunk *chunk)
+{
+	sctp_set_owner_w(chunk);
+	if (chunk->shkey)
+		sctp_auth_shkey_release(chunk->shkey);
+}
+
 #define traverse_and_process()	\
 do {				\
 	msg = chunk->msg;	\
@@ -9632,7 +9642,7 @@ static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
 	lock_sock_nested(newsk, SINGLE_DEPTH_NESTING);
 	sctp_for_each_tx_datachunk(assoc, true, sctp_clear_owner_w);
 	sctp_assoc_migrate(assoc, newsk);
-	sctp_for_each_tx_datachunk(assoc, false, sctp_set_owner_w);
+	sctp_for_each_tx_datachunk(assoc, false, sctp_set_owner_w_migrate);
 
 	/* If the association on the newsk is already closed before accept()
 	 * is called, set RCV_SHUTDOWN flag.
author
#2 lore raw

PATCH v4 2/2 sctp: re-point retained control chunks on association migration

In reply to Jun Yang

From: Jun Yang <[email protected]>

sctp_sock_migrate() transfers DATA chunk ownership but leaves retained control chunks pointing at the old socket. A later retransmission can therefore access the socket after it has been freed.

Extend the migration walk to cover retained control chunks and use sctp_control_set_owner_w() to assign their new owner. Reuse the DATA ownership check so each chunk is processed once per pass, even when it is reachable through multiple lists or retained pointers.

Preserve a control chunk's existing authentication key across migration so its final release can still generate SCTP_AUTH_FREE_KEY when needed.

Fixes d04adf1b3551 ("sctp: reset owner sk for data chunks on out queues when migrating a sock")
Assisted-by tencentos-corvus-ai:hy4-preview

---
A KASAN reproducer for this issue is available if requested.

v4:
- Restore sctp_process_tx_chunk() to skip duplicate visits.
- Preserve the control chunk's existing shared key.

v3: https://lore.kernel.org/netdev/[email protected]/
v2: https://lore.kernel.org/netdev/[email protected]/
v1: https://lore.kernel.org/netdev/[email protected]/

 include/net/sctp/sm.h    |  1 +
 net/sctp/sm_make_chunk.c |  5 ++--
 net/sctp/socket.c        | 53 ++++++++++++++++++++++++++++++----------
 3 files changed, 44 insertions(+), 15 deletions(-)
include/net/sctp/sm.h +1 -0
index 3bfd261a53cc..76605d1ee839 100644
@@ -252,6 +252,7 @@ struct sctp_chunk *sctp_make_fwdtsn(const struct sctp_association *asoc,
 				    struct sctp_fwdtsn_skip *skiplist);
 struct sctp_chunk *sctp_make_auth(const struct sctp_association *asoc,
 				  __u16 key_id);
+void sctp_control_set_owner_w(struct sctp_chunk *chunk);
 struct sctp_chunk *sctp_make_strreset_req(const struct sctp_association *asoc,
 					  __u16 stream_num, __be16 *stream_list,
 					  bool out, bool in);
net/sctp/sm_make_chunk.c +3 -2
index 84a4c97d0f75..ddc31a5dbad3 100644
@@ -94,7 +94,7 @@ static void sctp_control_release_owner(struct sk_buff *skb)
 	}
 }
 
-static void sctp_control_set_owner_w(struct sctp_chunk *chunk)
+void sctp_control_set_owner_w(struct sctp_chunk *chunk)
 {
 	struct sctp_association *asoc = chunk->asoc;
 	struct sk_buff *skb = chunk->skb;
@@ -107,7 +107,8 @@ static void sctp_control_set_owner_w(struct sctp_chunk *chunk)
 	 *  For now don't do anything for now.
 	 */
 	if (chunk->auth) {
-		chunk->shkey = asoc->shkey;
+		if (!chunk->shkey)
+			chunk->shkey = asoc->shkey;
 		sctp_auth_shkey_hold(chunk->shkey);
 	}
 	skb->sk = asoc ? asoc->base.sk : NULL;
net/sctp/socket.c +40 -13

81 lines not on this page · raw message

maintainer Acked-by on v4 2/2
#3 lore raw
Quoted 12 lines · Jun Yang

From: Jun Yang <[email protected]>

sctp_sock_migrate() transfers DATA chunk ownership but leaves retained control chunks pointing at the old socket. A later retransmission can therefore access the socket after it has been freed.

Extend the migration walk to cover retained control chunks and use sctp_control_set_owner_w() to assign their new owner. Reuse the DATA ownership check so each chunk is processed once per pass, even when it is reachable through multiple lists or retained pointers.

Quoted 8 lines

Preserve a control chunk's existing authentication key across migration so its final release can still generate SCTP_AUTH_FREE_KEY when needed.

Fixes d04adf1b3551 ("sctp: reset owner sk for data chunks on out queues when migrating a sock")
Assisted-by tencentos-corvus-ai:hy4-preview

Thanks.

#4 lore raw
In reply to Jun Yang
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Fri, 9 Oct 2026 15:42:30 +0800 you wrote:

This series fixes ownership of retained SCTP control chunks during socket migration. Patch 1 carries David Lee's shared-key prerequisite.

Changes since v3 [1], following Xin Long's review:
- Add David Lee's and the forwarding submitter's sign-offs to patch 1.
- Restore sctp_process_tx_chunk() to skip duplicate visits.
- Preserve a control chunk's existing shared key across migration.

[...]

Here is the summary with links:
- [net,v4,1/2] sctp: hold shkey across socket migration

    https://git.kernel.org/netdev/net/c/ad1320865b18
  - [net,v4,2/2] sctp: re-point retained control chunks on association migration
    https://git.kernel.org/netdev/net/c/52ffeaa358d1

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html