Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ac34ebb3 authored by Christopher Yeoh's avatar Christopher Yeoh Committed by Linus Torvalds
Browse files

aio/vfs: cleanup of rw_copy_check_uvector() and compat_rw_copy_check_uvector()



A cleanup of rw_copy_check_uvector and compat_rw_copy_check_uvector after
changes made to support CMA in an earlier patch.

Rather than having an additional check_access parameter to these
functions, the first paramater type is overloaded to allow the caller to
specify CHECK_IOVEC_ONLY which means check that the contents of the iovec
are valid, but do not check the memory that they point to.  This is used
by process_vm_readv/writev where we need to validate that a iovec passed
to the syscall is valid but do not want to check the memory that it points
to at this point because it refers to an address space in another process.

Signed-off-by: default avatarChris Yeoh <yeohc@au1.ibm.com>
Reviewed-by: default avatarOleg Nesterov <oleg@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ee62c6b2
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -1446,13 +1446,13 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
		ret = compat_rw_copy_check_uvector(type,
		ret = compat_rw_copy_check_uvector(type,
				(struct compat_iovec __user *)kiocb->ki_buf,
				(struct compat_iovec __user *)kiocb->ki_buf,
				kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
				kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
				&kiocb->ki_iovec, 1);
				&kiocb->ki_iovec);
	else
	else
#endif
#endif
		ret = rw_copy_check_uvector(type,
		ret = rw_copy_check_uvector(type,
				(struct iovec __user *)kiocb->ki_buf,
				(struct iovec __user *)kiocb->ki_buf,
				kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
				kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
				&kiocb->ki_iovec, 1);
				&kiocb->ki_iovec);
	if (ret < 0)
	if (ret < 0)
		goto out;
		goto out;


+3 −3
Original line number Original line Diff line number Diff line
@@ -532,7 +532,7 @@ compat_sys_io_getevents(aio_context_t ctx_id,
ssize_t compat_rw_copy_check_uvector(int type,
ssize_t compat_rw_copy_check_uvector(int type,
		const struct compat_iovec __user *uvector, unsigned long nr_segs,
		const struct compat_iovec __user *uvector, unsigned long nr_segs,
		unsigned long fast_segs, struct iovec *fast_pointer,
		unsigned long fast_segs, struct iovec *fast_pointer,
		struct iovec **ret_pointer, int check_access)
		struct iovec **ret_pointer)
{
{
	compat_ssize_t tot_len;
	compat_ssize_t tot_len;
	struct iovec *iov = *ret_pointer = fast_pointer;
	struct iovec *iov = *ret_pointer = fast_pointer;
@@ -579,7 +579,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
		}
		}
		if (len < 0)	/* size_t not fitting in compat_ssize_t .. */
		if (len < 0)	/* size_t not fitting in compat_ssize_t .. */
			goto out;
			goto out;
		if (check_access &&
		if (type >= 0 &&
		    !access_ok(vrfy_dir(type), compat_ptr(buf), len)) {
		    !access_ok(vrfy_dir(type), compat_ptr(buf), len)) {
			ret = -EFAULT;
			ret = -EFAULT;
			goto out;
			goto out;
@@ -1094,7 +1094,7 @@ static ssize_t compat_do_readv_writev(int type, struct file *file,
		goto out;
		goto out;


	tot_len = compat_rw_copy_check_uvector(type, uvector, nr_segs,
	tot_len = compat_rw_copy_check_uvector(type, uvector, nr_segs,
					       UIO_FASTIOV, iovstack, &iov, 1);
					       UIO_FASTIOV, iovstack, &iov);
	if (tot_len == 0) {
	if (tot_len == 0) {
		ret = 0;
		ret = 0;
		goto out;
		goto out;
+3 −4
Original line number Original line Diff line number Diff line
@@ -633,8 +633,7 @@ ssize_t do_loop_readv_writev(struct file *filp, struct iovec *iov,
ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
			      unsigned long nr_segs, unsigned long fast_segs,
			      unsigned long nr_segs, unsigned long fast_segs,
			      struct iovec *fast_pointer,
			      struct iovec *fast_pointer,
			      struct iovec **ret_pointer,
			      struct iovec **ret_pointer)
			      int check_access)
{
{
	unsigned long seg;
	unsigned long seg;
	ssize_t ret;
	ssize_t ret;
@@ -690,7 +689,7 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
			ret = -EINVAL;
			ret = -EINVAL;
			goto out;
			goto out;
		}
		}
		if (check_access
		if (type >= 0
		    && unlikely(!access_ok(vrfy_dir(type), buf, len))) {
		    && unlikely(!access_ok(vrfy_dir(type), buf, len))) {
			ret = -EFAULT;
			ret = -EFAULT;
			goto out;
			goto out;
@@ -723,7 +722,7 @@ static ssize_t do_readv_writev(int type, struct file *file,
	}
	}


	ret = rw_copy_check_uvector(type, uvector, nr_segs,
	ret = rw_copy_check_uvector(type, uvector, nr_segs,
				    ARRAY_SIZE(iovstack), iovstack, &iov, 1);
				    ARRAY_SIZE(iovstack), iovstack, &iov);
	if (ret <= 0)
	if (ret <= 0)
		goto out;
		goto out;


+1 −2
Original line number Original line Diff line number Diff line
@@ -577,8 +577,7 @@ extern ssize_t compat_rw_copy_check_uvector(int type,
		const struct compat_iovec __user *uvector,
		const struct compat_iovec __user *uvector,
		unsigned long nr_segs,
		unsigned long nr_segs,
		unsigned long fast_segs, struct iovec *fast_pointer,
		unsigned long fast_segs, struct iovec *fast_pointer,
		struct iovec **ret_pointer,
		struct iovec **ret_pointer);
		int check_access);


extern void __user *compat_alloc_user_space(unsigned long len);
extern void __user *compat_alloc_user_space(unsigned long len);


+10 −2
Original line number Original line Diff line number Diff line
@@ -173,6 +173,15 @@ struct inodes_stat_t {
#define WRITE_FUA		(WRITE | REQ_SYNC | REQ_NOIDLE | REQ_FUA)
#define WRITE_FUA		(WRITE | REQ_SYNC | REQ_NOIDLE | REQ_FUA)
#define WRITE_FLUSH_FUA		(WRITE | REQ_SYNC | REQ_NOIDLE | REQ_FLUSH | REQ_FUA)
#define WRITE_FLUSH_FUA		(WRITE | REQ_SYNC | REQ_NOIDLE | REQ_FLUSH | REQ_FUA)



/*
 * Flag for rw_copy_check_uvector and compat_rw_copy_check_uvector
 * that indicates that they should check the contents of the iovec are
 * valid, but not check the memory that the iovec elements
 * points too.
 */
#define CHECK_IOVEC_ONLY -1

#define SEL_IN		1
#define SEL_IN		1
#define SEL_OUT		2
#define SEL_OUT		2
#define SEL_EX		4
#define SEL_EX		4
@@ -1690,8 +1699,7 @@ struct seq_file;
ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
			      unsigned long nr_segs, unsigned long fast_segs,
			      unsigned long nr_segs, unsigned long fast_segs,
			      struct iovec *fast_pointer,
			      struct iovec *fast_pointer,
			      struct iovec **ret_pointer,
			      struct iovec **ret_pointer);
			      int check_access);


extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
Loading