Skip to contentSkip to conversation

iov_iter-take-an-unsigned-long-segment-count-in-import_iovec.patch removed from -mm tree

merged Andrew Morton 1 participant 1 message Nov 5

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: iov_iter: take an unsigned long segment count in import_iovec()
has been removed from the -mm tree. Its filename was
iov_iter-take-an-unsigned-long-segment-count-in-import_iovec.patch

This patch was dropped because it was merged into mainline or a subsystem tree

------------------------------------------------------
From: Andrea Parri <[email protected]>
Subject: iov_iter: take an unsigned long segment count in import_iovec()
Date: Mon, 26 Oct 2026 19:06:18 +0100

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")
Cc Al Viro <[email protected]>
Cc Christian Brauner <[email protected]>

---

 include/linux/uio.h |    8 ++++----
 lib/iov_iter.c      |    6 +++---
 2 files changed, 7 insertions(+), 7 deletions(-)
include/linux/uio.h renamed from include/linux/uio.h~iov_iter-take-an-unsigned-long-segment-count-in-import_iovec +4 -4
@@ -373,11 +373,11 @@ struct iovec *iovec_from_user(const stru
 		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,
lib/iov_iter.c renamed from lib/iov_iter.c~iov_iter-take-an-unsigned-long-segment-count-in-import_iovec +3 -3
@@ -1382,8 +1382,8 @@ static ssize_t __import_iovec_ubuf(int t
 }
 
 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;
@@ -1454,7 +1454,7 @@ ssize_t __import_iovec(int type, const s
  * 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,

_

Patches currently in -mm which might be from [email protected] are