* [PATCH net] sctp: validate SACK gap-ack block ranges
@ 2026-12-01 14:18 Shawn Shao
2026-12-01 14:25 ` netdev-bot+sinfo
0 siblings, 1 reply; 2+ 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] 2+ 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
0 siblings, 0 replies; 2+ 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] 2+ messages in thread
end of thread, other threads:[~2026-12-01 14:25 UTC | newest]
Thread overview: 2+ 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox