* [PATCH net-next] sctp: copy endpoint settings to accepted and peeled-off sockets
@ 2026-11-23 1:23 Xin Long
2026-11-24 2:04 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: Xin Long @ 2026-11-23 1:23 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.
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
include/net/sctp/auth.h | 2 ++
net/sctp/auth.c | 47 +++++++++++++++++++++++++++++++++++++++++
net/sctp/socket.c | 17 +++++++++++++++
3 files changed, 66 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..e075297b9ead 100644
--- a/net/sctp/auth.c
+++ b/net/sctp/auth.c
@@ -1056,3 +1056,50 @@ 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);
+ 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-next] sctp: copy endpoint settings to accepted and peeled-off sockets
2026-11-23 1:23 [PATCH net-next] sctp: copy endpoint settings to accepted and peeled-off sockets Xin Long
@ 2026-11-24 2:04 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-11-24 2:04 UTC (permalink / raw)
To: lucien.xin
Cc: netdev, linux-sctp, davem, kuba, edumazet, pabeni, horms,
marcelo.leitner
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 2
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] In sctp_auth_ep_copy() (net/sctp/auth.c), the per-key copy is
incomplete: the source key's `deactivated` flag is not copied.
- [Low] The commit message says the change only affects restart
negotiation and lists PR-SCTP, ECN, RECONF, ASCONF, I-DATA and AUTH.
- [Low] The commit fixes a wire-visible bug: an association restart on an
accepted or peeled-off socket negotiates capabilities (PR-SCTP, ECN,…
--
sctp: copy endpoint settings to accepted and peeled-off sockets
This patch makes sctp_sock_migrate() copy the feature flags and AUTH
configuration from the listening socket's endpoint to the new endpoint.
Association restarts on accepted and peeled-off sockets then negotiate the
same capabilities as the listener. It adds sctp_auth_ep_copy(), which
deep-copies the HMAC list, the chunk list and the shared keys.
> As gomaja noticed, when accept() or SCTP_SOCKOPT_PEELOFF creates a new
> socket, sctp_endpoint_new() initialises the new endpoint from the network
[ ... ]
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
[Severity: Low]
This fixes a restart negotiation problem that is visible on the wire.
There is no Fixes: tag to tell stable tooling which commit introduced it.
Could one be added?
The reporter is credited in prose ("As gomaja noticed"), but there is no
Reported-by: or Closes: trailer. Should one be included?
> diff --git a/net/sctp/auth.c b/net/sctp/auth.c
> index cbeb8a87a17a7..e075297b9ead1 100644
> --- a/net/sctp/auth.c
> +++ b/net/sctp/auth.c
> @@ -1056,3 +1056,50 @@ 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;
> +
[ ... ]
> + 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);
> + list_add_tail(&new_key->key_list, &dst->endpoint_shared_keys);
> + }
[Severity: Medium]
Should sh_key->deactivated be copied into new_key here too?
sctp_auth_shkey_create() returns a zeroed container. Only key_id, refcnt
and key_list are set, and this loop never reads sh_key->deactivated.
For endpoint keys, sctp_auth_deact_key_id() leaves the key on
ep->endpoint_shared_keys and only marks it:
net/sctp/auth.c:sctp_auth_deact_key_id() {
...
key->deactivated = 1;
...
}
After accept() or peeloff, a key that was deactivated on the listening
socket therefore looks active again on the new endpoint. This check in
sctp_auth_set_active_key() no longer fires for it:
if (!found || key->deactivated)
return -EINVAL;
An endpoint-level SCTP_AUTH_ACTIVE_KEY for a retired key id returns
-EINVAL on the listener but succeeds on the new socket. That lets
newep->active_key_id point at the retired key. Associations created later
on the new endpoint, for example on restart, would then inherit it.
Would something like this be needed?
new_key->deactivated = sh_key->deactivated;
sctp_auth_asoc_copy_shkeys() also drops this flag when it copies keys
into associations. That part is existing behaviour, not something this
patch adds.
[ ... ]
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index bc68af88e2710..bfd87be8ed54c 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;
[Severity: Low]
The commit message only covers restart negotiation of PR-SCTP, ECN,
RECONF, ASCONF, I-DATA and AUTH. It doesn't mention these last three
copies.
sndbuf_policy and rcvbuf_policy are not negotiated. sctp_endpoint_init()
sets them only from net->sctp.sndbuf_policy and net->sctp.rcvbuf_policy.
Once sctp_assoc_migrate() sets asoc->ep = newep, the live association
reads them in these functions:
sctp_wspace()
sctp_wake_up_waiters()
sctp_assoc_rwnd_decrease()
sctp_ulpevent_make_rcvmsg()
inet_sctp_diag_fill()
If the sysctls changed between creating the listener and accept() or
peeloff, this changes which buffer accounting model the migrated
association uses.
strreset_enable is also copied without mention. New associations inherit
it, and getsockopt(SCTP_ENABLE_STREAM_RESET) reports it.
Could the commit message describe these copies as well?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/48580ca6a02b588e9c24444801109506da11a9d2.1795396989.git.lucien.xin%40gmail.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-24 2:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 1:23 [PATCH net-next] sctp: copy endpoint settings to accepted and peeled-off sockets Xin Long
2026-11-24 2:04 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox