git: 0fb9da95f7cb - stable/13 - pipe: keep uio_iovcnt consistent

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Sun, 11 Aug 2024 23:04:21 UTC
The branch stable/13 has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=0fb9da95f7cb1730fdf4308f9a12ff8a80c28c87

commit 0fb9da95f7cb1730fdf4308f9a12ff8a80c28c87
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2024-07-17 14:33:53 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2024-08-11 23:03:42 +0000

    pipe: keep uio_iovcnt consistent
    
    In pipe_build_write_buffer we increment uio_iov but did not update
    uio_iovcnt.  This would not cause an OOB read (thanks to to uio_resid)
    but is inconsistent and could be an issue if other code changes are made
    in the future.
    
    Reported by:    Synacktiv
    Reviewed by:    jhb, markj, brooks
    Sponsored by:   The Alpha-Omega Project
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D45999
    
    (cherry picked from commit d8ff42e816848a0d4a427755b46b8560cb86ebc8)
    (cherry picked from commit cbbc8d67301c650dd683566d44ff554993556224)
---
 sys/kern/sys_pipe.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c
index 19f5f07d7523..dd1fd9b6d2a9 100644
--- a/sys/kern/sys_pipe.c
+++ b/sys/kern/sys_pipe.c
@@ -901,8 +901,10 @@ pipe_build_write_buffer(struct pipe *wpipe, struct uio *uio)
 
 	uio->uio_iov->iov_len -= size;
 	uio->uio_iov->iov_base = (char *)uio->uio_iov->iov_base + size;
-	if (uio->uio_iov->iov_len == 0)
+	if (uio->uio_iov->iov_len == 0) {
 		uio->uio_iov++;
+		uio->uio_iovcnt--;
+	}
 	uio->uio_resid -= size;
 	uio->uio_offset += size;
 	return (0);