sctp: bound the auth_chunks copy length in SCTP_LOCAL_AUTH_CHUNKS
Subsystems (3)
PATCH 1/1 sctp: bound the auth_chunks copy length in SCTP_LOCAL_AUTH_CHUNKS
From: Jun Yang <[email protected]>
sctp_getsockopt_local_auth_chunks() copies ntohs(length) - sizeof(paramhdr) bytes out of ch->chunks without bounding the count. For an association ch is the fixed-size asoc->c.auth_chunks[] array (sizeof(struct sctp_paramhdr) + SCTP_AUTH_MAX_CHUNKS bytes), whose length field is restored from the received state cookie by sctp_unpack_cookie() and is not validated against the array size. A cookie carrying an oversized length makes copy_to_user() read past the array (out-of-bounds read).
Bound the chunk count to SCTP_AUTH_MAX_CHUNKS before the copy. That is the most valid chunk bytes either source can hold, so legitimate output is unchanged, and it also covers a stored length smaller than the parameter header, which would otherwise underflow.
--- net/sctp/socket.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/sctp/socket.c +6 -0
@@ -7109,6 +7109,12 @@ static int sctp_getsockopt_local_auth_chunks(struct sock *sk, int len, goto num; num_chunks =ntohs (ch->param_hdr.length) -sizeof (struct sctp_paramhdr ); +/* asoc->c.auth_chunks[] holds at most SCTP_AUTH_MAX_CHUNKS bytes but its +* length is restored from the state cookie and is not bounded here; +* clamp so an oversized length cannot read past the array. +*/ +if (num_chunks >SCTP_AUTH_MAX_CHUNKS ) + num_chunks =SCTP_AUTH_MAX_CHUNKS ;if (len <sizeof (struct sctp_authchunks ) + num_chunks)return -EINVAL ;
Signature · 1 line
2.55.0
Xin Long
maintainerQuoted 43 lines · Jun Yang
From: Jun Yang <[email protected]>
sctp_getsockopt_local_auth_chunks()copies ntohs(length) - sizeof(paramhdr) bytes out ofch->chunkswithout bounding the count. For an association ch is the fixed-size asoc->c.auth_chunks[] array (sizeof(struct sctp_paramhdr)+SCTP_AUTH_MAX_CHUNKSbytes), whose length field is restored from the received state cookie bysctp_unpack_cookie()and is not validated against the array size. A cookie carrying an oversized length makescopy_to_user()read past the array (out-of-bounds read).Bound the chunk count to
SCTP_AUTH_MAX_CHUNKSbefore the copy. That is the most valid chunk bytes either source can hold, so legitimate output is unchanged, and it also covers a stored length smaller than the parameter header, which would otherwise underflow.Fixes 65b07e5d0d09 ("[SCTP]: API updates to suport SCTP-AUTH extensions.")Reported-by TencentOS Corvus AI <[email protected]>Signed-off-by Jun Yang <[email protected]>--- net/sctp/socket.c | 6 ++++++ 1 file changed, 6 insertions(+)net/sctp/socket.c +6
-1@@ -7109,6 +7109,12 @@ static int sctp_getsockopt_local_auth_chunks(struct sock *sk, int len, goto num; num_chunks =ntohs (ch->param_hdr.length) -sizeof (struct sctp_paramhdr ); +/* asoc->c.auth_chunks[] holds at most SCTP_AUTH_MAX_CHUNKS bytes but its +* length is restored from the state cookie and is not bounded here; +* clamp so an oversized length cannot read past the array. +*/ +if (num_chunks >SCTP_AUTH_MAX_CHUNKS ) + num_chunks =SCTP_AUTH_MAX_CHUNKS ;if (len <sizeof (struct sctp_authchunks ) + num_chunks)return -EINVAL ; --
Quoted 2 lines
2.55.0
The issue requires sysctl net.sctp.cookie_hmac_alg=none, right?
If so, Jean Jeremy has reported two issues caused by the missing validation of the auth params in the cookie. We may need to validate all auth_random, auth_hmacs and auth_chunks in sctp_unpack_cookie().
Let's wait a bit and see if he proceeds with the fix I've suggested.
Thanks.
Dear all,
Attached is a proposed fix that relies on a code suggestion from Xin Long, but reworked to better handle all cases. Does this look ok?
I verified experimentally on 8ba098e6b6ff that this fix solves the two bugs I reported.
Regards,
Jérémy
-----Message d'origine-----
De : Xin Long <[email protected]>
Envoyé : vendredi 31 juillet 2026 17:27
À : Jun Yang <[email protected]>; JEAN Jeremy <[email protected]>
Cc : [email protected]; Jun Yang <[email protected]>; [email protected]; TencentOS Corvus AI <[email protected]>; Marcelo Ricardo Leitner <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Simon Horman <[email protected]>; Vlad Yasevich <[email protected]>; [email protected]; [email protected] Objet : Re: [PATCH net] sctp: bound the auth_chunks copy length in SCTP_LOCAL_AUTH_CHUNKS
Quoted 45 lines · Jun Yang
From: Jun Yang <[email protected]>
sctp_getsockopt_local_auth_chunks()copies ntohs(length) - sizeof(paramhdr) bytes out ofch->chunkswithout bounding the count. For an association ch is the fixed-size asoc->c.auth_chunks[] array (sizeof(struct sctp_paramhdr)+SCTP_AUTH_MAX_CHUNKSbytes), whose length field is restored from the received state cookie bysctp_unpack_cookie()and is not validated against the array size. A cookie carrying an oversized length makescopy_to_user()read past the array (out-of-bounds read).Bound the chunk count to
SCTP_AUTH_MAX_CHUNKSbefore the copy. That is the most valid chunk bytes either source can hold, so legitimate output is unchanged, and it also covers a stored length smaller than the parameter header, which would otherwise underflow.Fixes 65b07e5d0d09 ("[SCTP]: API updates to suport SCTP-AUTHextensions.")
Reported-by TencentOS Corvus AI <[email protected]>Signed-off-by Jun Yang <[email protected]>--- net/sctp/socket.c | 6 ++++++ 1 file changed, 6 insertions(+)net/sctp/socket.c index renamed from net/sctp/socket.c +0
-0
9a6da4e0d741..3e9dacb772a0100644net/sctp/socket.c +6
-1@@ -7109,6 +7109,12 @@ static int sctp_getsockopt_local_auth_chunks(struct sock *sk, int len, goto num; num_chunks =ntohs (ch->param_hdr.length) -sizeof (struct sctp_paramhdr ); +/* asoc->c.auth_chunks[] holds at most SCTP_AUTH_MAX_CHUNKS bytes but its +* length is restored from the state cookie and is not bounded here; +* clamp so an oversized length cannot read past the array. +*/ +if (num_chunks >SCTP_AUTH_MAX_CHUNKS ) + num_chunks =SCTP_AUTH_MAX_CHUNKS ;if (len <sizeof (struct sctp_authchunks ) + num_chunks)return -EINVAL ; --
Quoted 2 lines
2.55.0
The issue requires sysctl net.sctp.cookie_hmac_alg=none, right?
If so, Jean Jeremy has reported two issues caused by the missing validation of the auth params in the cookie. We may need to validate all auth_random, auth_hmacs and auth_chunks in sctp_unpack_cookie().
Let's wait a bit and see if he proceeds with the fix I've suggested.
Thanks.
Les données à caractère personnel recueillies et traitées dans le cadre de cet échange, le sont à seule fin d’exécution d’une relation professionnelle et s’opèrent dans cette seule finalité et pour la durée nécessaire à cette relation. Si vous souhaitez faire usage de vos droits de consultation, de rectification et de suppression de vos données, veuillez contacter [email protected]. Si vous avez reçu ce message par erreur, nous vous remercions d’en informer l’expéditeur et de détruire le message. The personal data collected and processed during this exchange aims solely at completing a business relationship and is limited to the necessary duration of that relationship. If you wish to use your rights of consultation, rectification and deletion of your data, please contact: [email protected]. If you have received this message in error, we thank you for informing the sender and destroying the message.
From 835c40c3aa0b1959b1fa27ed41385487987a0098 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Jean?= <[email protected]>
Date: Sun, 26 Jul 2026 23:03:04 +0000
Subject: [PATCH] sctp: validate cookie AUTH state before use
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
When cookie authentication is disabled, COOKIE_ECHO restores fixed-size AUTH fields directly from peer-controlled cookie bytes. A forged RANDOM length, HMAC list, or CHUNKS list can then reach association consumers with lengths or identifiers that were never validated against the local backing arrays.
Validate the cookie's RANDOM, HMACS, and CHUNKS parameters at the cookie trust boundary before copying them into the association. Reject invalid types, malformed lengths, unsupported HMAC identifiers, HMAC lists without SHA1, and forbidden chunk ids. Keep the downstream HMAC lookup path range-safe as a second line of defense.
--- include/net/sctp/auth.h | 3 ++ net/sctp/auth.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ net/sctp/sm_make_chunk.c | 3 ++ net/sctp/sm_statefuns.c | 3 ++ 4 files changed, 97 insertions(+)
include/net/sctp/auth.h +3 -0
@@ -22,6 +22,7 @@ struct sctp_endpoint;struct sctp_association ;struct sctp_authkey ;struct sctp_hmacalgo ; +struct sctp_cookie ;/* Defines an HMAC algorithm supported by SCTP chunk authentication */ struct sctp_hmac {
@@ -72,6 +73,8 @@ struct sctp_shared_key *sctp_auth_get_shkey(int sctp_auth_asoc_copy_shkeys (const struct sctp_endpoint *ep,struct sctp_association *asoc,gfp_t gfp); +bool sctp_auth_verify_cookie_params (const struct sctp_endpoint *ep, +const struct sctp_cookie *cookie);const struct sctp_hmac *sctp_auth_get_hmac (__u16 hmac_id);const struct sctp_hmac *sctp_auth_asoc_get_hmac (const struct sctp_association *asoc);
net/sctp/auth.c +88 -0
112 lines not on this page · raw message
net/sctp/sm_make_chunk.c +3 -0
@@ -1852,6 +1852,9 @@ struct sctp_association *sctp_unpack_cookie(/* Set up our peer's port number. */ retval->peer.port =ntohs (chunk->sctp_hdr->source); +if (!sctp_auth_verify_cookie_params (ep, bear_cookie)) + goto malformed; +/* Populate the association from the cookie. */ memcpy (&retval->c, bear_cookie,sizeof (*bear_cookie));
net/sctp/sm_statefuns.c +3 -0
@@ -4436,6 +4436,9 @@ static enum sctp_ierror sctp_sf_authenticate( sig_len =ntohs (chunk->chunk_hdr->length) -sizeof (struct sctp_auth_chunk ); hmac =sctp_auth_get_hmac (ntohs (auth_hdr->hmac_id)); +if (!hmac) +return SCTP_IERROR_AUTH_BAD_HMAC ; +if (sig_len != hmac->hmac_len)return SCTP_IERROR_PROTO_VIOLATION ;
Signature · 1 line
2.47.3
Xin Long
maintainerQuoted 7 lines · JEAN Jeremy
Dear all,
Attached is a proposed fix that relies on a code suggestion from Xin Long, but reworked to better handle all cases. Does this look ok?
I verified experimentally on8ba098e6b6ffthat this fix solves the two bugs I reported.
Hi, JEAN,
I think the fix only needs to add sctp_auth_verify_cookie_params() and call it from sctp_unpack_cookie(). Since the reported issues are caused by tampering with the cookie auth parameters, I don't think the other changes in net/sctp/auth.c and net/sctp/sm_statefuns.c are necessary. Could you please confirm?
Also, you may consider renaming it to sctp_auth_chunk_id_forbidden(), so it can be reused later to replace the existing open-coded checks in sctp_setsockopt_auth_chunk() and __sctp_auth_cid() in a separate patch.
Nit: In sctp_auth_verify_cookie_params(), too many lines for these u16 variable, please merge them into 1 or 2 lines, like:
u16 hmacs_len, chunks_len;
u16 n_hmacs, n_chunks, i;
bool has_sha1 = false;
With all the above comments addressed, please send the next patch to:
# ./scripts/get_ get_dvb_firmware get_maintainer.pl [root@wsfd-netdev64 net-next]# ./scripts/get_maintainer.pl net/sctp/auth.c Marcelo Ricardo Leitner <[email protected]> (maintainer:SCTP PROTOCOL) Xin Long <[email protected]> (maintainer:SCTP PROTOCOL) "David S. Miller" <[email protected]> (maintainer:NETWORKING [GENERAL]) Eric Dumazet <[email protected]> (maintainer:NETWORKING [GENERAL]) Jakub Kicinski <[email protected]> (maintainer:NETWORKING [GENERAL]) Paolo Abeni <[email protected]> (maintainer:NETWORKING [GENERAL]) Simon Horman <[email protected]> (reviewer:NETWORKING [GENERAL]) [email protected] (open list:SCTP PROTOCOL) [email protected] (open list:NETWORKING [GENERAL]) [email protected] (open list)
Thanks.
Quoted 66 lines
Regards,
Jérémy-----Message d'origine-----
De : Xin Long <[email protected]>
Envoyé : vendredi 31 juillet 2026 17:27
À : Jun Yang <[email protected]>; JEAN Jeremy <[email protected]>
Cc : [email protected]; Jun Yang <[email protected]>; [email protected]; TencentOS Corvus AI <[email protected]>; Marcelo Ricardo Leitner <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Simon Horman <[email protected]>; Vlad Yasevich <[email protected]>; [email protected]; [email protected] Objet : Re: [PATCH net] sctp: bound theauth_chunkscopy length inSCTP_LOCAL_AUTH_CHUNKSQuoted 45 lines · Jun Yang
From: Jun Yang <[email protected]>
sctp_getsockopt_local_auth_chunks()copies ntohs(length) - sizeof(paramhdr) bytes out ofch->chunkswithout bounding the count. For an association ch is the fixed-size asoc->c.auth_chunks[] array (sizeof(struct sctp_paramhdr)+SCTP_AUTH_MAX_CHUNKSbytes), whose length field is restored from the received state cookie bysctp_unpack_cookie()and is not validated against the array size. A cookie carrying an oversized length makescopy_to_user()read past the array (out-of-bounds read).Bound the chunk count to
SCTP_AUTH_MAX_CHUNKSbefore the copy. That is the most valid chunk bytes either source can hold, so legitimate output is unchanged, and it also covers a stored length smaller than the parameter header, which would otherwise underflow.Fixes 65b07e5d0d09 ("[SCTP]: API updates to suport SCTP-AUTHextensions.")
Reported-by TencentOS Corvus AI <[email protected]>Signed-off-by Jun Yang <[email protected]>--- net/sctp/socket.c | 6 ++++++ 1 file changed, 6 insertions(+)net/sctp/socket.c index renamed from net/sctp/socket.c +0
-0
9a6da4e0d741..3e9dacb772a0100644net/sctp/socket.c +6
-1@@ -7109,6 +7109,12 @@ static int sctp_getsockopt_local_auth_chunks(struct sock *sk, int len, goto num; num_chunks =ntohs (ch->param_hdr.length) -sizeof (struct sctp_paramhdr ); +/* asoc->c.auth_chunks[] holds at most SCTP_AUTH_MAX_CHUNKS bytes but its +* length is restored from the state cookie and is not bounded here; +* clamp so an oversized length cannot read past the array. +*/ +if (num_chunks >SCTP_AUTH_MAX_CHUNKS ) + num_chunks =SCTP_AUTH_MAX_CHUNKS ;if (len <sizeof (struct sctp_authchunks ) + num_chunks)return -EINVAL ; --Quoted 2 lines
2.55.0
The issue requires sysctl net.sctp.cookie_hmac_alg=none, right?
If so, Jean Jeremy has reported two issues caused by the missing validation of the auth params in the cookie. We may need to validate all
auth_random,auth_hmacsandauth_chunksinsctp_unpack_cookie().Let's wait a bit and see if he proceeds with the fix I've suggested.
Thanks.
Les données à caractère personnel recueillies et traitées dans le cadre de cet échange, le sont à seule fin d’exécution d’une relation professionnelle et s’opèrent dans cette seule finalité et pour la durée nécessaire à cette relation. Si vous souhaitez faire usage de vos droits de consultation, de rectification et de suppression de vos données, veuillez contacter [email protected]. Si vous avez reçu ce message par erreur, nous vous remercions d’en informer l’expéditeur et de détruire le message. The personal data collected and processed during this exchange aims solely at completing a business relationship and is limited to the necessary duration of that relationship. If you wish to use your rights of consultation, rectification and deletion of your data, please contact: [email protected]. If you have received this message in error, we thank you for informing the sender and destroying the message.
Thanks for your valuable feedbacks.
I updated the patch, and sent it to the list.
https://lore.kernel.org/netdev/[email protected]/
Regards,
Jérémy
-----Message d'origine-----
De : Xin Long <[email protected]>
Envoyé : mardi 4 août 2026 16:56
À : JEAN Jeremy <[email protected]>
Cc : Jun Yang <[email protected]>; [email protected]; Jun Yang <[email protected]>; [email protected]; TencentOS Corvus AI <[email protected]>; Marcelo Ricardo Leitner <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Simon Horman <[email protected]>; Vlad Yasevich <[email protected]>; [email protected]; [email protected] Objet : Re: [PATCH net] sctp: bound the auth_chunks copy length in SCTP_LOCAL_AUTH_CHUNKS
Quoted 7 lines · JEAN Jeremy
Dear all,
Attached is a proposed fix that relies on a code suggestion from Xin Long, but reworked to better handle all cases. Does this look ok?
I verified experimentally on8ba098e6b6ffthat this fix solves the two bugs I reported.
Hi, JEAN,
I think the fix only needs to add sctp_auth_verify_cookie_params() and call it from sctp_unpack_cookie(). Since the reported issues are caused by tampering with the cookie auth parameters, I don't think the other changes in net/sctp/auth.c and net/sctp/sm_statefuns.c are necessary. Could you please confirm?
Also, you may consider renaming it to sctp_auth_chunk_id_forbidden(), so it can be reused later to replace the existing open-coded checks in sctp_setsockopt_auth_chunk() and __sctp_auth_cid() in a separate patch.
Nit: In sctp_auth_verify_cookie_params(), too many lines for these u16 variable, please merge them into 1 or 2 lines, like:
u16 hmacs_len, chunks_len;
u16 n_hmacs, n_chunks, i;
bool has_sha1 = false;
With all the above comments addressed, please send the next patch to:
# ./scripts/get_ get_dvb_firmware get_maintainer.pl [root@wsfd-netdev64 net-next]# ./scripts/get_maintainer.pl net/sctp/auth.c Marcelo Ricardo Leitner <[email protected]> (maintainer:SCTP PROTOCOL) Xin Long <[email protected]> (maintainer:SCTP PROTOCOL) "David S. Miller" <[email protected]> (maintainer:NETWORKING [GENERAL]) Eric Dumazet <[email protected]> (maintainer:NETWORKING [GENERAL]) Jakub Kicinski <[email protected]> (maintainer:NETWORKING [GENERAL]) Paolo Abeni <[email protected]> (maintainer:NETWORKING [GENERAL]) Simon Horman <[email protected]> (reviewer:NETWORKING [GENERAL]) [email protected] (open list:SCTP PROTOCOL) [email protected] (open list:NETWORKING [GENERAL]) [email protected] (open list)
Thanks.
Quoted 67 lines
Regards,
Jérémy-----Message d'origine-----
De : Xin Long <[email protected]>
Envoyé : vendredi 31 juillet 2026 17:27 À : Jun Yang <[email protected]>; JEAN Jeremy <[email protected]> Cc :
[email protected]; Jun Yang <[email protected]>; [email protected]; TencentOS Corvus AI <[email protected]>; Marcelo Ricardo Leitner <[email protected]>; David S. Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Simon Horman <[email protected]>; Vlad Yasevich <[email protected]>; [email protected]; [email protected] Objet : Re:
[PATCH net] sctp: bound theauth_chunkscopy length inSCTP_LOCAL_AUTH_CHUNKSQuoted 45 lines · Jun Yang
From: Jun Yang <[email protected]>
sctp_getsockopt_local_auth_chunks()copies ntohs(length) - sizeof(paramhdr) bytes out ofch->chunkswithout bounding the count. For an association ch is the fixed-size asoc->c.auth_chunks[] array (sizeof(struct sctp_paramhdr)+SCTP_AUTH_MAX_CHUNKSbytes), whose length field is restored from the received state cookie bysctp_unpack_cookie()and is not validated against the array size. A cookie carrying an oversized length makescopy_to_user()read past the array (out-of-bounds read).Bound the chunk count to
SCTP_AUTH_MAX_CHUNKSbefore the copy. That is the most valid chunk bytes either source can hold, so legitimate output is unchanged, and it also covers a stored length smaller than the parameter header, which would otherwise underflow.Fixes 65b07e5d0d09 ("[SCTP]: API updates to suport SCTP-AUTHextensions.")
Reported-by TencentOS Corvus AI <[email protected]>Signed-off-by Jun Yang <[email protected]>--- net/sctp/socket.c | 6 ++++++ 1 file changed, 6 insertions(+)net/sctp/socket.c index renamed from net/sctp/socket.c +0
-0
9a6da4e0d741..3e9dacb772a0100644net/sctp/socket.c +6
-1@@ -7109,6 +7109,12 @@ static int sctp_getsockopt_local_auth_chunks(struct sock *sk, int len, goto num; num_chunks =ntohs (ch->param_hdr.length) -sizeof (struct sctp_paramhdr ); +/* asoc->c.auth_chunks[] holds at most SCTP_AUTH_MAX_CHUNKS bytes but its +* length is restored from the state cookie and is not bounded here; +* clamp so an oversized length cannot read past the array. +*/ +if (num_chunks >SCTP_AUTH_MAX_CHUNKS ) + num_chunks =SCTP_AUTH_MAX_CHUNKS ;if (len <sizeof (struct sctp_authchunks ) + num_chunks)return -EINVAL ; --Quoted 2 lines
2.55.0
The issue requires sysctl net.sctp.cookie_hmac_alg=none, right?
Quoted 6 lines
If so, Jean Jeremy has reported two issues caused by the missing validation of the auth params in the cookie. We may need to validate all
auth_random,auth_hmacsandauth_chunksinsctp_unpack_cookie().Let's wait a bit and see if he proceeds with the fix I've suggested.
Thanks.
Les données à caractère personnel recueillies et traitées dans le cadre de cet échange, le sont à seule fin d’exécution d’une relation professionnelle et s’opèrent dans cette seule finalité et pour la durée nécessaire à cette relation. Si vous souhaitez faire usage de vos droits de consultation, de rectification et de suppression de vos données, veuillez contacter [email protected]. Si vous avez reçu ce message par erreur, nous vous remercions d’en informer l’expéditeur et de détruire le message. The personal data collected and processed during this exchange aims solely at completing a business relationship and is limited to the necessary duration of that relationship. If you wish to use your rights of consultation, rectification and deletion of your data, please contact: [email protected]. If you have received this message in error, we thank you for informing the sender and destroying the message.
Les données à caractère personnel recueillies et traitées dans le cadre de cet échange, le sont à seule fin d’exécution d’une relation professionnelle et s’opèrent dans cette seule finalité et pour la durée nécessaire à cette relation. Si vous souhaitez faire usage de vos droits de consultation, de rectification et de suppression de vos données, veuillez contacter [email protected]. Si vous avez reçu ce message par erreur, nous vous remercions d’en informer l’expéditeur et de détruire le message. The personal data collected and processed during this exchange aims solely at completing a business relationship and is limited to the necessary duration of that relationship. If you wish to use your rights of consultation, rectification and deletion of your data, please contact: [email protected]. If you have received this message in error, we thank you for informing the sender and destroying the message.