From nobody Sat Aug 03 11:36:51 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Wbgdw2VBtz5SHgH; Sat, 03 Aug 2024 11:36:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Wbgdw1r8vz3ymH; Sat, 3 Aug 2024 11:36:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722685012; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Mw6QIi420GqEapR0sn5MvG7P4nzf7yKT8L4WMmWW/O0=; b=jus6rzPTLduS0YtqA7SPrJhu0MJWCsLQ+zDrjrH1l/ZM7jdlNkneXZI/yqilC/uR/G72Jp EViSLDZ7o82Q0rapCGt+Wvbt4nKwOraR31ACi9YGNVGRPpHBxXZqRvWfWeiFgGvC06OKzH cXh4KTSamHuQZLfdCgHi07GCa78xDpWwgRsMt+MoDxr5yS6nSU8noImrpC2sqoj2rSkTvz WAI/9N/dMOnOYUBLE5Q6pJxL0JoQRzWIEKJyVgxIhJ2x677DG4kfXaVnXS+ehEhD0nfWnR rRO63uYvstIKnfxpORmqHdW/QPWO2WmWcYpIt5bOw7TEFfe5zxk5sxDiA4KHYQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722685012; a=rsa-sha256; cv=none; b=o7BjRcuZhC7db7dWu8p3YIW2lgFPzZqAVu1NYWkp6Z2GCtJuMHhQ/oys/Q1a92XGswYACG R3h9Xbr3+tOgAGne0LR1pTDyYjPDLVlkGTouFCUqJ8+0yhH6zAjZlN9mXxRchO+xMfwpr4 3WTDLJvHrZg2+yv4OxxkrrGJh6Uiu8pWSKaWsAErpAdMPXD0wgHg4wRobxJWpXNOwc55Rt oZERHavTDiTfl0kkR7NnRvJrwEfyjtVWMD21PE3cq/+8FMdl1UrgUr+3Bzgp/DBXkH6CMt oXwX+oPJr/UqRjk6wiXEBCjDDstFbtOos675Jk1AL3HYFvwn1xV9+s60CMtIPw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722685012; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Mw6QIi420GqEapR0sn5MvG7P4nzf7yKT8L4WMmWW/O0=; b=F7MzrT/e/Sqx/+lUhON4mgWSeHhIybC57nUj42KH6NYGSVD2/nJ+jozxNFIis/kqwvSlKo 7/cQRUt9G8O6ShaEoWeFULcatGbFRY0OaqLebWX2i/aSjj8wl7rQV3SVQDOIfUJ2e7Mnn6 EJvOe3h87zg6hm9AtvAvmcX808UnNVe6YvNp8jmWamePGKdMSUEOc8jEjWeolXxkhaU2ND TKzB1RaoLs49Jw2XTXvyOwubgbiQ93sHSnW2L1We6GlCqRepAMiAZNUFvOPgr25tW+JTip s/tCSfC41/0oeShloueIlm2iEzdkcOMicV5jm7e+/jbo62DpiIqIDADmkKLyJA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Wbgdw0v8mz19HW; Sat, 3 Aug 2024 11:36:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 473Bap5X010473; Sat, 3 Aug 2024 11:36:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 473BapGb010470; Sat, 3 Aug 2024 11:36:51 GMT (envelope-from git) Date: Sat, 3 Aug 2024 11:36:51 GMT Message-Id: <202408031136.473BapGb010470@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Michael Tuexen Subject: git: 101a0f09e8ba - main - sctp: improve input validation for data chunks List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tuexen X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 101a0f09e8baf8293e1eeb591de18caf15e49e00 Auto-Submitted: auto-generated The branch main has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=101a0f09e8baf8293e1eeb591de18caf15e49e00 commit 101a0f09e8baf8293e1eeb591de18caf15e49e00 Author: Michael Tuexen AuthorDate: 2024-08-03 11:27:18 +0000 Commit: Michael Tuexen CommitDate: 2024-08-03 11:27:18 +0000 sctp: improve input validation for data chunks fsn_included should only be considered, if first_frag_seen is true. Also, fix the resetting of the control structure, if stream queues are flushed. This fixes a bug where a legitimate message sequence was incorrectly classified as illegitimate. Thanks to Victor Boivie for reporting the issue on the userland stack. MFC after: 3 days --- sys/netinet/sctp_indata.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/sys/netinet/sctp_indata.c b/sys/netinet/sctp_indata.c index 4c40e0de4326..693de313b970 100644 --- a/sys/netinet/sctp_indata.c +++ b/sys/netinet/sctp_indata.c @@ -746,21 +746,6 @@ sctp_build_readq_entry_from_ctl(struct sctp_queued_to_read *nc, struct sctp_queu nc->do_not_ref_stcb = control->do_not_ref_stcb; } -static void -sctp_reset_a_control(struct sctp_queued_to_read *control, - struct sctp_inpcb *inp, uint32_t tsn) -{ - control->fsn_included = tsn; - if (control->on_read_q) { - /* - * We have to purge it from there, hopefully this will work - * :-) - */ - TAILQ_REMOVE(&inp->read_queue, control, next); - control->on_read_q = 0; - } -} - static int sctp_handle_old_unordered_data(struct sctp_tcb *stcb, struct sctp_association *asoc, @@ -1922,7 +1907,8 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, SCTP_SNPRINTF(msg, sizeof(msg), "Duplicate MID=%8.8x detected.", mid); goto err_out; } else { - if ((tsn == control->fsn_included + 1) && + if ((control->first_frag_seen) && + (tsn == control->fsn_included + 1) && (control->end_added == 0)) { SCTP_SNPRINTF(msg, sizeof(msg), "Illegal message sequence, missing end for MID: %8.8x", @@ -5430,12 +5416,25 @@ sctp_flush_reassm_for_str_seq(struct sctp_tcb *stcb, sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED); } if (!TAILQ_EMPTY(&control->reasm)) { - /* This has to be old data, unordered */ + KASSERT(!asoc->idata_supported, + ("Reassembly queue not empty for I-DATA")); + KASSERT(!ordered, + ("Reassembly queue not empty for ordered data")); if (control->data) { sctp_m_freem(control->data); control->data = NULL; } - sctp_reset_a_control(control, stcb->sctp_ep, cumtsn); + control->fsn_included = 0xffffffff; + control->first_frag_seen = 0; + control->last_frag_seen = 0; + if (control->on_read_q) { + /* + * We have to purge it from there, hopefully this + * will work :-) + */ + TAILQ_REMOVE(&stcb->sctp_ep->read_queue, control, next); + control->on_read_q = 0; + } chk = TAILQ_FIRST(&control->reasm); if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { TAILQ_REMOVE(&control->reasm, chk, sctp_next);