diff options
author | Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | 2013-02-25 10:20:36 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-03-12 14:05:45 -0400 |
commit | 8aec0f5d4137532de14e6554fd5dd201ff3a3c49 (patch) | |
tree | 314f28e5ad96423c6983aec9270462d76c0bb343 /security | |
parent | c39ac49f23424086b43aceeace243f7a8bcc3ad8 (diff) |
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 <torvalds@linux-foundation.org>
Acked-by: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'security')
-rw-r--r-- | security/keys/compat.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/security/keys/compat.c b/security/keys/compat.c index 1c261763f479..d65fa7fa29ba 100644 --- a/security/keys/compat.c +++ b/security/keys/compat.c | |||
@@ -40,12 +40,12 @@ static long compat_keyctl_instantiate_key_iov( | |||
40 | ARRAY_SIZE(iovstack), | 40 | ARRAY_SIZE(iovstack), |
41 | iovstack, &iov); | 41 | iovstack, &iov); |
42 | if (ret < 0) | 42 | if (ret < 0) |
43 | return ret; | 43 | goto err; |
44 | if (ret == 0) | 44 | if (ret == 0) |
45 | goto no_payload_free; | 45 | goto no_payload_free; |
46 | 46 | ||
47 | ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid); | 47 | ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid); |
48 | 48 | err: | |
49 | if (iov != iovstack) | 49 | if (iov != iovstack) |
50 | kfree(iov); | 50 | kfree(iov); |
51 | return ret; | 51 | return ret; |