From nobody Tue Aug 06 21:38:40 2024 X-Original-To: dev-commits-src-branches@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 4Wdmrx17QRz5Sj4v; Tue, 06 Aug 2024 21:38:41 +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 4Wdmrx0ZrGz4bxs; Tue, 6 Aug 2024 21:38:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722980321; 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=MRK7KelSXEQmxP7QtbmlorcBx6l7SJU4+D07qjQ8MYY=; b=XSAP0AovHEOR9ejdIiw8DvNiVmihouIOfVY+69IcRjXkmVl/tBhZ+Zo0+o4wTxaMmGTxo6 WkHok4WjSHccQknDUI/oGQ6gB321ks5RHmSnJldstPVPZpdWWtLJhE2AFTZitky7SMrqFh AdX06QK7mD+7LF/jaJE2oCzhi8dUcPRVyeCUO7d72BJyoKd74eEklT+UIKAB8AxVTdmrvU M2DBtNMWJBfbUPbRtEwCfkYjHfH62mdp9zlZKQcZmVrs8RJyFH/vkuVVNv2fVK+VWAA3Nl lfVVMU6qKPIqJpcrHmJCZ2eUz+3l8nmQAOTNS/gdO+ZOlJLGr+lyTD1j9Knw8w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722980321; a=rsa-sha256; cv=none; b=FM1i6wM+FUyuAKmXAdAf2QzArUL7PpGFlfhT5Mibo8FxQLDy7gOy3LJFPqPTt0ZcO9dHDs 2FRrG6RrrvEQMP1VwQzFpJZNUedSopJtNO1rsWp4wKZFXlYPNL0zmDf179jdCNeLUiy2Ju cei7mL19nmGx7dGZ9kFfSDN+2BYv86hT7IkYsRhAXqs6bqk2nOuEzCei1qqjAUOpK+zUvI 99uFsdQM9bQuIu7K2riq67aOrXxpZSY+X7U4cmdMnWhnxoY2dA2SS1+NgkM4inVG43h9zM QHvEmMiJvpo5LjfKGgAhKv+rha8P8c6M+ZZJH44LNnJ/cwi1DgwbHB26n432xQ== 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=1722980321; 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=MRK7KelSXEQmxP7QtbmlorcBx6l7SJU4+D07qjQ8MYY=; b=QnMdQEEnuo/65TPU+168N/Rw3fbo7TRYjDnoXg/eA8fOjd6SmZjvhNfpb9hkA0pElZUsHC glqrSkbLDcq8B9EW1n2QQLawnutkZ8mWRIb277zTaoXjf+CUYWmINXFTYG9ac++5OP//wE xFE3pyXArZQx9p2YFAel9yL5E4bCkAgf5N6HJxgUVD3MBse5OS/c3AnEm3yKyg4prwASuM cdTyhyC864hH1yWMGrxuG91Y66SCskgStE8pL5VBnGrlrx5wy/sJKbTe/R9GvR57/ZDCzV nrrjopmuVBN8xQ5dl++78VbgPZ4IevnvYmrp7BiKYP3uE+LuBinbvJVGx93rGQ== 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 4Wdmrx09yBzNG1; Tue, 6 Aug 2024 21:38:41 +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 476Lcetp085000; Tue, 6 Aug 2024 21:38:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 476LceaS084997; Tue, 6 Aug 2024 21:38:40 GMT (envelope-from git) Date: Tue, 6 Aug 2024 21:38:40 GMT Message-Id: <202408062138.476LceaS084997@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Michael Tuexen Subject: git: 18f4b705734e - stable/13 - sctp: improve input validation for data chunks List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 18f4b705734e1c76bac441ffe86cb8fbb131a153 Auto-Submitted: auto-generated The branch stable/13 has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=18f4b705734e1c76bac441ffe86cb8fbb131a153 commit 18f4b705734e1c76bac441ffe86cb8fbb131a153 Author: Michael Tuexen AuthorDate: 2024-08-03 11:27:18 +0000 Commit: Michael Tuexen CommitDate: 2024-08-06 21:38:16 +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. (cherry picked from commit 101a0f09e8baf8293e1eeb591de18caf15e49e00) --- 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);