From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795618605; b=LihjkgHtKbWDxsmTZVWcIIjw+npJ/93d4MaXZSdDbomIt0EUOiS4/1isP23/Kkn4zKBV fgmeb9pintq/Q+O5Y1EYEYRgIC54GDkMSQEyuAfjgf9K3gR2r7zppN9GnDFECvUGjFkk2 F3IyCAlt1ziL9Dg7XpW4K3LGE4SO6r7kGB6t8bcZ2k2ln8dYEjscV+DiSGk/mHcskuj4l 776YHPAZmzkhJAWiGehlWiejU8hiamuNNrknA1TCmjyIvTmvvxPTkNHMZnJCfIKLra6/o 7XtoR/rUvq2AMVAJkmAE8NjVWI1Z03Il7IPyB9vYuyv8TiHrGaIPkLYhRke0Ra/vRyw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795618605; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=v/5Au3wmejWVdelUl4cNscNy8l5C0YlGHshNzNXcGOY=; b=SSh3nsPB0WVjArQ6PgLItiF8sucLrKSiOTQOWchUwz78xUCj1DsBNhHYJ318JprWeifI RkEiVwaBTemRvzz2/h0Z4s2w0tYl5NB8UGMQ8YorQKmKG0BW17W35kEF6w34BPg+ql+EU PFyzJoaJSjNhi+ItVty07jejbUXdAdK9pBAI6RvdmbN+Vxixu3i4EQB6LsczN962bjoPQ 7911aK4grz1y+vW7OnvtWhx1ah8HTllc/aEMRaqKA53Ri4qsjopQtsh+qxWusIn4r07GS Gy/z09BvRVhfHHB1QqHouMwnwMz1Ka67bGfRczqq7+yFnloE8BiCdglCF3O9aZKRSig== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ivaXz9LG; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59B21606A321; Wed, 25 Nov 2026 14:56:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ivaXz9LG Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C8701F000F0; Wed, 25 Nov 2026 14:56:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795618605; bh=v/5Au3wmejWVdelUl4cNscNy8l5C0YlGHshNzNXcGOY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ivaXz9LGwRLZ+ujxJJmTcVr7hMBollwjynGXnt0Z+dChhjn/9J648Hktkq5dhyC1Q 2tk7FQmLT2OK156tJ6ntiaPxIMPoJIrHcIHDekJp5rQi1gpEeQVpe+513HRxzJGg9y rlQ2+0bYLNyt0TBOs5frL4EWahu0TuQ3ExmqOYIc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Andrea Parri , Jan Kara , "Christian Brauner (Amutable)" , Sasha Levin Subject: [PATCH 7.3 0332/1005] iov_iter: take an unsigned long segment count in import_iovec() Date: Wed, 25 Nov 2026 15:27:50 +0100 Message-ID: <20261125143829.511728041@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125143821.729802100@linuxfoundation.org> References: <20261125143821.729802100@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andrea Parri [ Upstream commit 965e5e451146a19f69523fbcbc73d07e401a3775 ] readv(), writev() and their positional variants, process_vm_readv(), process_vm_writev(), vmsplice(), process_madvise(), vectored aio and the btrfs encoded I/O ioctls all take a full-width segment count, and all of them hand it to import_iovec() or __import_iovec(). Those take an unsigned int count, so on 64-bit kernels the upper 32 bits are dropped before iovec_from_user() checks the count against UIO_MAXIOV. A count of 0x100000001 is therefore imported as one segment: writev() on a pipe writes a byte and readv() reads it back, instead of both failing with EINVAL. A count of 0x100000000 returns 0 as an empty vector. import_iovec() was added with an unsigned int count, but the helper it wrapped, rw_copy_check_uvector(), took an unsigned long, as does iovec_from_user() today. Until v4.1, readv(), writev(), preadv(), pwritev(), process_vm_readv(), process_vm_writev() and vectored aio therefore failed these counts with EINVAL, as did vmsplice() until v4.18. Widen nr_segs in both import helpers so the UIO_MAXIOV check sees the count the caller passed. Callers with 32-bit counts are unaffected. AI assistance was used to find the bug, develop the fix, and run the reproducers. Fixes: bc917be81059 ("saner iov_iter initialization primitives") Signed-off-by: Andrea Parri Link: https://patch.msgid.link/20261026180619.4147910-1-parri.andrea@gmail.com Reviewed-by: Jan Kara Signed-off-by: Christian Brauner (Amutable) Signed-off-by: Sasha Levin --- include/linux/uio.h | 8 ++++---- lib/iov_iter.c | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/linux/uio.h b/include/linux/uio.h index fe2e985d74d24..529c6cd53df7a 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -362,11 +362,11 @@ struct iovec *iovec_from_user(const struct iovec __user *uvector, unsigned long nr_segs, unsigned long fast_segs, struct iovec *fast_iov, bool compat); ssize_t import_iovec(int type, const struct iovec __user *uvec, - unsigned nr_segs, unsigned fast_segs, struct iovec **iovp, - struct iov_iter *i); + unsigned long nr_segs, unsigned int fast_segs, + struct iovec **iovp, struct iov_iter *i); ssize_t __import_iovec(int type, const struct iovec __user *uvec, - unsigned nr_segs, unsigned fast_segs, struct iovec **iovp, - struct iov_iter *i, bool compat); + unsigned long nr_segs, unsigned int fast_segs, + struct iovec **iovp, struct iov_iter *i, bool compat); int import_ubuf(int type, void __user *buf, size_t len, struct iov_iter *i); static inline void iov_iter_ubuf(struct iov_iter *i, unsigned int direction, diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 56c59a2b589d3..55c0dc7e10741 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1366,8 +1366,8 @@ static ssize_t __import_iovec_ubuf(int type, const struct iovec __user *uvec, } ssize_t __import_iovec(int type, const struct iovec __user *uvec, - unsigned nr_segs, unsigned fast_segs, struct iovec **iovp, - struct iov_iter *i, bool compat) + unsigned long nr_segs, unsigned int fast_segs, + struct iovec **iovp, struct iov_iter *i, bool compat) { ssize_t total_len = 0; unsigned long seg; @@ -1438,7 +1438,7 @@ ssize_t __import_iovec(int type, const struct iovec __user *uvec, * Return: Negative error code on error, bytes imported on success */ ssize_t import_iovec(int type, const struct iovec __user *uvec, - unsigned nr_segs, unsigned fast_segs, + unsigned long nr_segs, unsigned int fast_segs, struct iovec **iovp, struct iov_iter *i) { return __import_iovec(type, uvec, nr_segs, fast_segs, iovp, i, -- 2.53.0