Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2] sctp: copy endpoint settings to accepted and peeled-off sockets
@ 2026-11-25 15:45 Xin Long
  0 siblings, 0 replies; 2+ messages in thread
From: Xin Long @ 2026-11-25 15:45 UTC (permalink / raw)
  To: network dev, linux-sctp
  Cc: davem, kuba, Eric Dumazet, Paolo Abeni, Simon Horman,
	Marcelo Ricardo Leitner

As gomaja noticed, when accept() or SCTP_SOCKOPT_PEELOFF creates a new
socket, sctp_endpoint_new() initialises the new endpoint from the network
namespace sysctls and from the compiled-in AUTH defaults rather than from
the listening socket's endpoint. If an association restart (RFC 9260
section 5.2.2) arrives on the accepted or peeled-off socket, the restart
INIT ACK is built from the new endpoint, so it negotiates capabilities
based on the namespace sysctls instead of what the listening socket
configured:

 - Feature flags (PR-SCTP, ECN, RECONF, ASCONF, I-DATA) in the restart INIT
   ACK follow the namespace sysctls rather than what the listening socket
   set via SCTP_*_SUPPORTED socket options.

 - AUTH HMAC and chunk lists revert to the kernel defaults (SHA-1 only,
   empty chunk list) instead of what SCTP_HMAC_IDENT and SCTP_AUTH_CHUNK
   set on the listening socket.

Copy the feature flags and AUTH configuration from the old endpoint to the
new one in sctp_sock_migrate(). Add sctp_auth_ep_copy() to deep-copy the
HMAC list, chunk list, and shared keys from one endpoint to another. This
ensures that association restarts on accepted and peeled-off sockets
negotiate the same capabilities as the original handshake.

Fixes: b14878ccb7fa ("net: sctp: cache auth_enable per endpoint")
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
v2:
  - Add a Fixes tag and target net.git.
  - Copy sh_key->deactivated to new_key->deactivated in sctp_auth_ep_copy()
    (reported by Clashiko).
---
 include/net/sctp/auth.h |  2 ++
 net/sctp/auth.c         | 48 +++++++++++++++++++++++++++++++++++++++++
 net/sctp/socket.c       | 17 +++++++++++++++
 3 files changed, 67 insertions(+)

diff --git a/include/net/sctp/auth.h b/include/net/sctp/auth.h
index 85efa65d3912..2ef52507bf11 100644
--- a/include/net/sctp/auth.h
+++ b/include/net/sctp/auth.h
@@ -106,5 +106,7 @@ int sctp_auth_deact_key_id(struct sctp_endpoint *ep,
 			   struct sctp_association *asoc, __u16 key_id);
 int sctp_auth_init(struct sctp_endpoint *ep, gfp_t gfp);
 void sctp_auth_free(struct sctp_endpoint *ep);
+int sctp_auth_ep_copy(struct sctp_endpoint *dst,
+		      const struct sctp_endpoint *src, gfp_t gfp);
 
 #endif
diff --git a/net/sctp/auth.c b/net/sctp/auth.c
index cbeb8a87a17a..3f97e2689e5a 100644
--- a/net/sctp/auth.c
+++ b/net/sctp/auth.c
@@ -1056,3 +1056,51 @@ void sctp_auth_free(struct sctp_endpoint *ep)
 	ep->auth_hmacs_list = NULL;
 	ep->auth_chunk_list = NULL;
 }
+
+int sctp_auth_ep_copy(struct sctp_endpoint *dst,
+		      const struct sctp_endpoint *src, gfp_t gfp)
+{
+	struct sctp_shared_key *sh_key, *new_key;
+
+	sctp_auth_free(dst);
+	sctp_auth_destroy_keys(&dst->endpoint_shared_keys);
+
+	dst->auth_enable = src->auth_enable;
+	dst->active_key_id = src->active_key_id;
+
+	if (src->auth_hmacs_list) {
+		dst->auth_hmacs_list = kzalloc_flex(*dst->auth_hmacs_list,
+						    hmac_ids,
+						    SCTP_AUTH_NUM_HMACS, gfp);
+		if (!dst->auth_hmacs_list)
+			goto nomem;
+		memcpy(dst->auth_hmacs_list, src->auth_hmacs_list,
+		       ntohs(src->auth_hmacs_list->param_hdr.length));
+	}
+
+	if (src->auth_chunk_list) {
+		dst->auth_chunk_list = kzalloc(sizeof(*dst->auth_chunk_list) +
+					       SCTP_NUM_CHUNK_TYPES, gfp);
+		if (!dst->auth_chunk_list)
+			goto nomem;
+		memcpy(dst->auth_chunk_list, src->auth_chunk_list,
+		       ntohs(src->auth_chunk_list->param_hdr.length));
+	}
+
+	key_for_each(sh_key, &src->endpoint_shared_keys) {
+		new_key = sctp_auth_shkey_create(sh_key->key_id, gfp);
+		if (!new_key)
+			goto nomem;
+		new_key->key = sh_key->key;
+		sctp_auth_key_hold(new_key->key);
+		new_key->deactivated = sh_key->deactivated;
+		list_add_tail(&new_key->key_list, &dst->endpoint_shared_keys);
+	}
+
+	return 0;
+
+nomem:
+	sctp_auth_free(dst);
+	sctp_auth_destroy_keys(&dst->endpoint_shared_keys);
+	return -ENOMEM;
+}
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index bc68af88e271..bfd87be8ed54 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -9623,6 +9623,23 @@ static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
 	if (err)
 		return err;
 
+	/* Copy the endpoint's feature flags and AUTH settings from the original
+	 * endpoint so that restarts on the accepted or peeled-off socket
+	 * negotiate the same capabilities.
+	 */
+	newep->prsctp_enable = oldsp->ep->prsctp_enable;
+	newep->ecn_enable = oldsp->ep->ecn_enable;
+	newep->reconf_enable = oldsp->ep->reconf_enable;
+	newep->asconf_enable = oldsp->ep->asconf_enable;
+	newep->intl_enable = oldsp->ep->intl_enable;
+	newep->strreset_enable = oldsp->ep->strreset_enable;
+	newep->sndbuf_policy = oldsp->ep->sndbuf_policy;
+	newep->rcvbuf_policy = oldsp->ep->rcvbuf_policy;
+
+	err = sctp_auth_ep_copy(newep, oldsp->ep, GFP_KERNEL);
+	if (err)
+		return err;
+
 	sctp_auto_asconf_init(newsp);
 
 	/* Move any messages in the old socket's receive queue that are for the
-- 
2.47.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net v2] sctp: copy endpoint settings to accepted and peeled-off sockets
@ 2026-11-25 15:47 netdev-bot+sinfo
  0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sinfo @ 2026-11-25 15:47 UTC (permalink / raw)
  To: Xin Long
  Cc: network dev, linux-sctp, davem, kuba, Eric Dumazet, Paolo Abeni,
	Simon Horman, Marcelo Ricardo Leitner

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-25 15:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 15:47 [PATCH net v2] sctp: copy endpoint settings to accepted and peeled-off sockets netdev-bot+sinfo
  -- strict thread matches above, loose matches on Subject: below --
2026-11-25 15:45 Xin Long

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox