iov: add import_ubuf()
authorJens Axboe <axboe@kernel.dk>
Thu, 5 Jan 2023 19:07:30 +0000 (11:07 -0800)
committerJens Axboe <axboe@kernel.dk>
Mon, 9 Jan 2023 03:59:17 +0000 (20:59 -0700)
Like import_single_range(), but for ITER_UBUF.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
include/linux/uio.h
lib/iov_iter.c

index 9f158238edba84fad4a90d00c825ab92c844c095..73b1d5d1e4f1dd3bfab3f9c9fa89ec6f03e53072 100644 (file)
@@ -346,6 +346,7 @@ ssize_t __import_iovec(int type, const struct iovec __user *uvec,
                 struct iov_iter *i, bool compat);
 int import_single_range(int type, void __user *buf, size_t len,
                 struct iovec *iov, struct iov_iter *i);
+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,
                        void __user *buf, size_t count)
index f9a3ff37ecd1aefc656c3b65941ad6c82158dedb..f036760b66e2d6d6b669e4ca5f20c9da88d068fe 100644 (file)
@@ -1877,6 +1877,17 @@ int import_single_range(int rw, void __user *buf, size_t len,
 }
 EXPORT_SYMBOL(import_single_range);
 
+int import_ubuf(int rw, void __user *buf, size_t len, struct iov_iter *i)
+{
+       if (len > MAX_RW_COUNT)
+               len = MAX_RW_COUNT;
+       if (unlikely(!access_ok(buf, len)))
+               return -EFAULT;
+
+       iov_iter_ubuf(i, rw, buf, len);
+       return 0;
+}
+
 /**
  * iov_iter_restore() - Restore a &struct iov_iter to the same state as when
  *     iov_iter_save_state() was called.