From nobody Thu May 09 14:49: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 4VZw0J1c2Cz5Jr0S; Thu, 09 May 2024 14:49: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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VZw0J14WJz47xF; Thu, 9 May 2024 14:49:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1715266192; 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=z+8aG9FR/IgumZNkTF2EvVsr97uY3gCYX/hACH0JqAU=; b=vMc832be0fPScxEdrGbWfDgHRvPXffj88NgnX5ICd+mR3lyDRzWuA4by3EN32y0xv+d0Pe NOti4kmi37lL5mrIILXyfk154Qf/fnev2nmmkwUUpHLe5vl+n+GAUQi6VboBOdEqspf2pD 3xl4kK53Qt4rA2F6ykWe07/ZVvv3PuSmofC64PPtQmPO9ALlD7h/TMPhCCCGlFy9plnfCv UQykx66cpcp8d/qVHyKc0Q5QQ9PddLBxsCdI0Q+wT1C6lSlh3+AOLGjbpWshzpfvJYlmN2 YAqQgmaoxVtCqmFx4f2XbvjyDUuATSx8dJ3bprR4hpBEzoHiSskeRUMcFijd+g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1715266192; a=rsa-sha256; cv=none; b=IEBouyZB8NfKH/lKAHDgexMqFb8rcjsf3C0R4jWCoSr8O0EBgkQqzx+fwp16qkpBvfMwPj 8P7SoebITaoBmq5U1OV4pZtohqMto0TMAsBzcGSMMnT4a5l2VnwutharKnrkEgZlOn6Few M4AneG12Jk6axwROPnXDisYRk8h81mWE+V3CCkWx/ktr+oYLon6OcR+JZ/R9rIg28o8eys 6aNr2956pKHypSf032/Bg+XtUli6L6QRWV7HQGIdlJxAp/0sBypWHcZFsrv9XH1ZhHiUeH JxfwzvR6bzTlWZhb3y/NLy30fyRWcHp9o7pYT6V42LZUR0agFHbN5+WYkLTH6Q== 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=1715266192; 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=z+8aG9FR/IgumZNkTF2EvVsr97uY3gCYX/hACH0JqAU=; b=YT6vg+ZE5Kkvs8I5r5FDCIrUwCEVhe1D9EZhjyWrgu0LkLP+3Bj96kETZbAtuuYRJZbpI9 rVatz6HQTG0OgmRR3NY+cksCiMAIYAmUT8tqEgLOXrRMyBPbzVmuw/iNFo9GFm/diVaOv4 FaQonaFrPEDlb3yhDOvwNUxDWtlrgGbRB/YlfyA4g3hikadYCazhpE6JVrdJI3ICZaOjMg Jb2ndJrTLs+qlVR4tZXaG+wbFo90C3guvyKgldRHSGjE+rfbT8QkRx3Oy3j7bJhIhKLv9P 9p7T/piFLKhB10iJZlUI420rGIR+Jyyd94WepQ07d2MlChxMxMexewxrsPfL2Q== 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 4VZw0J0Md8z1CGD; Thu, 9 May 2024 14:49:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 449EnpEg085236; Thu, 9 May 2024 14:49:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 449EnplH085233; Thu, 9 May 2024 14:49:51 GMT (envelope-from git) Date: Thu, 9 May 2024 14:49:51 GMT Message-Id: <202405091449.449EnplH085233@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: e187fa569047 - main - sctp: fix sctp_sendall() when an mbuf chain is provided 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: e187fa56904712cb4dac9e14c81c88821582aeb4 Auto-Submitted: auto-generated The branch main has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=e187fa56904712cb4dac9e14c81c88821582aeb4 commit e187fa56904712cb4dac9e14c81c88821582aeb4 Author: Michael Tuexen AuthorDate: 2024-05-08 21:41:17 +0000 Commit: Michael Tuexen CommitDate: 2024-05-08 21:45:55 +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 MFC after: 3 days --- 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);