sctp: fix I-FORWARD-TSN handling with user message interleaving
Subsystems (5)
v2 cover sctp: fix I-FORWARD-TSN handling with user message interleaving
With user message interleaving (RFC 8260), fragments of messages on different streams share the TSN space. When a PR-SCTP message is abandoned, the receiver still frees queued fragments by the I-FORWARD-TSN's New Cumulative TSN, which loses fragments of messages still being received on other streams:
TSN stream MID
0 0 0 B 64KB reliable message on stream 0
...
5 0 0
6 1 0 BE PR-SCTP message on stream 1, lost, abandoned
7 0 0 ...
I-FORWARD-TSN new_cum=6 skip=[sid=1 mid=0]
The stream 0 fragments with TSNs 0-5 are freed with the abandoned message, are never retransmitted, and stream 0 stays blocked.
Patch 3 frees fragments by the skip entries instead of by TSN, and no longer treats an I-FORWARD-TSN that reaches the highest TSN seen as a reset. Such an I-FORWARD-TSN is then handled by sctp_intl_skip() alone, which has two partial delivery bugs of its own: an unordered partial delivery is not aborted when its own message is skipped, and PARTIAL_DELIVERY_ABORTED reports the highest skipped MID rather than the one being delivered. Patches 1 and 2 fix these first, so the three fixes should be backported together and in order. Patch 4 adds a selftest.
Patch 3 has a cost, as discussed on v1 [2]: an unordered fragment of an abandoned message that first arrives after the last I-FORWARD-TSN naming that message is no longer freed by a later, unrelated I-FORWARD-TSN. It keeps its rwnd and receive buffer charge until a later unordered skip on its stream, a reset, or teardown. Dropping such fragments on arrival needs new per-stream state and is left to a follow-up [3].
Changes since v1 [1]:
- Fold "sctp: don't treat an I-FORWARD-TSN as an association reset" into the purge patch, now patch 3, as Xin suggested [3].
- New patch 2, from Sashiko's review of v1 patch 3.
- Move the unordered partial delivery fix first.
- Selftest: add leading_edge_nopd, reset_pending_srv/cli and pdapi/pdapi_uo; wait for conditions rather than fixed times, including all data being acked before the queue check.
Tested with the new selftest, sctp_vrf.sh and the lksctp-tools functional tests, also on a kernel with KASAN, lockdep and kmemleak. W=1 and sparse show no new warnings.
Initial bug observed in use, root cause identified with AI-assisted code inspection. Related bugs found and fixes implemented with AI assistance. All reviewed and tested by me.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/CADvbK_du=-oT19kKBKYSjFKYscnQSH1mekRKMXgmLPMXTEH_=w@mail.gmail.com/
Tim Budding (4):
sctp: abort unordered partial delivery when its message is skipped
sctp: report the partially delivered MID in PARTIAL_DELIVERY_ABORTED
sctp: fix I-FORWARD-TSN handling of fragments on other streams
selftests: net: add SCTP I-FORWARD-TSN tests with message interleaving
net/sctp/stream.c | 2 + net/sctp/stream_interleave.c | 38 +- tools/testing/selftests/net/.gitignore | 1 + tools/testing/selftests/net/Makefile | 2 + tools/testing/selftests/net/sctp_ifwdtsn.c | 699 ++++++++++++++++++++ tools/testing/selftests/net/sctp_ifwdtsn.sh | 233 +++++++ 6 files changed, 951 insertions(+), 24 deletions(-) create mode 100644 tools/testing/selftests/net/sctp_ifwdtsn.c create mode 100755 tools/testing/selftests/net/sctp_ifwdtsn.sh
base-commit: 6baae996ecf6a3f57b08ea6f6786e29af9260f51
Signature · 1 line
2.34.1
PATCH v2 1/4 sctp: abort unordered partial delivery when its message is skipped
When an I-FORWARD-TSN skips unordered messages on a stream, sctp_intl_skip() only aborts the stream's unordered partial delivery if the MID being delivered is lower than the skipped MID. If the skipped message is the one being partially delivered, partial delivery stays in
progress: no PARTIAL_DELIVERY_ABORTED is sent, and the next unordered message on the stream is delivered as the rest of the abandoned one.
Abort the partial delivery when the MID being delivered is at or below the skipped MID, as the ordered case already does.
Reproduced on an unmodified kernel with the uo_pd test of the sctp_ifwdtsn.sh selftest added later in this series; its partial delivery checks pass with this fix. Reproduction and fix done with AI assistance.
--- net/sctp/stream_interleave.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sctp/stream_interleave.c +1 -1
@@ -1255,7 +1255,7 @@ static void sctp_intl_skip(struct sctp_ulpq *ulpq, __u16 sid, __u32 mid,struct sctp_stream *stream = &ulpq->asoc->stream;if (flags &SCTP_FTSN_U_BIT ) { -if (sin->pd_mode_uo &&MID_lt (sin->mid_uo, mid)) { +if (sin->pd_mode_uo && !MID_lt (mid, sin->mid_uo)) { sin->pd_mode_uo =0 ;sctp_intl_stream_abort_pd (ulpq, sid, mid,0x1 ,GFP_ATOMIC );
Signature · 1 line
2.34.1
PATCH v2 2/4 sctp: report the partially delivered MID in PARTIAL_DELIVERY_ABORTED
In reply to Tim BuddingWhen an I-FORWARD-TSN skips the message being partially delivered on a stream, sctp_intl_skip() passes the MID from the I-FORWARD-TSN to the PARTIAL_DELIVERY_ABORTED notification as pdapi_seq. That MID is the highest one skipped on the stream, so when more than one message is skipped, the notification names a later message instead of the one whose partial delivery was aborted.
Report the MID being partially delivered, sin->mid_uo or sin->mid, instead.
Reproduced on an unmodified kernel with the pdapi and pdapi_uo tests of the sctp_ifwdtsn.sh selftest added later in this series, which pass with this fix. Reproduction and fix done with AI assistance.
--- net/sctp/stream_interleave.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/sctp/stream_interleave.c +2 -2
@@ -1257,7 +1257,7 @@ static void sctp_intl_skip(struct sctp_ulpq *ulpq, __u16 sid, __u32 mid,if (flags &SCTP_FTSN_U_BIT ) {if (sin->pd_mode_uo && !MID_lt (mid, sin->mid_uo)) { sin->pd_mode_uo =0 ; -sctp_intl_stream_abort_pd (ulpq, sid, mid,0x1 , +sctp_intl_stream_abort_pd (ulpq, sid, sin->mid_uo,0x1 ,GFP_ATOMIC ); }return ;
@@ -1268,7 +1268,7 @@ static void sctp_intl_skip(struct sctp_ulpq *ulpq, __u16 sid, __u32 mid,if (sin->pd_mode) { sin->pd_mode =0 ; -sctp_intl_stream_abort_pd (ulpq, sid, mid,0x0 ,GFP_ATOMIC ); +sctp_intl_stream_abort_pd (ulpq, sid, sin->mid,0x0 ,GFP_ATOMIC ); }sctp_mid_skip (stream, in, sid, mid);
Signature · 1 line
2.34.1
PATCH v2 3/4 sctp: fix I-FORWARD-TSN handling of fragments on other streams
In reply to Tim Buddingsctp_report_iftsn() incorrectly frees queued I-DATA fragments in two cases. First, it drops any queued fragments with TSN less than or equal to the New Cumulative TSN. This prevents reconstruction of messages still being received on other streams and can fully block an ordered stream. Second, it calls sctp_intl_abort_pd() if the New Cumulative TSN equals the highest TSN seen. This check exists for association resets but can be inadvertently triggered by any I-FORWARD-TSN that arrives before data with a higher TSN, causing data loss and, if a partial delivery is in progress on an ordered stream, an aborted association.
Fix the first by freeing fragments from sctp_intl_skip() based on stream, U bit, and MID instead of TSN. Fix the second by moving the call to sctp_intl_abort_pd() from sctp_report_iftsn() to the corresponding reset handlers.
Observed in real use as unexpected message loss. Reproduced on an unmodified kernel with the sctp_ifwdtsn.sh selftest added later in this series, which passes with this fix. Reproduction and fix done with AI assistance.
--- net/sctp/stream.c | 2 ++ net/sctp/stream_interleave.c | 32 +++++++++++--------------------- 2 files changed, 13 insertions(+), 21 deletions(-)
net/sctp/stream.c +2 -0
@@ -749,6 +749,7 @@ struct sctp_chunk *sctp_process_strreset_tsnreq(*/ max_tsn_seen =sctp_tsnmap_get_max_tsn_seen (&asoc->peer.tsn_map); asoc->stream.si->report_ftsn (&asoc->ulpq, max_tsn_seen); + asoc->stream.si->abort_pd (&asoc->ulpq,GFP_ATOMIC );/* G1: Compute an appropriate value for the Receiver's Next TSN -- the * TSN that the peer should use to send the next DATA chunk. The
@@ -1028,6 +1029,7 @@ struct sctp_chunk *sctp_process_strreset_resp(LIST_HEAD (temp); asoc->stream.si->report_ftsn (&asoc->ulpq, mtsn); + asoc->stream.si->abort_pd (&asoc->ulpq,GFP_ATOMIC ); sctp_tsnmap_init(&asoc->peer.tsn_map, SCTP_TSN_MAP_INITIAL,
net/sctp/stream_interleave.c +11 -21
@@ -1203,28 +1203,21 @@ static void sctp_report_fwdtsn(struct sctp_ulpq *ulpq, __u32 ftsn)sctp_ulpq_abort_pd (ulpq,GFP_ATOMIC ); } -static void sctp_intl_reasm_flushtsn (struct sctp_ulpq *ulpq,__u32 ftsn) +static void sctp_intl_reasm_flush_mid (struct sk_buff_head *reasm,__u16 sid, +__u32 mid) {struct sk_buff *pos, *tmp; - skb_queue_walk_safe(&ulpq->reasm, pos, tmp) { + skb_queue_walk_safe(reasm, pos, tmp) {struct sctp_ulpevent *event =sctp_skb2event (pos); -__u32 tsn = event->tsn; -if (TSN_lte (tsn, ftsn)) { -__skb_unlink (pos, &ulpq->reasm); -sctp_ulpevent_free (event); - } - } - - skb_queue_walk_safe(&ulpq->reasm_uo, pos, tmp) { -struct sctp_ulpevent *event =sctp_skb2event (pos); -__u32 tsn = event->tsn; +if (event->stream < sid) +continue ; +if (event->stream > sid ||MID_lt (mid, event->mid)) +break ; -if (TSN_lte (tsn, ftsn)) { -__skb_unlink (pos, &ulpq->reasm_uo); -sctp_ulpevent_free (event); - } +__skb_unlink (pos, reasm); +sctp_ulpevent_free (event); } }
@@ -1232,11 +1225,6 @@ static void sctp_report_iftsn(struct sctp_ulpq *ulpq, __u32 ftsn) {/* Move the Cumulattive TSN Ack ahead. */ sctp_tsnmap_skip (&ulpq->asoc->peer.tsn_map, ftsn); -/* purge the fragmentation queue */ -sctp_intl_reasm_flushtsn (ulpq, ftsn); -/* abort only when it's for all data */ -if (ftsn ==sctp_tsnmap_get_max_tsn_seen (&ulpq->asoc->peer.tsn_map)) -sctp_intl_abort_pd (ulpq,GFP_ATOMIC ); }static void sctp_handle_fwdtsn (struct sctp_ulpq *ulpq,struct sctp_chunk *chunk)
@@ -1260,6 +1248,7 @@ static void sctp_intl_skip(struct sctp_ulpq *ulpq, __u16 sid, __u32 mid,sctp_intl_stream_abort_pd (ulpq, sid, sin->mid_uo,0x1 ,GFP_ATOMIC ); } +sctp_intl_reasm_flush_mid (&ulpq->reasm_uo, sid, mid);return ; }
@@ -1271,6 +1260,7 @@ static void sctp_intl_skip(struct sctp_ulpq *ulpq, __u16 sid, __u32 mid,sctp_intl_stream_abort_pd (ulpq, sid, sin->mid,0x0 ,GFP_ATOMIC ); } +sctp_intl_reasm_flush_mid (&ulpq->reasm, sid, mid);sctp_mid_skip (stream, in, sid, mid);sctp_intl_reap_ordered (ulpq, sid);
Signature · 1 line
2.34.1
PATCH v2 4/4 selftests: net: add SCTP I-FORWARD-TSN tests with message interleaving
In reply to Tim BuddingAdd tests for the receiver side of I-FORWARD-TSN with user message interleaving (RFC 8260) and partial reliability. Most tests interleave a 64KB reliable message on stream 0 with a PR-SCTP message on stream 1 that nft drops, so the sender abandons it, and check that the large message is delivered intact and nothing is left queued. Others cover partial delivery aborts, including the MID reported in PARTIAL_DELIVERY_ABORTED, and SSN/TSN association resets requested by either side.
--- tools/testing/selftests/net/.gitignore | 1 + tools/testing/selftests/net/Makefile | 2 + tools/testing/selftests/net/sctp_ifwdtsn.c | 699 ++++++++++++++++++++ tools/testing/selftests/net/sctp_ifwdtsn.sh | 233 +++++++ 4 files changed, 935 insertions(+) create mode 100644 tools/testing/selftests/net/sctp_ifwdtsn.c create mode 100755 tools/testing/selftests/net/sctp_ifwdtsn.sh
tools/testing/selftests/net/.gitignore +1 -0
@@ -34,6 +34,7 @@ reuseport_bpf_numa reuseport_dualstack rxtimestamp sctp_hello +sctp_ifwdtsn sk_bind_sendto_listen sk_connect_zero_addr sk_so_peek_off
tools/testing/selftests/net/Makefile +2 -0
@@ -90,6 +90,7 @@ TEST_PROGS := \ run_afpackettests \ run_netsocktests \ rxtimestamp.sh \ + sctp_ifwdtsn.sh \ sctp_vrf.sh \ skf_net_off.sh \ srv6_encap_lookup_l3vpn_test.sh \
@@ -163,6 +164,7 @@ TEST_GEN_FILES := \ reuseport_addr_any \ rxtimestamp \ sctp_hello \ + sctp_ifwdtsn \ skf_net_off \ so_netns_cookie \ so_rcv_listener \
tools/testing/selftests/net/sctp_ifwdtsn.c new file +699 -0
699 lines not on this page · raw message
tools/testing/selftests/net/sctp_ifwdtsn.sh new file +233 -0
233 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 75 lines · Tim Budding
With user message interleaving (RFC 8260), fragments of messages on different streams share the TSN space. When a PR-SCTP message is abandoned, the receiver still frees queued fragments by the I-FORWARD-TSN's New Cumulative TSN, which loses fragments of messages still being received on other streams:
TSN stream MID
0 0 0 B 64KB reliable message on stream 0
...5 0 0 6 1 0 BE PR-SCTP message on stream 1, lost, abandoned 7 0 0...
I-FORWARD-TSN new_cum=6 skip=[sid=1 mid=0]The stream 0 fragments with TSNs 0-5 are freed with the abandoned message, are never retransmitted, and stream 0 stays blocked.
Patch 3 frees fragments by the skip entries instead of by TSN, and no longer treats an I-FORWARD-TSN that reaches the highest TSN seen as a reset. Such an I-FORWARD-TSN is then handled by
sctp_intl_skip()alone, which has two partial delivery bugs of its own: an unordered partial delivery is not aborted when its own message is skipped, andPARTIAL_DELIVERY_ABORTEDreports the highest skipped MID rather than the one being delivered. Patches 1 and 2 fix these first, so the three fixes should be backported together and in order. Patch 4 adds a selftest.Patch 3 has a cost, as discussed on v1 [2]: an unordered fragment of an abandoned message that first arrives after the last I-FORWARD-TSN naming that message is no longer freed by a later, unrelated I-FORWARD-TSN. It keeps its rwnd and receive buffer charge until a later unordered skip on its stream, a reset, or teardown. Dropping such fragments on arrival needs new per-stream state and is left to a follow-up [3].
Changes since v1 [1]:
- Fold "sctp: don't treat an I-FORWARD-TSN as an association reset" into the purge patch, now patch 3, as Xin suggested [3].
- New patch 2, from Sashiko's review of v1 patch 3.
- Move the unordered partial delivery fix first.
- Selftest: addleading_edge_nopd, reset_pending_srv/cli and pdapi/pdapi_uo; wait for conditions rather than fixed times, including all data being acked before the queue check.Tested with the new selftest,
sctp_vrf.shand the lksctp-tools functional tests, also on a kernel with KASAN, lockdep and kmemleak. W=1 and sparse show no new warnings.Initial bug observed in use, root cause identified with AI-assisted code inspection. Related bugs found and fixes implemented with AI assistance. All reviewed and tested by me.
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/CADvbK_du=-oT19kKBKYSjFKYscnQSH1mekRKMXgmLPMXTEH_=w@mail.gmail.com/Tim Budding (4):
sctp: abort unordered partial delivery when its message is skipped
sctp: report the partially delivered MID inPARTIAL_DELIVERY_ABORTED
sctp: fix I-FORWARD-TSN handling of fragments on other streams
selftests: net: add SCTP I-FORWARD-TSN tests with message interleavingnet/sctp/stream.c | 2 + net/sctp/stream_interleave.c | 38 +- tools/testing/selftests/net/.gitignore | 1 + tools/testing/selftests/net/Makefile | 2 + tools/testing/selftests/net/sctp_ifwdtsn.c | 699 ++++++++++++++++++++ tools/testing/selftests/net/sctp_ifwdtsn.sh | 233 +++++++ 6 files changed, 951 insertions(+), 24 deletions(-) create mode 100644 tools/testing/selftests/net/sctp_ifwdtsn.c create mode 100755 tools/testing/selftests/net/sctp_ifwdtsn.sh
Quoted 4 lines
base-commit:
6baae996ecf6a3f57b08ea6f6786e29af9260f51--
2.34.1
Series,
Thanks for the fixes and test case. You may also want to look into the pre-existing issue in:
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261105050225.49292-1-tim.budding%40gmail.com
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Wed, 4 Nov 2026 21:02:21 -0800 you wrote:
With user message interleaving (RFC 8260), fragments of messages on different streams share the TSN space. When a PR-SCTP message is abandoned, the receiver still frees queued fragments by the I-FORWARD-TSN's New Cumulative TSN, which loses fragments of messages still being received on other streams:
TSN stream MID
0 0 0 B 64KB reliable message on stream 0
...
Quoted 7 lines
5 0 0 6 1 0 BE PR-SCTP message on stream 1, lost, abandoned 7 0 0...
I-FORWARD-TSN new_cum=6 skip=[sid=1 mid=0][...]
Here is the summary with links:
- [net,v2,1/4] sctp: abort unordered partial delivery when its message is skipped
https://git.kernel.org/netdev/net/c/05852c8b70f2 - [net,v2,2/4] sctp: report the partially delivered MID in PARTIAL_DELIVERY_ABORTED https://git.kernel.org/netdev/net/c/3097fba86801 - [net,v2,3/4] sctp: fix I-FORWARD-TSN handling of fragments on other streams https://git.kernel.org/netdev/net/c/5b9cfc6491a6 - [net,v2,4/4] selftests: net: add SCTP I-FORWARD-TSN tests with message interleaving https://git.kernel.org/netdev/net/c/ee8568a834ac
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html