Skip to content

Commit 1cd23ca

Browse files
winminPaolo Abeni
authored andcommitted
sctp: validate STALE_COOKIE cause length before reading staleness
When an ERROR chunk with a STALE_COOKIE cause is received in the COOKIE_ECHOED state, sctp_sf_do_5_2_6_stale() reads the 4-byte Measure of Staleness that follows the cause header: err = (struct sctp_errhdr *)(chunk->skb->data); stale = ntohl(*(__be32 *)((u8 *)err + sizeof(*err))); err is the first cause in the chunk, not the STALE_COOKIE cause that caused the dispatch, and nothing guarantees the staleness field is present. sctp_walk_errors() only requires a cause to be as long as the 4-byte header, so for a STALE_COOKIE cause of length 4 the read runs past the cause, and for a minimal ERROR chunk past skb->tail. The value is echoed to the peer in the Cookie Preservative of the reply INIT, leaking uninitialized memory. sctp_sf_cookie_echoed_err() already walks to the STALE_COOKIE cause, so check its length there and pass it to sctp_sf_do_5_2_6_stale(), which reads that cause instead of the first one. A STALE_COOKIE cause too short to hold the staleness field is discarded. The read is reachable by any peer that can drive an association into COOKIE_ECHOED, including an unprivileged process using a raw SCTP socket in a user and network namespace. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: Xiang Mei <xmei5@asu.edu> Assisted-by: Claude:claude-opus-4-8 Cc: stable@vger.kernel.org Signed-off-by: Weiming Shi <bestswngs@gmail.com> Acked-by: Xin Long <lucien.xin@gmail.com> Link: https://patch.msgid.link/20260704033545.2438373-2-bestswngs@gmail.com Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent a0d82fb commit 1cd23ca

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

net/sctp/sm_statefuns.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ static enum sctp_disposition sctp_sf_do_5_2_6_stale(
7474
const struct sctp_association *asoc,
7575
const union sctp_subtype type,
7676
void *arg,
77-
struct sctp_cmd_seq *commands);
77+
struct sctp_cmd_seq *commands,
78+
struct sctp_errhdr *err);
7879
static enum sctp_disposition sctp_sf_shut_8_4_5(
7980
struct net *net,
8081
const struct sctp_endpoint *ep,
@@ -2529,9 +2530,15 @@ enum sctp_disposition sctp_sf_cookie_echoed_err(
25292530
* errors.
25302531
*/
25312532
sctp_walk_errors(err, chunk->chunk_hdr) {
2532-
if (SCTP_ERROR_STALE_COOKIE == err->cause)
2533-
return sctp_sf_do_5_2_6_stale(net, ep, asoc, type,
2534-
arg, commands);
2533+
if (err->cause != SCTP_ERROR_STALE_COOKIE)
2534+
continue;
2535+
/* The staleness is only meaningful if the cause is long
2536+
* enough to hold it; a shorter one is malformed.
2537+
*/
2538+
if (ntohs(err->length) < sizeof(*err) + sizeof(__be32))
2539+
break;
2540+
return sctp_sf_do_5_2_6_stale(net, ep, asoc, type,
2541+
arg, commands, err);
25352542
}
25362543

25372544
/* It is possible to have malformed error causes, and that
@@ -2573,13 +2580,13 @@ static enum sctp_disposition sctp_sf_do_5_2_6_stale(
25732580
const struct sctp_association *asoc,
25742581
const union sctp_subtype type,
25752582
void *arg,
2576-
struct sctp_cmd_seq *commands)
2583+
struct sctp_cmd_seq *commands,
2584+
struct sctp_errhdr *err)
25772585
{
25782586
int attempts = asoc->init_err_counter + 1;
2579-
struct sctp_chunk *chunk = arg, *reply;
25802587
struct sctp_cookie_preserve_param bht;
25812588
struct sctp_bind_addr *bp;
2582-
struct sctp_errhdr *err;
2589+
struct sctp_chunk *reply;
25832590
u32 stale;
25842591

25852592
if (attempts > asoc->max_init_attempts) {
@@ -2590,8 +2597,6 @@ static enum sctp_disposition sctp_sf_do_5_2_6_stale(
25902597
return SCTP_DISPOSITION_DELETE_TCB;
25912598
}
25922599

2593-
err = (struct sctp_errhdr *)(chunk->skb->data);
2594-
25952600
/* When calculating the time extension, an implementation
25962601
* SHOULD use the RTT information measured based on the
25972602
* previous COOKIE ECHO / ERROR exchange, and should add no

0 commit comments

Comments
 (0)