From nobody Thu Aug 01 20:58:24 2024 X-Original-To: dev-commits-src-all@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 4WZhBm68Zgz5RRpB; Thu, 01 Aug 2024 20:58:24 +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 4WZhBm5Yg1z4P6W; Thu, 1 Aug 2024 20:58:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722545904; 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=x7p8Fr/tx5A1PLkjBSMHaZIFbxoVoQGoxwTQaCWh/Z0=; b=ZOF8Qr9lfN1ixTVmzGciHwe3PTVaWGGYyUK4pvaGx5OnmaXd6ctZjyS8R91z9Xczn6GI7j ieiweJ8FOjyrH4i3SSn5wVueV242LudOppXM4N0IyS8+u4f80S2ihaCN7AONDT2AjoWEnx ZNkJR4Umkw24m8FxWRLwhQc3sj98QQSrjYaY3COtI+e8XE6AT2fUK1NyT6PsIdCEyORGVY dh/CyiGJ6y0Rgbgt37liP5gX5DarSqOe0yba6WIfK3a6cFeWswzUrN7F5tduy1TQKWJIKs 3ipV9/u+RpkUEI85We45GTrB5ldwZF+7O17vQeDdup1kBrE/IwieFpMGWIY2Aw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722545904; a=rsa-sha256; cv=none; b=h321XdX1A7s2Jp/lnyX+25T8xfHBb+Ond/uof6b8Ac3VPYpdizUjRvleakHayGYerlijl3 LVJcXRiw6vpRUUpivbkFEwsMUAqwM3eWoHgbb55ONB6sm1yndSyz4gbYzn7M2Uzbf6TvUW U3mE1/PXhs7os/2yN4OZ6fSYU7Y3wpoi18Y47ExYKRvwgj20CnKOYC6hMCZyiY+IQkvTXW rHssUf/Det9bD6npkvtbq56CTdjWpEhj1PN0cJYQmgATzsS09GwEgYvuzS5LyKrRDD292E AG9Z2JQwjOQmiI0I2cnToO2xVYasgW+jPzz/BeB4hQt6bmfGf1tBnh/y8hQQmw== 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=1722545904; 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=x7p8Fr/tx5A1PLkjBSMHaZIFbxoVoQGoxwTQaCWh/Z0=; b=UmTFBtYQUG3AL/vZKx+uX6iB/2HNc5fxJYSQlpZbP7EqbbB2jJ6TpFqhLnbTMCJ06CU7A2 QmNCCXFJ926VDfyVl7S1MSttc1jpqF6RUNzJ8IJT/1eKWmI2D7oG+/MmyMYASgnTYhGNBl Zzmymmpg5JDvjhwOrDAmON2F1Yrdf8OyPKWjpynYvtSHjeC67nhHjiWkaHLurS5b+OwOZz 2YrYyCDEslaL0kvMbRkSlJNQ3aFjYmpeLDJX/2OJyJo99AX7ffmkmslefMnDRTxlGPOFEH CK9+YAKDX6Eq2ATBZzpACSJNK3zheQGGQfwGMJUSSRMl9Lfq7IXTLN6SJ/fotg== 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 4WZhBm55qhz10m2; Thu, 1 Aug 2024 20:58:24 +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 471KwOn3072570; Thu, 1 Aug 2024 20:58:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 471KwO7N072568; Thu, 1 Aug 2024 20:58:24 GMT (envelope-from git) Date: Thu, 1 Aug 2024 20:58:24 GMT Message-Id: <202408012058.471KwO7N072568@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: 27f782e804a0 - stable/13 - sctp: fix sctp_sendall() when an mbuf chain is provided List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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: 27f782e804a00e15e40e28efea6aa88450838e13 Auto-Submitted: auto-generated The branch stable/13 has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=27f782e804a00e15e40e28efea6aa88450838e13 commit 27f782e804a00e15e40e28efea6aa88450838e13 Author: Michael Tuexen AuthorDate: 2024-05-08 21:41:17 +0000 Commit: Michael Tuexen CommitDate: 2024-08-01 20:57:54 +0000 sctp: fix sctp_sendall() when an mbuf chain is provided In this case uio is NULL, which needs to be checked and m must be copied into the sctp_copy_all structure. Reported by: Coverity Scan CID: 1400449 (cherry picked from commit e187fa56904712cb4dac9e14c81c88821582aeb4) --- sys/netinet/sctp_output.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/sys/netinet/sctp_output.c b/sys/netinet/sctp_output.c index 13a9a65da9eb..e719a5706f3b 100644 --- a/sys/netinet/sctp_output.c +++ b/sys/netinet/sctp_output.c @@ -6841,10 +6841,20 @@ static int sctp_sendall(struct sctp_inpcb *inp, struct uio *uio, struct mbuf *m, struct sctp_nonpad_sndrcvinfo *srcv) { - int ret; struct sctp_copy_all *ca; + struct mbuf *mat; + ssize_t sndlen; + int ret; - if (uio->uio_resid > (ssize_t)SCTP_BASE_SYSCTL(sctp_sendall_limit)) { + if (uio != NULL) { + sndlen = uio->uio_resid; + } else { + sndlen = 0; + for (mat = m; mat; mat = SCTP_BUF_NEXT(mat)) { + sndlen += SCTP_BUF_LEN(mat); + } + } + if (sndlen > (ssize_t)SCTP_BASE_SYSCTL(sctp_sendall_limit)) { /* You must not be larger than the limit! */ return (EMSGSIZE); } @@ -6856,12 +6866,10 @@ sctp_sendall(struct sctp_inpcb *inp, struct uio *uio, struct mbuf *m, return (ENOMEM); } memset(ca, 0, sizeof(struct sctp_copy_all)); - ca->inp = inp; if (srcv != NULL) { memcpy(&ca->sndrcv, srcv, sizeof(struct sctp_nonpad_sndrcvinfo)); } - /* Serialize. */ SCTP_INP_WLOCK(inp); if ((inp->sctp_flags & SCTP_PCB_FLAGS_SND_ITERATOR_UP) != 0) { @@ -6872,15 +6880,14 @@ sctp_sendall(struct sctp_inpcb *inp, struct uio *uio, struct mbuf *m, } inp->sctp_flags |= SCTP_PCB_FLAGS_SND_ITERATOR_UP; SCTP_INP_WUNLOCK(inp); - /* * take off the sendall flag, it would be bad if we failed to do * this :-0 */ ca->sndrcv.sinfo_flags &= ~SCTP_SENDALL; /* get length and mbuf chain */ - if (uio) { - ca->sndlen = uio->uio_resid; + ca->sndlen = sndlen; + if (uio != NULL) { ca->m = sctp_copy_out_all(uio, ca->sndlen); if (ca->m == NULL) { SCTP_FREE(ca, SCTP_M_COPYAL); @@ -6892,20 +6899,14 @@ sctp_sendall(struct sctp_inpcb *inp, struct uio *uio, struct mbuf *m, return (ENOMEM); } } else { - /* Gather the length of the send */ - struct mbuf *mat; - - ca->sndlen = 0; - for (mat = m; mat; mat = SCTP_BUF_NEXT(mat)) { - ca->sndlen += SCTP_BUF_LEN(mat); - } + ca->m = m; } ret = sctp_initiate_iterator(NULL, sctp_sendall_iterator, NULL, SCTP_PCB_ANY_FLAGS, SCTP_PCB_ANY_FEATURES, SCTP_ASOC_ANY_STATE, (void *)ca, 0, sctp_sendall_completes, inp, 1); - if (ret) { + if (ret != 0) { SCTP_INP_WLOCK(inp); inp->sctp_flags &= ~SCTP_PCB_FLAGS_SND_ITERATOR_UP; SCTP_INP_WUNLOCK(inp);