Netdev List
 help / color / mirror / Atom feed
* [PATCH net] sctp: validate SACK gap-ack block ranges
@ 2026-12-01 14:18 Shawn Shao
  2026-12-01 14:25 ` netdev-bot+sinfo
  2026-12-04  2:18 ` netdev-bot+sashiko
  0 siblings, 2 replies; 3+ messages in thread
From: Shawn Shao @ 2026-12-01 14:18 UTC (permalink / raw)
  To: Marcelo Ricardo Leitner, Xin Long
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Willem de Bruijn, Simon Horman, linux-sctp, netdev

Hello,

sctp_sack_update_unack_data() subtracts each Gap Ack Block's width
from a 16-bit count of outstanding DATA chunks. The SACK path does
not validate that the ranges are well-formed. With one outstanding
DATA chunk, an established peer can send a SACK with start=65535 and
end=0; this makes the reported SCTP_STATUS.sstat_unackdata wrap to
65535.

The patch validates Gap Ack Blocks before processing the SACK. It
discards zero, inverted, overlapping, or out-of-order ranges. If a
well-formed block acknowledges a TSN that has not been sent, the
association is aborted as required by RFC 9260, Section 12.4.

The trigger requires an established SCTP association and a SACK with
a valid verification tag and CRC32c. The demonstrated issue is
incorrect protocol accounting observable through getsockopt().
No crash, memory corruption, information disclosure, or privilege
escalation was observed.

Gap Ack Block offsets are relative to the Cumulative TSN Ack, as
defined in RFC 9260, Section 3.3.4:
https://www.rfc-editor.org/rfc/rfc9260.html#section-3.3.4

Tested source revision:
HEAD commit:    7cd8495c0f16275c4f9abe1cef09a7b5fcd6d046
git tree:       194227446ae61b4971eea1b7bed06856fe3cc477
source version: v7.3-23903-g7cd8495c0f162 (Linux 7.4.0-rc4)
compiler:       gcc 11.4.0, GNU ld 2.38, GNU Make 4.3
QEMU:           6.2.0, x86-64 TCG, one vCPU

The complete console logs, kernel configuration, reproducer, and
reproduction scripts are available here:

console output:
https://gist.githubusercontent.com/shaos26/08241891ab01c14e900a41e9b09cb4b4/raw/32b58cba46b785e30df07414ed0ef7f25045ccd9/console-output.txt
kernel config:
https://gist.githubusercontent.com/shaos26/08241891ab01c14e900a41e9b09cb4b4/raw/32b58cba46b785e30df07414ed0ef7f25045ccd9/kernel-config.txt
reproducer:
https://gist.githubusercontent.com/shaos26/08241891ab01c14e900a41e9b09cb4b4/raw/32b58cba46b785e30df07414ed0ef7f25045ccd9/poc.c
PoC build script:
https://gist.githubusercontent.com/shaos26/08241891ab01c14e900a41e9b09cb4b4/raw/32b58cba46b785e30df07414ed0ef7f25045ccd9/build-poc.sh
initramfs builder:
https://gist.githubusercontent.com/shaos26/08241891ab01c14e900a41e9b09cb4b4/raw/32b58cba46b785e30df07414ed0ef7f25045ccd9/build-initramfs.sh
QEMU runner:
https://gist.githubusercontent.com/shaos26/08241891ab01c14e900a41e9b09cb4b4/raw/32b58cba46b785e30df07414ed0ef7f25045ccd9/run-qemu.sh
patch:
https://gist.githubusercontent.com/shaos26/08241891ab01c14e900a41e9b09cb4b4/raw/32b58cba46b785e30df07414ed0ef7f25045ccd9/fix.patch

The reproducer uses a TUN device to emulate the SCTP peer. It sends
one DATA chunk and then injects a SACK for the selected mode. Build
the kernel from the tested revision with the supplied configuration,
then run:

    set -eu
    work=$(mktemp -d /tmp/sctp-sack.XXXXXX)
    cd "$work"
    gist_id=08241891ab01c14e900a41e9b09cb4b4
    gist_revision=32b58cba46b785e30df07414ed0ef7f25045ccd9
    gist_base=https://gist.githubusercontent.com/shaos26
    gist=$gist_base/$gist_id/raw/$gist_revision
    for file in console-output.txt kernel-config.txt poc.c \
        build-poc.sh build-initramfs.sh run-qemu.sh fix.patch; do
        curl -fL "$gist/$file" -o "$file"
    done
    git clone \
        https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
    cd linux
    git checkout 7cd8495c0f16275c4f9abe1cef09a7b5fcd6d046
    mkdir build
    cp ../kernel-config.txt build/.config
    make O=build olddefconfig
    make O=build -j"$(nproc)" bzImage
    cd ..
    sh ./build-poc.sh poc.c poc

Run the baseline modes against the unmodified kernel, then apply the
patch and run the same modes:

    run_modes() {
        prefix=$1
        for mode in gap range overlap valid nogap; do
            sh ./build-initramfs.sh "$mode" "$PWD/poc" \
                "$PWD/linux/build/scripts/gen_init_cpio" \
                "$PWD/initrd-$mode.cpio.gz"
            sh ./run-qemu.sh "$PWD/linux/build/arch/x86/boot/bzImage" \
                "$PWD/initrd-$mode.cpio.gz" \
                "$PWD/$prefix-$mode.log"
        done
    }
    run_modes base

Apply the supplied fix.patch and rebuild the kernel:

    git -C linux apply --check sctp.patch
    git -C linux apply sctp.patch
    make -C linux O=build -j"$(nproc)" bzImage
    run_modes fixed

The modes are: gap, an inverted start=65535/end=0 block; range, a
start=1/end=65535 block that acknowledges unsent TSNs; overlap, the
same one-TSN block twice; valid, one block acknowledging the sent
TSN; and nogap, the same SACK with no Gap Ack Blocks.

Observed sstat_unackdata, SctpInPktDiscards, and SctpAborteds:

    baseline gap:       65535, discard 0, aborts 0
    patched gap:            1, discard 1, aborts 0
    baseline overlap:   65535, discard 0, aborts 0
    patched overlap:        1, discard 1, aborts 0
    baseline range:         2, discard 0, aborts 0
    patched range:  association aborted, discard 1, aborts 1
    baseline valid:         0, discard 0, aborts 0
    patched valid:          0, discard 0, aborts 0
    baseline nogap:         1, discard 0, aborts 0
    patched nogap:          1, discard 0, aborts 0

The association stays established for the inverted and overlapping
ranges. The range mode closes it because that block acknowledges
TSNs not sent. Both valid controls continue to work.

Signed-off-by: Shawn Shao <shawnq1@163.com>

Thanks,
Shawn Shao

---
 net/sctp/sm_statefuns.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
index 6a4205de0aa69..79d297af661d4 100644
--- a/net/sctp/sm_statefuns.c
+++ b/net/sctp/sm_statefuns.c
@@ -3457,7 +3457,11 @@ enum sctp_disposition sctp_sf_eat_sack_6_2(struct net *net,
 {
 	struct sctp_chunk *chunk = arg;
 	struct sctp_sackhdr *sackh;
-	__u32 ctsn;
+	union sctp_sack_variable *frags;
+	__u32 ctsn, max_offset, last_end = 0;
+	__u16 num_blocks, i, start, end;
+	static const __u8 err_str[] =
+		"Gap Ack Block acknowledges a TSN that has not been sent:";
 
 	if (!sctp_vtag_verify(chunk, asoc))
 		return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
@@ -3497,6 +3501,24 @@ enum sctp_disposition sctp_sf_eat_sack_6_2(struct net *net,
 		return SCTP_DISPOSITION_DISCARD;
 	}
 
+	/* Gap Ack Blocks must describe sent TSNs in ascending order. */
+	frags = (union sctp_sack_variable *)(sackh + 1);
+	num_blocks = ntohs(sackh->num_gap_ack_blocks);
+	max_offset = asoc->next_tsn - ctsn - 1;
+	for (i = 0; i < num_blocks; i++) {
+		start = ntohs(frags[i].gab.start);
+		end = ntohs(frags[i].gab.end);
+		if (!start || start > end || (i && start <= last_end))
+			return sctp_sf_pdiscard(net, ep, asoc, type, arg,
+						commands);
+		if (end > max_offset)
+			return sctp_sf_abort_violation(net, ep, asoc, chunk,
+						       commands, err_str,
+						       sizeof(err_str));
+
+		last_end = end;
+	}
+
 	/* Return this SACK for further processing.  */
 	sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_CHUNK(chunk));
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] sctp: validate SACK gap-ack block ranges
  2026-12-01 14:18 [PATCH net] sctp: validate SACK gap-ack block ranges Shawn Shao
@ 2026-12-01 14:25 ` netdev-bot+sinfo
  2026-12-04  2:18 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sinfo @ 2026-12-01 14:25 UTC (permalink / raw)
  To: Shawn Shao
  Cc: Marcelo Ricardo Leitner, Xin Long, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Willem de Bruijn, Simon Horman,
	linux-sctp, netdev

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] sctp: validate SACK gap-ack block ranges
  2026-12-01 14:18 [PATCH net] sctp: validate SACK gap-ack block ranges Shawn Shao
  2026-12-01 14:25 ` netdev-bot+sinfo
@ 2026-12-04  2:18 ` netdev-bot+sashiko
  1 sibling, 0 replies; 3+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04  2:18 UTC (permalink / raw)
  To: shawnq1
  Cc: marcelo.leitner, lucien.xin, davem, edumazet, kuba, pabeni,
	willemb, horms, linux-sctp, netdev

Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 3

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] The commit message understates what the new check does, and
  the drop behaviour it chose has costs.
- [Low] The patch fixes a bug that a remote peer can trigger.
- [Low] The commit message gives 'RFC 9260, Section 12.4' as the
  requirement for the new abort in sctp_sf_eat_sack_6_2()…
- [Low] The commit body is formatted as an email and would end up in git
  history that way.

--

sctp: validate SACK gap-ack block ranges

This patch adds a check of the Gap Ack Blocks to sctp_sf_eat_sack_6_2(),
run before the SACK is queued for processing. A block with a zero start,
an inverted range, or a start at or below the previous block's end causes
the packet to be discarded. A block that ends past the last sent TSN
aborts the association.

> The patch validates Gap Ack Blocks before processing the SACK. It
> discards zero, inverted, overlapping, or out-of-order ranges. If a
> well-formed block acknowledges a TSN that has not been sent, the
> association is aborted as required by RFC 9260, Section 12.4.

[Severity: Low]
Is RFC 9260, Section 12.4 the right reference for this abort? As far as I
can tell, that section is "Protection of Non-SCTP-Capable Hosts" in the
Security Considerations. It doesn't seem to require an abort when a Gap
Ack Block acknowledges a TSN that hasn't been sent. I haven't been able to
check the RFC text directly, so this needs confirming.

SACKs that used to be tolerated now tear down the association with
ECONNABORTED. Could the commit message cite the normative text that
requires this? If that text is only a SHOULD or MAY, could the message
say so?

[ ... ]

> Apply the supplied fix.patch and rebuild the kernel:
>
>     git -C linux apply --check sctp.patch
>     git -C linux apply sctp.patch

[Severity: Low]
This isn't a bug, but the script downloads fix.patch and then applies
sctp.patch, so it won't work as written.

The commit body is also formatted as an email. It opens with "Hello," and
has "Thanks, Shawn Shao" after the Signed-off-by line, and both would end
up in git history. Could the greeting, the closing and the long
reproduction script move below the --- line, or be trimmed?

The tested version string "v7.3-23903-g7cd8495c0f162 (Linux 7.4.0-rc4)"
also looks inconsistent.

[ ... ]

> Signed-off-by: Shawn Shao <shawnq1@163.com>

[Severity: Low]
Should this have a Fixes: tag? The unchecked subtraction being guarded
against dates back to the initial git import:

net/sctp/outqueue.c:sctp_sack_update_unack_data() {
    ...
	for (i = 0; i < ntohs(sack->num_gap_ack_blocks); i++) {
		unack_data -= ((ntohs(frags[i].gab.end) -
				ntohs(frags[i].gab.start) + 1));
	}
    ...
}

sctp_outq_sack() has long assumed that the last block holds the highest
end, which the new ordering check now enforces:

	highest_tsn += ntohs(frags[gap_ack_blocks - 1].gab.end);

Something like this would help stable backporters pick up the fix:

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")

> diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
> index 6a4205de0aa69..79d297af661d4 100644
> --- a/net/sctp/sm_statefuns.c
> +++ b/net/sctp/sm_statefuns.c

[ ... ]

> @@ -3497,6 +3501,24 @@ enum sctp_disposition sctp_sf_eat_sack_6_2(struct net *net,
>  		return SCTP_DISPOSITION_DISCARD;
>  	}
>
> +	/* Gap Ack Blocks must describe sent TSNs in ascending order. */
> +	frags = (union sctp_sack_variable *)(sackh + 1);
> +	num_blocks = ntohs(sackh->num_gap_ack_blocks);
> +	max_offset = asoc->next_tsn - ctsn - 1;
> +	for (i = 0; i < num_blocks; i++) {
> +		start = ntohs(frags[i].gab.start);
> +		end = ntohs(frags[i].gab.end);
> +		if (!start || start > end || (i && start <= last_end))
> +			return sctp_sf_pdiscard(net, ep, asoc, type, arg,
> +						commands);

[Severity: Medium]
Should a single bad block discard the whole packet here?
sctp_sf_pdiscard() queues SCTP_CMD_DISCARD_PACKET, and
sctp_cmd_interpreter() handles that command by marking the entire packet:

net/sctp/sm_sideeffect.c:sctp_cmd_interpreter() {
    ...
		case SCTP_CMD_DISCARD_PACKET:
			/* We need to discard the whole packet.
			 * Uncork the queue since there might be
			 * responses pending
			 */
			chunk->pdiscard = 1;
    ...
}

After that, sctp_inq_peek() and sctp_inq_pop() stop returning the
remaining chunks of the packet:

net/sctp/inqueue.c:sctp_inq_peek() {
    ...
	if (chunk->singleton ||
	    chunk->end_of_packet ||
	    chunk->pdiscard)
		    return NULL;
    ...
}

So SCTP_CMD_PROCESS_SACK is never queued, and the SACK's otherwise valid
Cumulative TSN Ack and a_rwnd are ignored. ctsn_ack_point doesn't
advance, the peer rwnd isn't updated, and the transmitted queue isn't
freed. Any DATA or control chunks bundled after the SACK in the same
packet are dropped too.

Suppose a peer always sends blocks in this form. Would its SACKs then
always be ignored? The cumulative ack would never move, and the
association would eventually fail on the T3-rtx retransmission limits.

Before this patch, sctp_check_transmitted() and sctp_acked() matched each
block on its own, so these SACKs were still processed.

The out-of-order cumulative ack check just above returns
SCTP_DISPOSITION_DISCARD, which drops only this chunk. Would that, or
skipping the bad block, fit better here?

The commit message says the patch "discards zero, inverted, overlapping,
or out-of-order ranges". In practice the whole packet is dropped. RFC
9260 Section 3.3.4 also seems to say only that Gap Ack Blocks SHOULD be
isolated. Is strict ascending, non-overlapping order actually required?

> +		if (end > max_offset)
> +			return sctp_sf_abort_violation(net, ep, asoc, chunk,
> +						       commands, err_str,
> +						       sizeof(err_str));
> +
> +		last_end = end;
> +	}
> +
>  	/* Return this SACK for further processing.  */
>  	sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_CHUNK(chunk));
>

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179613469562.187341.14965162957276514602.1796134695.3-1-shawnq1%40163.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-04  2:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 14:18 [PATCH net] sctp: validate SACK gap-ack block ranges Shawn Shao
2026-12-01 14:25 ` netdev-bot+sinfo
2026-12-04  2:18 ` 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