Re: [PATCH 2/3] userfaultfd: convert to ->read_iter()

From: Al Viro
Date: Wed Apr 03 2024 - 18:46:06 EST


On Wed, Apr 03, 2024 at 08:02:53AM -0600, Jens Axboe wrote:
> - if (count < sizeof(msg))
> + if (iov_iter_count(to) < sizeof(msg))
> return ret ? ret : -EINVAL;
> _ret = userfaultfd_ctx_read(ctx, no_wait, &msg, inode);
> if (_ret < 0)
> return ret ? ret : _ret;
> - if (copy_to_user((__u64 __user *) buf, &msg, sizeof(msg)))
> + _ret = copy_to_iter(&msg, sizeof(msg), to);
> + if (_ret < 0)
> return ret ? ret : -EFAULT;

Take a look in uio.h - you'll see

size_t copy_to_iter(const void *addr, size_t bytes, struct iov_iter *i)

in there. See the problem?

> + fd = get_unused_fd_flags(O_RDONLY | (flags & UFFD_SHARED_FCNTL_FLAGS));
> + if (fd < 0)
> + goto err_out;

Same comment as for the previous patch.