* [PATCH 5.15.y 0/3] sctp: validate the cached INIT in COOKIE_ECHO
@ 2026-11-27 3:45 ` Dickson Wu
0 siblings, 0 replies; 9+ messages in thread
From: Dickson Wu via B4 Relay @ 2026-11-27 3:45 UTC (permalink / raw)
To: stable; +Cc: Xin Long, Marcelo Ricardo Leitner, linux-sctp, netdev
6.1.y and newer already have these three fixes. 5.15.y keeps the
cached INIT in peer_init[] and tests sctp_sk()->hmac instead of
cookie_auth_enable. In the duplicate cookie path the security hook
still runs before the switch, so the A/B INIT check sits just ahead of
it and the tie-tag compare moves up a few lines.
Tested on v5.15.226:
- x86_64 allmodconfig W=1 builds of net/sctp/bind_addr.o,
net/sctp/sm_make_chunk.o and net/sctp/sm_statefuns.o, base vs
patched, no new warnings
- pahole on the base object to check the cookie layout
- booted the patched kernel under QEMU/KVM with SCTP built in. I
didn't run a malformed COOKIE_ECHO test.
The backports and the test runs were prepared with AI coding tools
(OpenAI Codex agents, with review by Claude). I went over the result
before signing off.
---
Xin Long (3):
sctp: validate cached peer INIT chunk length in COOKIE_ECHO processing
sctp: validate embedded INIT chunk and address list lengths in cookie
sctp: add INIT verification after cookie unpacking
net/sctp/bind_addr.c | 11 ++++++++++-
net/sctp/sm_make_chunk.c | 17 +++++++++++++++--
net/sctp/sm_statefuns.c | 46 +++++++++++++++++++++++++++++++++++++---------
3 files changed, 62 insertions(+), 12 deletions(-)
---
base-commit: 4f2df9a01754521fbba3493e8ad91ef65515e68c
change-id: 20261127-so4-sctp-515-d31cc8e35fd3
Best regards,
--
Dickson Wu <dickson.wu@certik.com>
^ permalink raw reply [flat|nested] 9+ messages in thread* [PATCH 5.15.y 0/3] sctp: validate the cached INIT in COOKIE_ECHO @ 2026-11-27 3:45 ` Dickson Wu 0 siblings, 0 replies; 9+ messages in thread From: Dickson Wu @ 2026-11-27 3:45 UTC (permalink / raw) To: stable; +Cc: Xin Long, Marcelo Ricardo Leitner, linux-sctp, netdev 6.1.y and newer already have these three fixes. 5.15.y keeps the cached INIT in peer_init[] and tests sctp_sk()->hmac instead of cookie_auth_enable. In the duplicate cookie path the security hook still runs before the switch, so the A/B INIT check sits just ahead of it and the tie-tag compare moves up a few lines. Tested on v5.15.226: - x86_64 allmodconfig W=1 builds of net/sctp/bind_addr.o, net/sctp/sm_make_chunk.o and net/sctp/sm_statefuns.o, base vs patched, no new warnings - pahole on the base object to check the cookie layout - booted the patched kernel under QEMU/KVM with SCTP built in. I didn't run a malformed COOKIE_ECHO test. The backports and the test runs were prepared with AI coding tools (OpenAI Codex agents, with review by Claude). I went over the result before signing off. --- Xin Long (3): sctp: validate cached peer INIT chunk length in COOKIE_ECHO processing sctp: validate embedded INIT chunk and address list lengths in cookie sctp: add INIT verification after cookie unpacking net/sctp/bind_addr.c | 11 ++++++++++- net/sctp/sm_make_chunk.c | 17 +++++++++++++++-- net/sctp/sm_statefuns.c | 46 +++++++++++++++++++++++++++++++++++++--------- 3 files changed, 62 insertions(+), 12 deletions(-) --- base-commit: 4f2df9a01754521fbba3493e8ad91ef65515e68c change-id: 20261127-so4-sctp-515-d31cc8e35fd3 Best regards, -- Dickson Wu <dickson.wu@certik.com> ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 5.15.y 1/3] sctp: validate cached peer INIT chunk length in COOKIE_ECHO processing 2026-11-27 3:45 ` Dickson Wu @ 2026-11-27 3:45 ` Dickson Wu -1 siblings, 0 replies; 9+ messages in thread From: Dickson Wu via B4 Relay @ 2026-11-27 3:45 UTC (permalink / raw) To: stable; +Cc: Xin Long, Marcelo Ricardo Leitner, linux-sctp, netdev From: Xin Long <lucien.xin@gmail.com> commit 0861615c28de668669d748ef4eb913ea9262d13b upstream. When a listening SCTP server processes a COOKIE_ECHO chunk, the cached peer INIT chunk embedded after the cookie is parsed and its parameters are later walked by sctp_process_init() using sctp_walk_params(). However, the chunk header length of this cached INIT chunk was not validated against the remaining buffer in the COOKIE_ECHO payload. If the length field is inflated, the parameter walk can run beyond the actual received data, leading to out-of-bounds reads and potential memory corruption during later parameter handling (e.g. STATE_COOKIE processing and kmemdup() copies). Add a bounds check in sctp_unpack_cookie() to ensure the cached INIT chunk length does not exceed the available data in the COOKIE_ECHO buffer before it is used. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: Brian Geffon <bgeffon@google.com> Signed-off-by: Xin Long <lucien.xin@gmail.com> Link: https://patch.msgid.link/eb60825fa22d6f9e663c7d4dbb69f397b5d34d42.1780362366.git.lucien.xin@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> [ adapted to 5.15.y: read the cached INIT from peer_init[] ] Signed-off-by: Dickson Wu <dickson.wu@certik.com> --- The backport and the test runs were prepared with AI coding tools (OpenAI Codex agents, with review by Claude). I went over the result before signing off. net/sctp/sm_make_chunk.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c index c15d62ad24754..b599dd2c15bd4 100644 --- a/net/sctp/sm_make_chunk.c +++ b/net/sctp/sm_make_chunk.c @@ -1757,6 +1757,7 @@ struct sctp_association *sctp_unpack_cookie( struct sctp_signed_cookie *cookie; struct sk_buff *skb = chunk->skb; struct sctp_cookie *bear_cookie; + struct sctp_chunkhdr *ch; __u8 *digest = ep->digest; enum sctp_scope scope; unsigned int len; @@ -1787,6 +1788,10 @@ struct sctp_association *sctp_unpack_cookie( cookie = chunk->subh.cookie_hdr; bear_cookie = &cookie->c; + ch = (struct sctp_chunkhdr *)&bear_cookie->peer_init[0]; + if (ntohs(ch->length) > len - fixed_size) + goto malformed; + if (!sctp_sk(ep->base.sk)->hmac) goto no_hmac; -- 2.43.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5.15.y 1/3] sctp: validate cached peer INIT chunk length in COOKIE_ECHO processing @ 2026-11-27 3:45 ` Dickson Wu 0 siblings, 0 replies; 9+ messages in thread From: Dickson Wu @ 2026-11-27 3:45 UTC (permalink / raw) To: stable; +Cc: Xin Long, Marcelo Ricardo Leitner, linux-sctp, netdev From: Xin Long <lucien.xin@gmail.com> commit 0861615c28de668669d748ef4eb913ea9262d13b upstream. When a listening SCTP server processes a COOKIE_ECHO chunk, the cached peer INIT chunk embedded after the cookie is parsed and its parameters are later walked by sctp_process_init() using sctp_walk_params(). However, the chunk header length of this cached INIT chunk was not validated against the remaining buffer in the COOKIE_ECHO payload. If the length field is inflated, the parameter walk can run beyond the actual received data, leading to out-of-bounds reads and potential memory corruption during later parameter handling (e.g. STATE_COOKIE processing and kmemdup() copies). Add a bounds check in sctp_unpack_cookie() to ensure the cached INIT chunk length does not exceed the available data in the COOKIE_ECHO buffer before it is used. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: Brian Geffon <bgeffon@google.com> Signed-off-by: Xin Long <lucien.xin@gmail.com> Link: https://patch.msgid.link/eb60825fa22d6f9e663c7d4dbb69f397b5d34d42.1780362366.git.lucien.xin@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> [ adapted to 5.15.y: read the cached INIT from peer_init[] ] Signed-off-by: Dickson Wu <dickson.wu@certik.com> --- The backport and the test runs were prepared with AI coding tools (OpenAI Codex agents, with review by Claude). I went over the result before signing off. net/sctp/sm_make_chunk.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c index c15d62ad24754..b599dd2c15bd4 100644 --- a/net/sctp/sm_make_chunk.c +++ b/net/sctp/sm_make_chunk.c @@ -1757,6 +1757,7 @@ struct sctp_association *sctp_unpack_cookie( struct sctp_signed_cookie *cookie; struct sk_buff *skb = chunk->skb; struct sctp_cookie *bear_cookie; + struct sctp_chunkhdr *ch; __u8 *digest = ep->digest; enum sctp_scope scope; unsigned int len; @@ -1787,6 +1788,10 @@ struct sctp_association *sctp_unpack_cookie( cookie = chunk->subh.cookie_hdr; bear_cookie = &cookie->c; + ch = (struct sctp_chunkhdr *)&bear_cookie->peer_init[0]; + if (ntohs(ch->length) > len - fixed_size) + goto malformed; + if (!sctp_sk(ep->base.sk)->hmac) goto no_hmac; -- 2.43.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5.15.y 2/3] sctp: validate embedded INIT chunk and address list lengths in cookie 2026-11-27 3:45 ` Dickson Wu @ 2026-11-27 3:45 ` Dickson Wu -1 siblings, 0 replies; 9+ messages in thread From: Dickson Wu via B4 Relay @ 2026-11-27 3:45 UTC (permalink / raw) To: stable; +Cc: Xin Long, Marcelo Ricardo Leitner, linux-sctp, netdev From: Xin Long <lucien.xin@gmail.com> commit 6f4c80a2a7e6d06753b89a578b710a2499a5e62b upstream. sctp_unpack_cookie() only checked that the embedded INIT chunk length did not exceed the remaining cookie payload, but did not ensure that the INIT chunk is large enough to contain a complete INIT header. A malformed COOKIE_ECHO can therefore carry a truncated INIT chunk whose length field is smaller than sizeof(struct sctp_init_chunk). Later, sctp_process_init() accesses INIT parameters unconditionally, which may lead to out-of-bounds reads. In addition, raw_addr_list_len is not fully validated against the remaining cookie payload. When cookie authentication is disabled, an attacker can supply an oversized raw_addr_list_len and cause sctp_raw_to_bind_addrs() to read beyond the end of the cookie. The address parser also lacks sufficient bounds checks for parameter headers and lengths, allowing malformed address parameters to trigger out-of-bounds reads. Fix this by: - requiring the embedded INIT chunk length to be at least sizeof(struct sctp_init_chunk); - validating that the INIT chunk and raw address list together fit within the cookie payload; - verifying sufficient data exists for each address parameter header and payload before parsing it. Note that sctp_verify_init() must be called after sctp_unpack_cookie() and before sctp_process_init() when cookie authentication is disabled. This will be addressed in a separate patch. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: Sashiko <sashiko-bot@kernel.org> Signed-off-by: Xin Long <lucien.xin@gmail.com> Link: https://patch.msgid.link/75af23a89adf881a0895d511775e4770da367cbf.1780873427.git.lucien.xin@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> [ adapted to 5.15.y: extend the existing bounds check ] Signed-off-by: Dickson Wu <dickson.wu@certik.com> --- The backport and the test runs were prepared with AI coding tools (OpenAI Codex agents, with review by Claude). I went over the result before signing off. net/sctp/bind_addr.c | 11 ++++++++++- net/sctp/sm_make_chunk.c | 9 +++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/net/sctp/bind_addr.c b/net/sctp/bind_addr.c index 6b95d3ba8fe1c..0947b276d1e08 100644 --- a/net/sctp/bind_addr.c +++ b/net/sctp/bind_addr.c @@ -275,6 +275,16 @@ int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw_addr_list, param = (struct sctp_paramhdr *)raw_addr_list; rawaddr = (union sctp_addr_param *)raw_addr_list; + if (addrs_len < sizeof(*param)) { + retval = -EINVAL; + goto out_err; + } + len = ntohs(param->length); + if (addrs_len < len) { + retval = -EINVAL; + goto out_err; + } + af = sctp_get_af_specific(param_type2af(param->type)); if (unlikely(!af) || !af->from_addr_param(&addr, rawaddr, htons(port), 0)) { @@ -291,7 +301,6 @@ int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw_addr_list, goto out_err; next: - len = ntohs(param->length); addrs_len -= len; raw_addr_list += len; } diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c index b599dd2c15bd4..79d2c2b179c35 100644 --- a/net/sctp/sm_make_chunk.c +++ b/net/sctp/sm_make_chunk.c @@ -1759,8 +1759,8 @@ struct sctp_association *sctp_unpack_cookie( struct sctp_cookie *bear_cookie; struct sctp_chunkhdr *ch; __u8 *digest = ep->digest; + unsigned int len, chlen; enum sctp_scope scope; - unsigned int len; ktime_t kt; /* Header size is static data prior to the actual cookie, including @@ -1789,7 +1789,12 @@ struct sctp_association *sctp_unpack_cookie( bear_cookie = &cookie->c; ch = (struct sctp_chunkhdr *)&bear_cookie->peer_init[0]; - if (ntohs(ch->length) > len - fixed_size) + chlen = ntohs(ch->length); + if (chlen < sizeof(struct sctp_init_chunk)) + goto malformed; + if (chlen > len - fixed_size) + goto malformed; + if (bear_cookie->raw_addr_list_len > len - fixed_size - chlen) goto malformed; if (!sctp_sk(ep->base.sk)->hmac) -- 2.43.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5.15.y 2/3] sctp: validate embedded INIT chunk and address list lengths in cookie @ 2026-11-27 3:45 ` Dickson Wu 0 siblings, 0 replies; 9+ messages in thread From: Dickson Wu @ 2026-11-27 3:45 UTC (permalink / raw) To: stable; +Cc: Xin Long, Marcelo Ricardo Leitner, linux-sctp, netdev From: Xin Long <lucien.xin@gmail.com> commit 6f4c80a2a7e6d06753b89a578b710a2499a5e62b upstream. sctp_unpack_cookie() only checked that the embedded INIT chunk length did not exceed the remaining cookie payload, but did not ensure that the INIT chunk is large enough to contain a complete INIT header. A malformed COOKIE_ECHO can therefore carry a truncated INIT chunk whose length field is smaller than sizeof(struct sctp_init_chunk). Later, sctp_process_init() accesses INIT parameters unconditionally, which may lead to out-of-bounds reads. In addition, raw_addr_list_len is not fully validated against the remaining cookie payload. When cookie authentication is disabled, an attacker can supply an oversized raw_addr_list_len and cause sctp_raw_to_bind_addrs() to read beyond the end of the cookie. The address parser also lacks sufficient bounds checks for parameter headers and lengths, allowing malformed address parameters to trigger out-of-bounds reads. Fix this by: - requiring the embedded INIT chunk length to be at least sizeof(struct sctp_init_chunk); - validating that the INIT chunk and raw address list together fit within the cookie payload; - verifying sufficient data exists for each address parameter header and payload before parsing it. Note that sctp_verify_init() must be called after sctp_unpack_cookie() and before sctp_process_init() when cookie authentication is disabled. This will be addressed in a separate patch. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: Sashiko <sashiko-bot@kernel.org> Signed-off-by: Xin Long <lucien.xin@gmail.com> Link: https://patch.msgid.link/75af23a89adf881a0895d511775e4770da367cbf.1780873427.git.lucien.xin@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> [ adapted to 5.15.y: extend the existing bounds check ] Signed-off-by: Dickson Wu <dickson.wu@certik.com> --- The backport and the test runs were prepared with AI coding tools (OpenAI Codex agents, with review by Claude). I went over the result before signing off. net/sctp/bind_addr.c | 11 ++++++++++- net/sctp/sm_make_chunk.c | 9 +++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/net/sctp/bind_addr.c b/net/sctp/bind_addr.c index 6b95d3ba8fe1c..0947b276d1e08 100644 --- a/net/sctp/bind_addr.c +++ b/net/sctp/bind_addr.c @@ -275,6 +275,16 @@ int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw_addr_list, param = (struct sctp_paramhdr *)raw_addr_list; rawaddr = (union sctp_addr_param *)raw_addr_list; + if (addrs_len < sizeof(*param)) { + retval = -EINVAL; + goto out_err; + } + len = ntohs(param->length); + if (addrs_len < len) { + retval = -EINVAL; + goto out_err; + } + af = sctp_get_af_specific(param_type2af(param->type)); if (unlikely(!af) || !af->from_addr_param(&addr, rawaddr, htons(port), 0)) { @@ -291,7 +301,6 @@ int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw_addr_list, goto out_err; next: - len = ntohs(param->length); addrs_len -= len; raw_addr_list += len; } diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c index b599dd2c15bd4..79d2c2b179c35 100644 --- a/net/sctp/sm_make_chunk.c +++ b/net/sctp/sm_make_chunk.c @@ -1759,8 +1759,8 @@ struct sctp_association *sctp_unpack_cookie( struct sctp_cookie *bear_cookie; struct sctp_chunkhdr *ch; __u8 *digest = ep->digest; + unsigned int len, chlen; enum sctp_scope scope; - unsigned int len; ktime_t kt; /* Header size is static data prior to the actual cookie, including @@ -1789,7 +1789,12 @@ struct sctp_association *sctp_unpack_cookie( bear_cookie = &cookie->c; ch = (struct sctp_chunkhdr *)&bear_cookie->peer_init[0]; - if (ntohs(ch->length) > len - fixed_size) + chlen = ntohs(ch->length); + if (chlen < sizeof(struct sctp_init_chunk)) + goto malformed; + if (chlen > len - fixed_size) + goto malformed; + if (bear_cookie->raw_addr_list_len > len - fixed_size - chlen) goto malformed; if (!sctp_sk(ep->base.sk)->hmac) -- 2.43.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5.15.y 3/3] sctp: add INIT verification after cookie unpacking 2026-11-27 3:45 ` Dickson Wu @ 2026-11-27 3:45 ` Dickson Wu via B4 Relay -1 siblings, 0 replies; 9+ messages in thread From: Dickson Wu @ 2026-11-27 3:45 UTC (permalink / raw) To: stable; +Cc: Xin Long, Marcelo Ricardo Leitner, linux-sctp, netdev From: Xin Long <lucien.xin@gmail.com> commit 414c5447fe6a200613dd46d7fdc8454622076cb1 upstream. In SCTP handshake, the INIT chunk is initially processed by the server and embedded into the cookie carried in INIT-ACK. The client then returns this cookie via COOKIE-ECHO, where the server unpacks it and reconstructs the original INIT chunk. When cookie authentication is enabled, the cookie contents are protected against tampering, so reusing the unpacked INIT without re-verification is safe. However, when cookie authentication is disabled, the reconstructed INIT can no longer be trusted. In this case, the INIT must be explicitly validated after unpacking to avoid processing potentially tampered data. Add sctp_verify_init() checks after cookie unpacking in COOKIE-ECHO processing paths (sctp_sf_do_5_1D_ce() and sctp_sf_do_5_2_4_dupcook()) when cookie_auth_enable is disabled. On failure, the new association is freed and the packet is discarded. Also tighten cookie validation in sctp_unpack_cookie() by verifying the embedded chunk type is SCTP_CID_INIT before treating it as an INIT chunk. Finally, update sctp_verify_init() to validate parameter bounds using the actual embedded INIT length instead of chunk->chunk_end, since the INIT stored in COOKIE-ECHO may not span the entire chunk buffer. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Xin Long <lucien.xin@gmail.com> Link: https://patch.msgid.link/ebcbbac574815b0850f371b4bdb02f2e602b94d3.1782341592.git.lucien.xin@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> [ adapted to 5.15.y: use ->hmac and peer_init[]; verify A/B before the security hook ] Signed-off-by: Dickson Wu <dickson.wu@certik.com> --- The backport and the test runs were prepared with AI coding tools (OpenAI Codex agents, with review by Claude). I went over the result before signing off. net/sctp/sm_make_chunk.c | 5 ++++- net/sctp/sm_statefuns.c | 46 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c index 79d2c2b179c35..669b94d9db620 100644 --- a/net/sctp/sm_make_chunk.c +++ b/net/sctp/sm_make_chunk.c @@ -1789,6 +1789,8 @@ struct sctp_association *sctp_unpack_cookie( bear_cookie = &cookie->c; ch = (struct sctp_chunkhdr *)&bear_cookie->peer_init[0]; + if (ch->type != SCTP_CID_INIT) + goto malformed; chlen = ntohs(ch->length); if (chlen < sizeof(struct sctp_init_chunk)) goto malformed; @@ -2346,7 +2348,8 @@ int sctp_verify_init(struct net *net, const struct sctp_endpoint *ep, * VIOLATION error. We build the ERROR chunk here and let the normal * error handling code build and send the packet. */ - if (param.v != (void *)chunk->chunk_end) + if (param.v != (void *)peer_init + + SCTP_PAD4(ntohs(peer_init->chunk_hdr.length))) return sctp_process_inv_paramlength(asoc, param.p, chunk, errp); /* The only missing mandatory param possible today is diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c index aec07ab9b9513..2990a3d7c5780 100644 --- a/net/sctp/sm_statefuns.c +++ b/net/sctp/sm_statefuns.c @@ -707,8 +707,9 @@ enum sctp_disposition sctp_sf_do_5_1D_ce(struct net *net, struct sctp_association *new_asoc; struct sctp_init_chunk *peer_init; struct sctp_chunk *chunk = arg; - struct sctp_chunk *err_chk_p; + struct sctp_chunk *err_chk_p = NULL; struct sctp_chunk *repl; + enum sctp_cid cid; struct sock *sk; int error = 0; @@ -782,6 +783,18 @@ enum sctp_disposition sctp_sf_do_5_1D_ce(struct net *net, } } + peer_init = &chunk->subh.cookie_hdr->c.peer_init[0]; + cid = peer_init->chunk_hdr.type; + if (!sctp_sk(sk)->hmac && + !sctp_verify_init(net, ep, asoc, cid, peer_init, chunk, + &err_chk_p)) { + sctp_association_free(new_asoc); + if (err_chk_p) + sctp_chunk_free(err_chk_p); + return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); + } + if (err_chk_p) + sctp_chunk_free(err_chk_p); /* Delay state machine commands until later. * @@ -791,8 +804,6 @@ enum sctp_disposition sctp_sf_do_5_1D_ce(struct net *net, /* This is a brand-new association, so these are not yet side * effects--it is safe to run them here. */ - peer_init = &chunk->subh.cookie_hdr->c.peer_init[0]; - if (!sctp_process_init(new_asoc, chunk, &chunk->subh.cookie_hdr->c.peer_addr, peer_init, GFP_ATOMIC)) @@ -2205,10 +2216,12 @@ enum sctp_disposition sctp_sf_do_5_2_4_dupcook( void *arg, struct sctp_cmd_seq *commands) { + struct sctp_chunk *err_chk_p = NULL; struct sctp_association *new_asoc; + struct sctp_init_chunk *peer_init; struct sctp_chunk *chunk = arg; enum sctp_disposition retval; - struct sctp_chunk *err_chk_p; + enum sctp_cid cid; int error = 0; char action; @@ -2263,6 +2276,26 @@ enum sctp_disposition sctp_sf_do_5_2_4_dupcook( } } + /* Compare the tie_tag in cookie with the verification tag of + * current association. + */ + action = sctp_tietags_compare(new_asoc, asoc); + + if ((action == 'A' || action == 'B') && !sctp_sk(ep->base.sk)->hmac) { + peer_init = &chunk->subh.cookie_hdr->c.peer_init[0]; + cid = peer_init->chunk_hdr.type; + if (!sctp_verify_init(net, ep, asoc, cid, peer_init, chunk, + &err_chk_p)) { + sctp_association_free(new_asoc); + if (err_chk_p) + sctp_chunk_free(err_chk_p); + return sctp_sf_pdiscard(net, ep, asoc, type, arg, + commands); + } + if (err_chk_p) + sctp_chunk_free(err_chk_p); + } + /* Update socket peer label if first association. */ if (security_sctp_assoc_request((struct sctp_endpoint *)ep, chunk->skb)) { @@ -2273,11 +2306,6 @@ enum sctp_disposition sctp_sf_do_5_2_4_dupcook( /* Set temp so that it won't be added into hashtable */ new_asoc->temp = 1; - /* Compare the tie_tag in cookie with the verification tag of - * current association. - */ - action = sctp_tietags_compare(new_asoc, asoc); - switch (action) { case 'A': /* Association restart. */ retval = sctp_sf_do_dupcook_a(net, ep, asoc, chunk, commands, -- 2.43.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5.15.y 3/3] sctp: add INIT verification after cookie unpacking @ 2026-11-27 3:45 ` Dickson Wu via B4 Relay 0 siblings, 0 replies; 9+ messages in thread From: Dickson Wu via B4 Relay @ 2026-11-27 3:45 UTC (permalink / raw) To: stable; +Cc: Xin Long, Marcelo Ricardo Leitner, linux-sctp, netdev From: Xin Long <lucien.xin@gmail.com> commit 414c5447fe6a200613dd46d7fdc8454622076cb1 upstream. In SCTP handshake, the INIT chunk is initially processed by the server and embedded into the cookie carried in INIT-ACK. The client then returns this cookie via COOKIE-ECHO, where the server unpacks it and reconstructs the original INIT chunk. When cookie authentication is enabled, the cookie contents are protected against tampering, so reusing the unpacked INIT without re-verification is safe. However, when cookie authentication is disabled, the reconstructed INIT can no longer be trusted. In this case, the INIT must be explicitly validated after unpacking to avoid processing potentially tampered data. Add sctp_verify_init() checks after cookie unpacking in COOKIE-ECHO processing paths (sctp_sf_do_5_1D_ce() and sctp_sf_do_5_2_4_dupcook()) when cookie_auth_enable is disabled. On failure, the new association is freed and the packet is discarded. Also tighten cookie validation in sctp_unpack_cookie() by verifying the embedded chunk type is SCTP_CID_INIT before treating it as an INIT chunk. Finally, update sctp_verify_init() to validate parameter bounds using the actual embedded INIT length instead of chunk->chunk_end, since the INIT stored in COOKIE-ECHO may not span the entire chunk buffer. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Xin Long <lucien.xin@gmail.com> Link: https://patch.msgid.link/ebcbbac574815b0850f371b4bdb02f2e602b94d3.1782341592.git.lucien.xin@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> [ adapted to 5.15.y: use ->hmac and peer_init[]; verify A/B before the security hook ] Signed-off-by: Dickson Wu <dickson.wu@certik.com> --- The backport and the test runs were prepared with AI coding tools (OpenAI Codex agents, with review by Claude). I went over the result before signing off. net/sctp/sm_make_chunk.c | 5 ++++- net/sctp/sm_statefuns.c | 46 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c index 79d2c2b179c35..669b94d9db620 100644 --- a/net/sctp/sm_make_chunk.c +++ b/net/sctp/sm_make_chunk.c @@ -1789,6 +1789,8 @@ struct sctp_association *sctp_unpack_cookie( bear_cookie = &cookie->c; ch = (struct sctp_chunkhdr *)&bear_cookie->peer_init[0]; + if (ch->type != SCTP_CID_INIT) + goto malformed; chlen = ntohs(ch->length); if (chlen < sizeof(struct sctp_init_chunk)) goto malformed; @@ -2346,7 +2348,8 @@ int sctp_verify_init(struct net *net, const struct sctp_endpoint *ep, * VIOLATION error. We build the ERROR chunk here and let the normal * error handling code build and send the packet. */ - if (param.v != (void *)chunk->chunk_end) + if (param.v != (void *)peer_init + + SCTP_PAD4(ntohs(peer_init->chunk_hdr.length))) return sctp_process_inv_paramlength(asoc, param.p, chunk, errp); /* The only missing mandatory param possible today is diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c index aec07ab9b9513..2990a3d7c5780 100644 --- a/net/sctp/sm_statefuns.c +++ b/net/sctp/sm_statefuns.c @@ -707,8 +707,9 @@ enum sctp_disposition sctp_sf_do_5_1D_ce(struct net *net, struct sctp_association *new_asoc; struct sctp_init_chunk *peer_init; struct sctp_chunk *chunk = arg; - struct sctp_chunk *err_chk_p; + struct sctp_chunk *err_chk_p = NULL; struct sctp_chunk *repl; + enum sctp_cid cid; struct sock *sk; int error = 0; @@ -782,6 +783,18 @@ enum sctp_disposition sctp_sf_do_5_1D_ce(struct net *net, } } + peer_init = &chunk->subh.cookie_hdr->c.peer_init[0]; + cid = peer_init->chunk_hdr.type; + if (!sctp_sk(sk)->hmac && + !sctp_verify_init(net, ep, asoc, cid, peer_init, chunk, + &err_chk_p)) { + sctp_association_free(new_asoc); + if (err_chk_p) + sctp_chunk_free(err_chk_p); + return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands); + } + if (err_chk_p) + sctp_chunk_free(err_chk_p); /* Delay state machine commands until later. * @@ -791,8 +804,6 @@ enum sctp_disposition sctp_sf_do_5_1D_ce(struct net *net, /* This is a brand-new association, so these are not yet side * effects--it is safe to run them here. */ - peer_init = &chunk->subh.cookie_hdr->c.peer_init[0]; - if (!sctp_process_init(new_asoc, chunk, &chunk->subh.cookie_hdr->c.peer_addr, peer_init, GFP_ATOMIC)) @@ -2205,10 +2216,12 @@ enum sctp_disposition sctp_sf_do_5_2_4_dupcook( void *arg, struct sctp_cmd_seq *commands) { + struct sctp_chunk *err_chk_p = NULL; struct sctp_association *new_asoc; + struct sctp_init_chunk *peer_init; struct sctp_chunk *chunk = arg; enum sctp_disposition retval; - struct sctp_chunk *err_chk_p; + enum sctp_cid cid; int error = 0; char action; @@ -2263,6 +2276,26 @@ enum sctp_disposition sctp_sf_do_5_2_4_dupcook( } } + /* Compare the tie_tag in cookie with the verification tag of + * current association. + */ + action = sctp_tietags_compare(new_asoc, asoc); + + if ((action == 'A' || action == 'B') && !sctp_sk(ep->base.sk)->hmac) { + peer_init = &chunk->subh.cookie_hdr->c.peer_init[0]; + cid = peer_init->chunk_hdr.type; + if (!sctp_verify_init(net, ep, asoc, cid, peer_init, chunk, + &err_chk_p)) { + sctp_association_free(new_asoc); + if (err_chk_p) + sctp_chunk_free(err_chk_p); + return sctp_sf_pdiscard(net, ep, asoc, type, arg, + commands); + } + if (err_chk_p) + sctp_chunk_free(err_chk_p); + } + /* Update socket peer label if first association. */ if (security_sctp_assoc_request((struct sctp_endpoint *)ep, chunk->skb)) { @@ -2273,11 +2306,6 @@ enum sctp_disposition sctp_sf_do_5_2_4_dupcook( /* Set temp so that it won't be added into hashtable */ new_asoc->temp = 1; - /* Compare the tie_tag in cookie with the verification tag of - * current association. - */ - action = sctp_tietags_compare(new_asoc, asoc); - switch (action) { case 'A': /* Association restart. */ retval = sctp_sf_do_dupcook_a(net, ep, asoc, chunk, commands, -- 2.43.0 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 5.15.y 0/3] sctp: validate the cached INIT in COOKIE_ECHO 2026-11-27 3:45 ` Dickson Wu ` (3 preceding siblings ...) (?) @ 2026-11-29 18:59 ` Sasha Levin -1 siblings, 0 replies; 9+ messages in thread From: Sasha Levin @ 2026-11-29 18:59 UTC (permalink / raw) To: stable Cc: Sasha Levin, Xin Long, Marcelo Ricardo Leitner, linux-sctp, netdev, Dickson Wu via B4 Relay, Dickson Wu > 6.1.y and newer already have these three fixes. 5.15.y keeps the > cached INIT in peer_init[] and tests sctp_sk()->hmac instead of Queued the series for 5.15, thanks. -- Thanks, Sasha ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-11-29 19:00 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-27 3:45 [PATCH 5.15.y 0/3] sctp: validate the cached INIT in COOKIE_ECHO Dickson Wu via B4 Relay 2026-11-27 3:45 ` Dickson Wu 2026-11-27 3:45 ` [PATCH 5.15.y 1/3] sctp: validate cached peer INIT chunk length in COOKIE_ECHO processing Dickson Wu via B4 Relay 2026-11-27 3:45 ` Dickson Wu 2026-11-27 3:45 ` [PATCH 5.15.y 2/3] sctp: validate embedded INIT chunk and address list lengths in cookie Dickson Wu via B4 Relay 2026-11-27 3:45 ` Dickson Wu 2026-11-27 3:45 ` [PATCH 5.15.y 3/3] sctp: add INIT verification after cookie unpacking Dickson Wu 2026-11-27 3:45 ` Dickson Wu via B4 Relay 2026-11-29 18:59 ` [PATCH 5.15.y 0/3] sctp: validate the cached INIT in COOKIE_ECHO Sasha Levin
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.