git: 932fc0590154 - stable/13 - sctp: provide a specific stream scheduler function for FCFS

From: Michael Tuexen <tuexen_at_FreeBSD.org>
Date: Tue, 22 Feb 2022 22:58:31 UTC
The branch stable/13 has been updated by tuexen:

URL: https://cgit.FreeBSD.org/src/commit/?id=932fc0590154d805699ad676f35a6a1202555f01

commit 932fc0590154d805699ad676f35a6a1202555f01
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2021-09-29 00:08:37 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2022-02-22 22:58:10 +0000

    sctp: provide a specific stream scheduler function for FCFS
    
    A KASSERT in the genric routine does not apply and triggers
    incorrectly.
    
    Reported by:    syzbot+8435af157238c6a11430@syzkaller.appspotmail.com
    
    (cherry picked from commit 28ea9470782d4d01004b801c3ec7d74761fcf611)
---
 sys/netinet/sctp_ss_functions.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/sys/netinet/sctp_ss_functions.c b/sys/netinet/sctp_ss_functions.c
index fe4b96cf00ab..5293c0fee742 100644
--- a/sys/netinet/sctp_ss_functions.c
+++ b/sys/netinet/sctp_ss_functions.c
@@ -863,6 +863,30 @@ default_again:
 	return (strq);
 }
 
+static void
+sctp_ss_fcfs_scheduled(struct sctp_tcb *stcb,
+    struct sctp_nets *net SCTP_UNUSED,
+    struct sctp_association *asoc,
+    struct sctp_stream_out *strq,
+    int moved_how_much SCTP_UNUSED)
+{
+	struct sctp_stream_queue_pending *sp;
+
+	KASSERT(strq != NULL, ("strq is NULL"));
+	asoc->ss_data.last_out_stream = strq;
+	if (asoc->idata_supported == 0) {
+		sp = TAILQ_FIRST(&strq->outqueue);
+		if ((sp != NULL) && (sp->some_taken == 1)) {
+			asoc->ss_data.locked_on_sending = strq;
+		} else {
+			asoc->ss_data.locked_on_sending = NULL;
+		}
+	} else {
+		asoc->ss_data.locked_on_sending = NULL;
+	}
+	return;
+}
+
 const struct sctp_ss_functions sctp_ss_functions[] = {
 /* SCTP_SS_DEFAULT */
 	{
@@ -948,7 +972,7 @@ const struct sctp_ss_functions sctp_ss_functions[] = {
 		.sctp_ss_is_empty = sctp_ss_fcfs_is_empty,
 		.sctp_ss_remove_from_stream = sctp_ss_fcfs_remove,
 		.sctp_ss_select_stream = sctp_ss_fcfs_select,
-		.sctp_ss_scheduled = sctp_ss_default_scheduled,
+		.sctp_ss_scheduled = sctp_ss_fcfs_scheduled,
 		.sctp_ss_packet_done = sctp_ss_default_packet_done,
 		.sctp_ss_get_value = sctp_ss_default_get_value,
 		.sctp_ss_set_value = sctp_ss_default_set_value,