linux/arch/mips/cavium-octeon
James Cowgill 884b426917 MIPS: OCTEON: Fix copy_from_user fault handling for large buffers
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: 5b3b16880f ("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
Cc: stable@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/14978/
Signed-off-by: James Hogan <james.hogan@imgtec.com>
2017-02-17 11:14:28 +00:00
..
crypto MIPS: Audit and remove any unnecessary uses of module.h 2017-02-14 09:00:25 +00:00
executive MIPS: Audit and remove any unnecessary uses of module.h 2017-02-14 09:00:25 +00:00
cpu.c
csrc-octeon.c clocksource: Use a plain u64 instead of cycle_t 2016-12-25 11:04:12 +01:00
dma-octeon.c MIPS: Octeon: Avoid empty-body warning 2017-01-25 02:51:11 +01:00
flash_setup.c MIPS: Octeon: Don't set .owner. 2015-04-08 01:10:53 +02:00
Kconfig treewide: Fix typos in Kconfig 2014-09-26 11:12:28 +02:00
Makefile MIPS: OCTEON: Platform support for OCTEON III USB controller 2017-02-14 08:52:46 +00:00
oct_ilm.c MIPS: Octeon: remove unnecessary null test before debugfs_remove_recursive 2014-08-02 00:06:47 +02:00
octeon_boot.h MIPS: Octeon: Handle bootloader structures in little-endian mode. 2015-04-01 17:21:23 +02:00
octeon-irq.c MIPS: Octeon: mark GPIO controller node not populated after IRQ init. 2016-09-29 18:59:49 +02:00
octeon-memcpy.S MIPS: OCTEON: Fix copy_from_user fault handling for large buffers 2017-02-17 11:14:28 +00:00
octeon-platform.c MIPS: OCTEON: Platform support for OCTEON III USB controller 2017-02-14 08:52:46 +00:00
octeon-usb.c MIPS: OCTEON: Platform support for OCTEON III USB controller 2017-02-14 08:52:46 +00:00
Platform MIPS: OCTEON: Rename Kconfig CAVIUM_OCTEON_REFERENCE_BOARD to CAVIUM_OCTEON_SOC 2013-06-10 18:01:25 +02:00
setup.c MIPS: Octeon: Add plat_get_fdt() function for Cavium platforms. 2017-01-03 16:34:35 +01:00
smp.c MIPS: Audit and remove any unnecessary uses of module.h 2017-02-14 09:00:25 +00:00