linux/arch/x86/lib
Linus Torvalds 42a886af72 x86-64: Fix "bytes left to copy" return value for copy_from_user()
Most users by far do not care about the exact return value (they only
really care about whether the copy succeeded in its entirety or not),
but a few special core routines actually care deeply about exactly how
many bytes were copied from user space.

And the unrolled versions of the x86-64 user copy routines would
sometimes report that it had copied more bytes than it actually had.

Very few uses actually have partial copies to begin with, but to make
this bug even harder to trigger, most x86 CPU's use the "rep string"
instructions for normal user copies, and that version didn't have this
issue.

To make it even harder to hit, the one user of this that really cared
about the return value (and used the uncached version of the copy that
doesn't use the "rep string" instructions) was the generic write
routine, which pre-populated its source, once more hiding the problem by
avoiding the exception case that triggers the bug.

In other words, very special thanks to Bron Gondwana who not only
triggered this, but created a test-program to show it, and bisected the
behavior down to commit 08291429cf ("mm:
fix pagecache write deadlocks") which changed the access pattern just
enough that you can now trigger it with 'writev()' with multiple
iovec's.

That commit itself was not the cause of the bug, it just allowed all the
stars to align just right that you could trigger the problem.

[ Side note: this is just the minimal fix to make the copy routines
  (with __copy_from_user_inatomic_nocache as the particular version that
  was involved in showing this) have the right return values.

  We really should improve on the exceptional case further - to make the
  copy do a byte-accurate copy up to the exact page limit that causes it
  to fail.  As it is, the callers have to do extra work to handle the
  limit case gracefully. ]

Reported-by: Bron Gondwana <brong@fastmail.fm>
Cc: Nick Piggin <npiggin@suse.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

 (which didn't have this problem), and since
most users that do the carethis was very hard to trigger, but
2008-06-17 17:47:50 -07:00
..
checksum_32.S
clear_page_64.S x86_64: move lib 2007-10-11 11:17:08 +02:00
copy_page_64.S x86_64: move lib 2007-10-11 11:17:08 +02:00
copy_user_64.S x86-64: Fix "bytes left to copy" return value for copy_from_user() 2008-06-17 17:47:50 -07:00
copy_user_nocache_64.S x86-64: Fix "bytes left to copy" return value for copy_from_user() 2008-06-17 17:47:50 -07:00
csum-copy_64.S x86_64: move lib 2007-10-11 11:17:08 +02:00
csum-partial_64.c x86: fix csum_partial() export 2008-05-13 19:38:47 +02:00
csum-wrappers_64.c x86: clean up csum-wrappers_64.c some more 2008-02-19 16:18:32 +01:00
delay_32.c x86: enable preemption in delay 2008-06-04 13:11:46 +02:00
delay_64.c x86: enable preemption in delay 2008-06-04 13:11:46 +02:00
getuser_32.S
getuser_64.S x86_64: move lib 2007-10-11 11:17:08 +02:00
io_64.c x86: coding style fixes in arch/x86/lib/io_64.c 2008-02-19 16:18:32 +01:00
iomap_copy_64.S x86_64: move lib 2007-10-11 11:17:08 +02:00
Makefile x86, UML: remove x86-specific implementations of find_first_bit 2008-04-26 19:21:17 +02:00
memcpy_32.c x86: coding style fixes to arch/x86/lib/memcpy_32.c 2008-04-17 17:40:49 +02:00
memcpy_64.S x86_64: move lib 2007-10-11 11:17:08 +02:00
memmove_64.c x86: coding style fixes to arch/x86/lib/memmove_64.c 2008-04-17 17:40:48 +02:00
memset_64.S x86_64: move lib 2007-10-11 11:17:08 +02:00
mmx_32.c x86: clean up mmx_32.c 2008-04-17 17:40:47 +02:00
msr-on-cpu.c i386: simplify smp_call_function_single() call sequence in msr-on-cpu 2007-10-17 20:16:20 +02:00
putuser_32.S
putuser_64.S x86_64: move lib 2007-10-11 11:17:08 +02:00
rwlock_64.S x86: rename .i assembler includes to .h 2007-10-17 20:16:29 +02:00
semaphore_32.S Generic semaphore implementation 2008-04-17 10:42:34 -04:00
string_32.c x86: coding style fixes to arch/x86/lib/string_32.c 2008-04-17 17:40:48 +02:00
strstr_32.c x86: coding style fixes to arch/x86/lib/strstr_3 2008-04-17 17:40:49 +02:00
thunk_64.S Generic semaphore implementation 2008-04-17 10:42:34 -04:00
usercopy_32.c x86: coding style fixes to arch/x86/lib/usercopy_32.c 2008-04-17 17:40:51 +02:00
usercopy_64.c x86: use _ASM_EXTABLE macro in arch/x86/lib/usercopy_64.c 2008-02-04 16:47:57 +01:00