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 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