mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 03:01:39 -04:00
Fix: compat_rw_copy_check_uvector() misuse in aio, readv, writev, and security keys
Looking at mm/process_vm_access.c:process_vm_rw() and comparing it to compat_process_vm_rw() shows that the compatibility code requires an explicit "access_ok()" check before calling compat_rw_copy_check_uvector(). The same difference seems to appear when we compare fs/read_write.c:do_readv_writev() to fs/compat.c:compat_do_readv_writev(). This subtle difference between the compat and non-compat requirements should probably be debated, as it seems to be error-prone. In fact, there are two others sites that use this function in the Linux kernel, and they both seem to get it wrong: Now shifting our attention to fs/aio.c, we see that aio_setup_iocb() also ends up calling compat_rw_copy_check_uvector() through aio_setup_vectored_rw(). Unfortunately, the access_ok() check appears to be missing. Same situation for security/keys/compat.c:compat_keyctl_instantiate_key_iov(). I propose that we add the access_ok() check directly into compat_rw_copy_check_uvector(), so callers don't have to worry about it, and it therefore makes the compat call code similar to its non-compat counterpart. Place the access_ok() check in the same location where copy_from_user() can trigger a -EFAULT error in the non-compat code, so the ABI behaviors are alike on both compat and non-compat. While we are here, fix compat_do_readv_writev() so it checks for compat_rw_copy_check_uvector() negative return values. And also, fix a memory leak in compat_keyctl_instantiate_key_iov() error handling. Acked-by: Linus Torvalds <[email protected]> Acked-by: Al Viro <[email protected]> Signed-off-by: Mathieu Desnoyers <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
parent
c39ac49f23
commit
8aec0f5d41
3 changed files with 9 additions and 18 deletions
15
fs/compat.c
15
fs/compat.c
|
|
@ -558,6 +558,10 @@ ssize_t compat_rw_copy_check_uvector(int type,
|
|||
}
|
||||
*ret_pointer = iov;
|
||||
|
||||
ret = -EFAULT;
|
||||
if (!access_ok(VERIFY_READ, uvector, nr_segs*sizeof(*uvector)))
|
||||
goto out;
|
||||
|
||||
/*
|
||||
* Single unix specification:
|
||||
* We should -EINVAL if an element length is not >= 0 and fitting an
|
||||
|
|
@ -1080,17 +1084,12 @@ static ssize_t compat_do_readv_writev(int type, struct file *file,
|
|||
if (!file->f_op)
|
||||
goto out;
|
||||
|
||||
ret = -EFAULT;
|
||||
if (!access_ok(VERIFY_READ, uvector, nr_segs*sizeof(*uvector)))
|
||||
goto out;
|
||||
|
||||
tot_len = compat_rw_copy_check_uvector(type, uvector, nr_segs,
|
||||
ret = compat_rw_copy_check_uvector(type, uvector, nr_segs,
|
||||
UIO_FASTIOV, iovstack, &iov);
|
||||
if (tot_len == 0) {
|
||||
ret = 0;
|
||||
if (ret <= 0)
|
||||
goto out;
|
||||
}
|
||||
|
||||
tot_len = ret;
|
||||
ret = rw_verify_area(type, file, pos, tot_len);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
|
|
|||
Loading…
Reference in a new issue