aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib/iov_iter.c
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2024-01-29 10:37:29 -0800
committerChristian Brauner <brauner@kernel.org>2024-02-02 13:11:49 +0100
commitbd8c239c0502e70c92cf9496846bcbec7cd5702f (patch)
tree2df9a33d2f482e58d6df3b1d666ee2319d33261f /lib/iov_iter.c
parentntfs3: use file_mnt_idmap helper (diff)
downloadwireguard-linux-bd8c239c0502e70c92cf9496846bcbec7cd5702f.tar.xz
wireguard-linux-bd8c239c0502e70c92cf9496846bcbec7cd5702f.zip
iov_iter: Avoid wrap-around instrumentation in copy_compat_iovec_from_user()
The loop counter "i" in copy_compat_iovec_from_user() is an int, but because the nr_segs argument is unsigned long, the signed overflow sanitizer got worried "i" could wrap around. Instead of making "i" an unsigned long (which may enlarge the type size), switch both nr_segs and i to u32. There is no truncation with nr_segs since it is never larger than UIO_MAXIOV anyway. This keeps sanitizer instrumentation[1] out of a UACCESS path: vmlinux.o: warning: objtool: copy_compat_iovec_from_user+0xa9: call to __ubsan_handle_add_overflow() with UACCESS enabled Link: https://github.com/KSPP/linux/issues/26 [1] Cc: Christian Brauner <brauner@kernel.org> Cc: Alexander Viro <viro@zeniv.linux.org.uk> Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20240129183729.work.991-kees@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'lib/iov_iter.c')
-rw-r--r--lib/iov_iter.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 15f5040709c3..73715d10c812 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -1167,11 +1167,12 @@ const void *dup_iter(struct iov_iter *new, struct iov_iter *old, gfp_t flags)
EXPORT_SYMBOL(dup_iter);
static __noclone int copy_compat_iovec_from_user(struct iovec *iov,
- const struct iovec __user *uvec, unsigned long nr_segs)
+ const struct iovec __user *uvec, u32 nr_segs)
{
const struct compat_iovec __user *uiov =
(const struct compat_iovec __user *)uvec;
- int ret = -EFAULT, i;
+ int ret = -EFAULT;
+ u32 i;
if (!user_access_begin(uiov, nr_segs * sizeof(*uiov)))
return -EFAULT;