]> git.ipfire.org Git - people/arne_f/kernel.git/commit
MIPS: OCTEON: Fix copy_from_user fault handling for large buffers
authorJames Cowgill <James.Cowgill@imgtec.com>
Mon, 9 Jan 2017 16:52:28 +0000 (16:52 +0000)
committerJiri Slaby <jslaby@suse.cz>
Mon, 13 Mar 2017 20:40:16 +0000 (21:40 +0100)
commit6f25f217710b484b7eea2ea1a3e9f1c00e44f496
tree6def75d64fb6952eca51225a1fc880b967588682
parent9245eb2ff54228b6ab2fcae449608279062b8eb2
MIPS: OCTEON: Fix copy_from_user fault handling for large buffers

commit 884b426917e4b3c85f33b382c792a94305dfdd62 upstream.

If copy_from_user is called with a large buffer (>= 128 bytes) and the
userspace buffer refers partially to unreadable memory, then it is
possible for Octeon's copy_from_user to report the wrong number of bytes
have been copied. In the case where the buffer size is an exact multiple
of 128 and the fault occurs in the last 64 bytes, copy_from_user will
report that all the bytes were copied successfully but leave some
garbage in the destination buffer.

The bug is in the main __copy_user_common loop in octeon-memcpy.S where
in the middle of the loop, src and dst are incremented by 128 bytes. The
l_exc_copy fault handler is used after this but that assumes that
"src < THREAD_BUADDR($28)". This is not the case if src has already been
incremented.

Fix by adding an extra fault handler which rewinds the src and dst
pointers 128 bytes before falling though to l_exc_copy.

Thanks to the pwritev test from the strace test suite for originally
highlighting this bug!

Fixes: 5b3b16880f40 ("MIPS: Add Cavium OCTEON processor support ...")
Signed-off-by: James Cowgill <James.Cowgill@imgtec.com>
Acked-by: David Daney <david.daney@cavium.com>
Reviewed-by: James Hogan <james.hogan@imgtec.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/14978/
Signed-off-by: James Hogan <james.hogan@imgtec.com>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
arch/mips/cavium-octeon/octeon-memcpy.S