Commit cde5406e authored by Linus Torvalds's avatar Linus Torvalds Committed by Willy Tarreau

vfs: make AIO use the proper rw_verify_area() area helpers

commit a70b52ec upstream.

We had for some reason overlooked the AIO interface, and it didn't use
the proper rw_verify_area() helper function that checks (for example)
mandatory locking on the file, and that the size of the access doesn't
cause us to overflow the provided offset limits etc.

Instead, AIO did just the security_file_permission() thing (that
rw_verify_area() also does) directly.

This fixes it to do all the proper helper functions, which not only
means that now mandatory file locking works with AIO too, we can
actually remove lines of code.
Reported-by: default avatarManish Honap <manish_honap_vit@yahoo.co.in>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Cc: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: default avatarWilly Tarreau <w@1wt.eu>
parent e3dea307
...@@ -1389,6 +1389,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb) ...@@ -1389,6 +1389,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb)
if (ret < 0) if (ret < 0)
goto out; goto out;
ret = rw_verify_area(type, kiocb->ki_filp, &kiocb->ki_pos, ret);
if (ret < 0)
goto out;
kiocb->ki_nr_segs = kiocb->ki_nbytes; kiocb->ki_nr_segs = kiocb->ki_nbytes;
kiocb->ki_cur_seg = 0; kiocb->ki_cur_seg = 0;
/* ki_nbytes/left now reflect bytes instead of segs */ /* ki_nbytes/left now reflect bytes instead of segs */
...@@ -1400,11 +1404,17 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb) ...@@ -1400,11 +1404,17 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb)
return ret; return ret;
} }
static ssize_t aio_setup_single_vector(struct kiocb *kiocb) static ssize_t aio_setup_single_vector(int type, struct file * file, struct kiocb *kiocb)
{ {
int bytes;
bytes = rw_verify_area(type, file, &kiocb->ki_pos, kiocb->ki_left);
if (bytes < 0)
return bytes;
kiocb->ki_iovec = &kiocb->ki_inline_vec; kiocb->ki_iovec = &kiocb->ki_inline_vec;
kiocb->ki_iovec->iov_base = kiocb->ki_buf; kiocb->ki_iovec->iov_base = kiocb->ki_buf;
kiocb->ki_iovec->iov_len = kiocb->ki_left; kiocb->ki_iovec->iov_len = bytes;
kiocb->ki_nr_segs = 1; kiocb->ki_nr_segs = 1;
kiocb->ki_cur_seg = 0; kiocb->ki_cur_seg = 0;
return 0; return 0;
...@@ -1429,10 +1439,7 @@ static ssize_t aio_setup_iocb(struct kiocb *kiocb) ...@@ -1429,10 +1439,7 @@ static ssize_t aio_setup_iocb(struct kiocb *kiocb)
if (unlikely(!access_ok(VERIFY_WRITE, kiocb->ki_buf, if (unlikely(!access_ok(VERIFY_WRITE, kiocb->ki_buf,
kiocb->ki_left))) kiocb->ki_left)))
break; break;
ret = security_file_permission(file, MAY_READ); ret = aio_setup_single_vector(READ, file, kiocb);
if (unlikely(ret))
break;
ret = aio_setup_single_vector(kiocb);
if (ret) if (ret)
break; break;
ret = -EINVAL; ret = -EINVAL;
...@@ -1447,10 +1454,7 @@ static ssize_t aio_setup_iocb(struct kiocb *kiocb) ...@@ -1447,10 +1454,7 @@ static ssize_t aio_setup_iocb(struct kiocb *kiocb)
if (unlikely(!access_ok(VERIFY_READ, kiocb->ki_buf, if (unlikely(!access_ok(VERIFY_READ, kiocb->ki_buf,
kiocb->ki_left))) kiocb->ki_left)))
break; break;
ret = security_file_permission(file, MAY_WRITE); ret = aio_setup_single_vector(WRITE, file, kiocb);
if (unlikely(ret))
break;
ret = aio_setup_single_vector(kiocb);
if (ret) if (ret)
break; break;
ret = -EINVAL; ret = -EINVAL;
...@@ -1461,9 +1465,6 @@ static ssize_t aio_setup_iocb(struct kiocb *kiocb) ...@@ -1461,9 +1465,6 @@ static ssize_t aio_setup_iocb(struct kiocb *kiocb)
ret = -EBADF; ret = -EBADF;
if (unlikely(!(file->f_mode & FMODE_READ))) if (unlikely(!(file->f_mode & FMODE_READ)))
break; break;
ret = security_file_permission(file, MAY_READ);
if (unlikely(ret))
break;
ret = aio_setup_vectored_rw(READ, kiocb); ret = aio_setup_vectored_rw(READ, kiocb);
if (ret) if (ret)
break; break;
...@@ -1475,9 +1476,6 @@ static ssize_t aio_setup_iocb(struct kiocb *kiocb) ...@@ -1475,9 +1476,6 @@ static ssize_t aio_setup_iocb(struct kiocb *kiocb)
ret = -EBADF; ret = -EBADF;
if (unlikely(!(file->f_mode & FMODE_WRITE))) if (unlikely(!(file->f_mode & FMODE_WRITE)))
break; break;
ret = security_file_permission(file, MAY_WRITE);
if (unlikely(ret))
break;
ret = aio_setup_vectored_rw(WRITE, kiocb); ret = aio_setup_vectored_rw(WRITE, kiocb);
if (ret) if (ret)
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment