Thread View: linux.kernel.netdev
1 messages
1 total messages
Started by Xin Long
Wed, 25 Nov 2026 15:45
[PATCH net v2] sctp: copy endpoint settings to accepted and peeled-off sockets
Author: Xin Long
Date: Wed, 25 Nov 2026 15:45
Date: Wed, 25 Nov 2026 15:45
135 lines
15316 bytes
15316 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads