Skip to content

Commit

Permalink
Merge branch 'vfs.iov_iter' into vfs.all
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Brauner <[email protected]>
  • Loading branch information
brauner committed Dec 14, 2023
2 parents 40ffa70 + 9fd7874 commit 85ddc21
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 43 deletions.
9 changes: 2 additions & 7 deletions drivers/block/ublk_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -893,12 +893,9 @@ static int ublk_map_io(const struct ublk_queue *ubq, const struct request *req,
*/
if (ublk_need_map_req(req)) {
struct iov_iter iter;
struct iovec iov;
const int dir = ITER_DEST;

import_single_range(dir, u64_to_user_ptr(io->addr), rq_bytes,
&iov, &iter);

import_ubuf(dir, u64_to_user_ptr(io->addr), rq_bytes, &iter);
return ublk_copy_user_pages(req, 0, &iter, dir);
}
return rq_bytes;
Expand All @@ -915,13 +912,11 @@ static int ublk_unmap_io(const struct ublk_queue *ubq,

if (ublk_need_unmap_req(req)) {
struct iov_iter iter;
struct iovec iov;
const int dir = ITER_SOURCE;

WARN_ON_ONCE(io->res > rq_bytes);

import_single_range(dir, u64_to_user_ptr(io->addr), io->res,
&iov, &iter);
import_ubuf(dir, u64_to_user_ptr(io->addr), io->res, &iter);
return ublk_copy_user_pages(req, 0, &iter, dir);
}
return rq_bytes;
Expand Down
6 changes: 2 additions & 4 deletions drivers/char/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,6 @@ static void __cold try_to_generate_entropy(void)
SYSCALL_DEFINE3(getrandom, char __user *, ubuf, size_t, len, unsigned int, flags)
{
struct iov_iter iter;
struct iovec iov;
int ret;

if (flags & ~(GRND_NONBLOCK | GRND_RANDOM | GRND_INSECURE))
Expand All @@ -1385,7 +1384,7 @@ SYSCALL_DEFINE3(getrandom, char __user *, ubuf, size_t, len, unsigned int, flags
return ret;
}

ret = import_single_range(ITER_DEST, ubuf, len, &iov, &iter);
ret = import_ubuf(ITER_DEST, ubuf, len, &iter);
if (unlikely(ret))
return ret;
return get_random_bytes_user(&iter);
Expand Down Expand Up @@ -1491,7 +1490,6 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
return 0;
case RNDADDENTROPY: {
struct iov_iter iter;
struct iovec iov;
ssize_t ret;
int len;

Expand All @@ -1503,7 +1501,7 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
return -EINVAL;
if (get_user(len, p++))
return -EFAULT;
ret = import_single_range(ITER_SOURCE, p, len, &iov, &iter);
ret = import_ubuf(ITER_SOURCE, p, len, &iter);
if (unlikely(ret))
return ret;
ret = write_pool_user(&iter);
Expand Down
2 changes: 1 addition & 1 deletion fs/aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ static ssize_t aio_setup_rw(int rw, const struct iocb *iocb,
size_t len = iocb->aio_nbytes;

if (!vectored) {
ssize_t ret = import_single_range(rw, buf, len, *iovec, iter);
ssize_t ret = import_ubuf(rw, buf, len, iter);
*iovec = NULL;
return ret;
}
Expand Down
2 changes: 0 additions & 2 deletions include/linux/uio.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,6 @@ ssize_t import_iovec(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);
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,
Expand Down
4 changes: 1 addition & 3 deletions kernel/trace/trace_events_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -2177,14 +2177,12 @@ static int user_events_open(struct inode *node, struct file *file)
static ssize_t user_events_write(struct file *file, const char __user *ubuf,
size_t count, loff_t *ppos)
{
struct iovec iov;
struct iov_iter i;

if (unlikely(*ppos != 0))
return -EFAULT;

if (unlikely(import_single_range(ITER_SOURCE, (char __user *)ubuf,
count, &iov, &i)))
if (unlikely(import_ubuf(ITER_SOURCE, (char __user *)ubuf, count, &i)))
return -EFAULT;

return user_events_write_core(file, &i);
Expand Down
13 changes: 0 additions & 13 deletions lib/iov_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1369,19 +1369,6 @@ ssize_t import_iovec(int type, const struct iovec __user *uvec,
}
EXPORT_SYMBOL(import_iovec);

int import_single_range(int rw, void __user *buf, size_t len,
struct iovec *iov, 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;
}
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)
Expand Down
10 changes: 4 additions & 6 deletions net/ipv4/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1849,7 +1849,6 @@ static int receive_fallback_to_copy(struct sock *sk,
{
unsigned long copy_address = (unsigned long)zc->copybuf_address;
struct msghdr msg = {};
struct iovec iov;
int err;

zc->length = 0;
Expand All @@ -1858,8 +1857,8 @@ static int receive_fallback_to_copy(struct sock *sk,
if (copy_address != zc->copybuf_address)
return -EINVAL;

err = import_single_range(ITER_DEST, (void __user *)copy_address,
inq, &iov, &msg.msg_iter);
err = import_ubuf(ITER_DEST, (void __user *)copy_address, inq,
&msg.msg_iter);
if (err)
return err;

Expand All @@ -1886,14 +1885,13 @@ static int tcp_copy_straggler_data(struct tcp_zerocopy_receive *zc,
{
unsigned long copy_address = (unsigned long)zc->copybuf_address;
struct msghdr msg = {};
struct iovec iov;
int err;

if (copy_address != zc->copybuf_address)
return -EINVAL;

err = import_single_range(ITER_DEST, (void __user *)copy_address,
copylen, &iov, &msg.msg_iter);
err = import_ubuf(ITER_DEST, (void __user *)copy_address, copylen,
&msg.msg_iter);
if (err)
return err;
err = skb_copy_datagram_msg(skb, *offset, &msg, copylen);
Expand Down
6 changes: 2 additions & 4 deletions net/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -2161,10 +2161,9 @@ int __sys_sendto(int fd, void __user *buff, size_t len, unsigned int flags,
struct sockaddr_storage address;
int err;
struct msghdr msg;
struct iovec iov;
int fput_needed;

err = import_single_range(ITER_SOURCE, buff, len, &iov, &msg.msg_iter);
err = import_ubuf(ITER_SOURCE, buff, len, &msg.msg_iter);
if (unlikely(err))
return err;
sock = sockfd_lookup_light(fd, &err, &fput_needed);
Expand Down Expand Up @@ -2226,11 +2225,10 @@ int __sys_recvfrom(int fd, void __user *ubuf, size_t size, unsigned int flags,
.msg_name = addr ? (struct sockaddr *)&address : NULL,
};
struct socket *sock;
struct iovec iov;
int err, err2;
int fput_needed;

err = import_single_range(ITER_DEST, ubuf, size, &iov, &msg.msg_iter);
err = import_ubuf(ITER_DEST, ubuf, size, &msg.msg_iter);
if (unlikely(err))
return err;
sock = sockfd_lookup_light(fd, &err, &fput_needed);
Expand Down
5 changes: 2 additions & 3 deletions security/keys/keyctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1252,12 +1252,11 @@ long keyctl_instantiate_key(key_serial_t id,
key_serial_t ringid)
{
if (_payload && plen) {
struct iovec iov;
struct iov_iter from;
int ret;

ret = import_single_range(ITER_SOURCE, (void __user *)_payload, plen,
&iov, &from);
ret = import_ubuf(ITER_SOURCE, (void __user *)_payload, plen,
&from);
if (unlikely(ret))
return ret;

Expand Down

0 comments on commit 85ddc21

Please sign in to comment.