From nobody Tue Oct 17 13:37:08 2023 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 4S8w503Z2Cz4xWnx; Tue, 17 Oct 2023 13:37:08 +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 4S8w5035F3z3Fww; Tue, 17 Oct 2023 13:37:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697549828; 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=Rg8W7BP5pvV7t00mCCCmgz3sdPzc5M9D6J+djyCRDyc=; b=YD00NUPkayxyUAShJRAP6MkQdCU/RxQKHjbGzUhmY1k0K0LaAS0m5bhhYu1jsubuFWbJ2H Uji+/FlHKzkKWnxV0fPUGTROV7dC2V+JFJ+Zs6YUMQWQEx/+9h6Jr90mdKsX4avcvPNIh5 70aH4qtTGM6mtTxNw2EHcDqndZDoXKqpBEA3Xgv/C+l8PMBuU5g63d0AzMT+Wc5Ii3UWIq ZT8GD+/mEsDAY/OYOmEP4PGCuqdEOfVWLWXUrBWI/MewNNwbu5/DMLOm5DBm3ByXyQ4LPS nil/Jmu5RhdU5wyb6snhs3vZGGpGjuLZgglYezYAZCnKIYsv2R+QtlxeO+VpjQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697549828; a=rsa-sha256; cv=none; b=svy67dimeFAgEHDjcOAJJIIaMbkhwNaGjD+bvQLen8IQShxZN0Ff8pP6GeLyCUNVorPlHA 64EPawg+y3YOx4+g7E034e6XH2Qy0vTShR1rXe8ogCgf7rGRUUV7lWokBe8pM0Aun5fECk DQIcP5Yl+6NMYQTQ70lZlh1udZG9pAxwIyQyS4AT86TmmkBLxw8m3jNpMI+mhttQgQ8vOV 2Wd4ukfH/B/wxOod2mtDPz9t086j7ffW+IhvKZBkzP94dE7j3Upf0NvaRtj+ZLTaWYeACz GpDr29781AuRfbfEwYpXTMw5XexsNbBuNzWcn5gwoVksurcbyIjEMPutKeyfPQ== 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=1697549828; 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=Rg8W7BP5pvV7t00mCCCmgz3sdPzc5M9D6J+djyCRDyc=; b=NRNr9fkB+PMm3/XVTpueyJxg1vTrVO+3NTgxG7NZmdrNG7qWTiGmFAkFIwg5JClurDKvvE K5X1EpTywUhfR9ClSoLRtiDNJtpeUazmxq3+CKdf/iFZBaXWgkybAcbYjOUST4XtIdMvcC 1+oGq3fmyWA9qsCYSlZG8cvPCGccNOM19pA6bHA0GdEhK9/ITkL1zABea71QhQOC6dMAyK 3RblAyo8m/o/nSakR4bGxPvplaO3mYDif5TmMpsKmhQnSCnltQES+UzbS4TV7uOl9p0Nsx 8YzBoe2OEs4yTG66EFbg7jBBmwURHTurJkjj5vyHFi+tGhsQ9fZ2nTJDf8mvOg== 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 4S8w5029B5z9hq; Tue, 17 Oct 2023 13:37:08 +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 39HDb8m2095822; Tue, 17 Oct 2023 13:37:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39HDb8oW095819; Tue, 17 Oct 2023 13:37:08 GMT (envelope-from git) Date: Tue, 17 Oct 2023 13:37:08 GMT Message-Id: <202310171337.39HDb8oW095819@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 8fd0ec53deaa - main - uiomove: Add some assertions 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: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8fd0ec53deaad34383d4b344714b74d67105b258 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=8fd0ec53deaad34383d4b344714b74d67105b258 commit 8fd0ec53deaad34383d4b344714b74d67105b258 Author: Mark Johnston AuthorDate: 2023-10-16 20:12:37 +0000 Commit: Mark Johnston CommitDate: 2023-10-17 13:12:19 +0000 uiomove: Add some assertions Make sure that we don't try to copy with a negative resid. Make sure that we don't walk off the end of the iovec array. Reviewed by: kib MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D42098 --- sys/amd64/amd64/uio_machdep.c | 6 ++++++ sys/arm/arm/uio_machdep.c | 6 ++++++ sys/arm64/arm64/uio_machdep.c | 6 ++++++ sys/i386/i386/uio_machdep.c | 6 ++++++ sys/kern/subr_uio.c | 5 +++++ sys/powerpc/powerpc/uio_machdep.c | 5 +++++ sys/riscv/riscv/uio_machdep.c | 6 ++++++ 7 files changed, 40 insertions(+) diff --git a/sys/amd64/amd64/uio_machdep.c b/sys/amd64/amd64/uio_machdep.c index f3e80addc92c..67e14d8e0d12 100644 --- a/sys/amd64/amd64/uio_machdep.c +++ b/sys/amd64/amd64/uio_machdep.c @@ -71,10 +71,16 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio) ("uiomove_fromphys: mode")); KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread, ("uiomove_fromphys proc")); + KASSERT(uio->uio_resid >= 0, + ("%s: uio %p resid underflow", __func__, uio)); + save = td->td_pflags & TDP_DEADLKTREAT; td->td_pflags |= TDP_DEADLKTREAT; mapped = false; while (n > 0 && uio->uio_resid) { + KASSERT(uio->uio_iovcnt > 0, + ("%s: uio %p iovcnt underflow", __func__, uio)); + iov = uio->uio_iov; cnt = iov->iov_len; if (cnt == 0) { diff --git a/sys/arm/arm/uio_machdep.c b/sys/arm/arm/uio_machdep.c index 07531f76217b..18661ebd1652 100644 --- a/sys/arm/arm/uio_machdep.c +++ b/sys/arm/arm/uio_machdep.c @@ -72,9 +72,15 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio) ("uiomove_fromphys: mode")); KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread, ("uiomove_fromphys proc")); + KASSERT(uio->uio_resid >= 0, + ("%s: uio %p resid underflow", __func__, uio)); + save = td->td_pflags & TDP_DEADLKTREAT; td->td_pflags |= TDP_DEADLKTREAT; while (n > 0 && uio->uio_resid) { + KASSERT(uio->uio_iovcnt > 0, + ("%s: uio %p iovcnt underflow", __func__, uio)); + iov = uio->uio_iov; cnt = iov->iov_len; if (cnt == 0) { diff --git a/sys/arm64/arm64/uio_machdep.c b/sys/arm64/arm64/uio_machdep.c index f9e4e7a9547f..4fdcaf74890c 100644 --- a/sys/arm64/arm64/uio_machdep.c +++ b/sys/arm64/arm64/uio_machdep.c @@ -69,10 +69,16 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio) ("uiomove_fromphys: mode")); KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread, ("uiomove_fromphys proc")); + KASSERT(uio->uio_resid >= 0, + ("%s: uio %p resid underflow", __func__, uio)); + save = td->td_pflags & TDP_DEADLKTREAT; td->td_pflags |= TDP_DEADLKTREAT; mapped = false; while (n > 0 && uio->uio_resid) { + KASSERT(uio->uio_iovcnt > 0, + ("%s: uio %p iovcnt underflow", __func__, uio)); + iov = uio->uio_iov; cnt = iov->iov_len; if (cnt == 0) { diff --git a/sys/i386/i386/uio_machdep.c b/sys/i386/i386/uio_machdep.c index 07d71eac5db6..92e067b35bed 100644 --- a/sys/i386/i386/uio_machdep.c +++ b/sys/i386/i386/uio_machdep.c @@ -71,9 +71,15 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio) ("uiomove_fromphys: mode")); KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread, ("uiomove_fromphys proc")); + KASSERT(uio->uio_resid >= 0, + ("%s: uio %p resid underflow", __func__, uio)); + save = td->td_pflags & TDP_DEADLKTREAT; td->td_pflags |= TDP_DEADLKTREAT; while (n > 0 && uio->uio_resid) { + KASSERT(uio->uio_iovcnt > 0, + ("%s: uio %p iovcnt underflow", __func__, uio)); + iov = uio->uio_iov; cnt = iov->iov_len; if (cnt == 0) { diff --git a/sys/kern/subr_uio.c b/sys/kern/subr_uio.c index 21a1f044db54..b0c4a256cd17 100644 --- a/sys/kern/subr_uio.c +++ b/sys/kern/subr_uio.c @@ -216,6 +216,8 @@ uiomove_faultflag(void *cp, int n, struct uio *uio, int nofault) ("uiomove: mode")); KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread, ("uiomove proc")); + KASSERT(uio->uio_resid >= 0, + ("%s: uio %p resid underflow", __func__, uio)); if (uio->uio_segflg == UIO_USERSPACE) { newflags = TDP_DEADLKTREAT; @@ -234,6 +236,9 @@ uiomove_faultflag(void *cp, int n, struct uio *uio, int nofault) } while (n > 0 && uio->uio_resid) { + KASSERT(uio->uio_iovcnt > 0, + ("%s: uio %p iovcnt underflow", __func__, uio)); + iov = uio->uio_iov; cnt = iov->iov_len; if (cnt == 0) { diff --git a/sys/powerpc/powerpc/uio_machdep.c b/sys/powerpc/powerpc/uio_machdep.c index 679139a96e99..5de2dd8b416b 100644 --- a/sys/powerpc/powerpc/uio_machdep.c +++ b/sys/powerpc/powerpc/uio_machdep.c @@ -75,10 +75,15 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio) ("uiomove_fromphys: mode")); KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread, ("uiomove_fromphys proc")); + KASSERT(uio->uio_resid >= 0, + ("%s: uio %p resid underflow", __func__, uio)); save = td->td_pflags & TDP_DEADLKTREAT; td->td_pflags |= TDP_DEADLKTREAT; while (n > 0 && uio->uio_resid) { + KASSERT(uio->uio_iovcnt > 0, + ("%s: uio %p iovcnt underflow", __func__, uio)); + iov = uio->uio_iov; cnt = iov->iov_len; if (cnt == 0) { diff --git a/sys/riscv/riscv/uio_machdep.c b/sys/riscv/riscv/uio_machdep.c index 86a39be12cdb..e2f82974b2e9 100644 --- a/sys/riscv/riscv/uio_machdep.c +++ b/sys/riscv/riscv/uio_machdep.c @@ -69,10 +69,16 @@ uiomove_fromphys(vm_page_t ma[], vm_offset_t offset, int n, struct uio *uio) ("uiomove_fromphys: mode")); KASSERT(uio->uio_segflg != UIO_USERSPACE || uio->uio_td == curthread, ("uiomove_fromphys proc")); + KASSERT(uio->uio_resid >= 0, + ("%s: uio %p resid underflow", __func__, uio)); + save = td->td_pflags & TDP_DEADLKTREAT; td->td_pflags |= TDP_DEADLKTREAT; mapped = false; while (n > 0 && uio->uio_resid) { + KASSERT(uio->uio_iovcnt > 0, + ("%s: uio %p iovcnt underflow", __func__, uio)); + iov = uio->uio_iov; cnt = iov->iov_len; if (cnt == 0) {