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=1795621864; b=Bd/1qVez7OXmKaE8V68MG089K1VWMJwTkQBaAYKgxJGmCR9amA/Txry3SkJXkHCHqdWK CWCFVUKnDNrKCcMETZbbcdHM0LIMOBBdULorPyQdmfFUrP9M2RVQqQHNM6XU4K6lcOqJB 6tBVNUVJd3/mrBYRwqBUathl0m8uQA9bnyHlRLlnWHXB9PoQ6te6/USQE7Wr/1ofNdjtw BLm/h2UNp1GHCUBa+gqloTMbPE1anXGMu0C5VMVMJ3SmYqkcZUqgR0Rtgv0qIS+jhEfOq UGQkMgdkJ9k7ia8Akonxy5auR28tLNLrkKzQgBO8BjUEcRhJi31QiPVid0JWNX9Vwfw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795621864; 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=6irtLqr6hhm26tflcWfIo57BMH+XiY/X3iul4CUnQmI=; b=F7ZoioGJzEhFh6tYLnYpyj3mNf3YC2xQFEazqfydAbQGIyBoCdauVi3QotO4ZNcrAIQH WD8hPCcspP9BoFpTvmV30HO128ddubHUtTw7dD7lyScdXsDuQVrnOIULQKQvWZ/N8CLEL dbBoQmOdzPPcv61jElpSOXYqC1RK5I/qYAAn44zvl44P9K1Vw36iHfa5lOOGFLvSkdZBa 59Ji1nJXF+28m4GDAliaBZJG3I/8B2im6fvp1W7lm2Z02tnMXCcaEJcl/h2kUwNN9O1Ae +H7akTl5ZOwd2PbkOhzkkD1xW3R74PbketfB8ZuSJViSKJIGfgUIIUdQr8qWU7JI4FQ== 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=bdEdcoIO; 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 800C5606A321; Wed, 25 Nov 2026 15:51:04 +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=bdEdcoIO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F0771F000CA; Wed, 25 Nov 2026 15:51:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795621863; bh=6irtLqr6hhm26tflcWfIo57BMH+XiY/X3iul4CUnQmI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bdEdcoIODkr6ce/KRBrYH7rTupiF1fx3YcL7TiMl+Y6e7g6Q7BaZ+DrbJAiz1sy1G WZlo6oDppiCV390hvfD2hry95zAFT0IVkN2pYUZBPUMkVFRuGPPAp49FkRMYRXPpHN T4Eq56KiTBD9LEBO7Nq9s5YhCx/bcO8y7TqWeKX4= 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 6.18 303/990] iov_iter: take an unsigned long segment count in import_iovec() Date: Wed, 25 Nov 2026 15:27:50 +0100 Message-ID: <20261125143829.189636612@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261125143822.072087159@linuxfoundation.org> References: <20261125143822.072087159@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 6.18-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 5b127043a1519..5678520f0bfb6 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 b2eb629497a92..a9918931055a8 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1354,8 +1354,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; @@ -1426,7 +1426,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