From nobody Sat Aug 03 22:23:12 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 4Wbxzh4tMPz5RRnM; Sat, 03 Aug 2024 22:23:12 +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 4Wbxzh49RWz4F31; Sat, 3 Aug 2024 22:23:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722723792; 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=NoEWmg0BHvrDCo5r7YeorqYLXkcC4U+lmpXAK0xegQY=; b=lCa3wwtpkZS7Rd2ZR06Gw58YDFc3x8JdJdEtBgcEUB/0gqY2cXohPumMpMGhLLLepwnV6w 8szs9ncJ6U9R2jIQh9KgYfDhqirFmQxrbg9OMzTL2qqEGpO1SFixL82JEirTXZB1Ua3qcz CyBm9eJBYFvq7SCOGLvBAJ/Kr8jlVJ8v5AXEZhFRkxiHzIPhSWbivdJmGmDwy849y5SqxQ QrnN1mdjhbcblKER1B/UUIcJ+h4tEXMWZGUxYD0YfxWfIXgFnVQGIXjgRjzK5TN237T+pK wTQblgneadMe6eXnYpqQsaPlAJzp61FXD9nAwvKA6adICzyrkwhm0qgQwPhCcg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722723792; a=rsa-sha256; cv=none; b=n668C/QwmULVHJ2hduojJ3Il+D75qQHOeH1hyYyHU6HeSvvU5DhmbwkZa/3cqk3zoFnJwX YOPOJ9upq/cmGHFWFIO9woW1FNbQbkMPkRaS/BOpnM/Oyk+W2iZPjOryA4frOGLhVOJren 33oj9M2h/w5G7633oA7cI1eW7/CBwk8WneB9MpuSKe3a3li/VHr6l0EKBK3lR5HU3yAegj COiER1eOXRgUGXxpXs3DVfiGLAfqE2FyFOrJQfKMHKwz6odlYoJltolv2stf4Xf4eQYJhi lwes3VLmmvLAqfItGV1dcSu3fY2zfnScIqokcbVbFJ41AD9D5r38gmqKIVfgkA== 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=1722723792; 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=NoEWmg0BHvrDCo5r7YeorqYLXkcC4U+lmpXAK0xegQY=; b=IOAG7d5kccKTpxVF7EfEr13WGwDpvZey7uF3WI2ohZUNNvnTUNtFEJcUneK4LBIOybwcM9 YgqQ2Iv6eZ2G3HYsQAfy13X+mjcjx8IY7ncah/fG24XXZGsKE/yBzNuZzeQ1yN+dK6E696 uAX0S/qK19SPNodfG1cP1/iU91aa3YxwFTdsxfA2i8VpFCa8W3Z8eUaZBrWB0rx8x+K54y wGvmClbt/2SccQ9lDjRQrXbZ965y38BIvVbsz/NB5031oxW0q003DVANwfF8s9nGwmaUz1 CmJGMwmgffQ3ORQivU1rpKBnHWU5DKnGa4b/qC+4wkqIFqMf4BNb0yPacZxFMg== 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 4Wbxzh3mw5zV87; Sat, 3 Aug 2024 22:23:12 +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 473MNCe6025471; Sat, 3 Aug 2024 22:23:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 473MNC0h025468; Sat, 3 Aug 2024 22:23:12 GMT (envelope-from git) Date: Sat, 3 Aug 2024 22:23:12 GMT Message-Id: <202408032223.473MNC0h025468@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: 1776db67c3d1 - stable/14 - 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/14 X-Git-Reftype: branch X-Git-Commit: 1776db67c3d1f7e207ac06956af2a9983b67f201 Auto-Submitted: auto-generated The branch stable/14 has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=1776db67c3d1f7e207ac06956af2a9983b67f201 commit 1776db67c3d1f7e207ac06956af2a9983b67f201 Author: Michael Tuexen AuthorDate: 2024-05-08 21:41:17 +0000 Commit: Michael Tuexen CommitDate: 2024-08-03 22:22:43 +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 e0106831f06a..c146bda95c7c 100644 --- a/sys/netinet/sctp_output.c +++ b/sys/netinet/sctp_output.c @@ -6911,10 +6911,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); } @@ -6926,12 +6936,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) { @@ -6942,15 +6950,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); @@ -6962,20 +6969,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);