Skip to contentSkip to conversation

Fix zeroing on exception in copy_*_user

PATCH In review Andrew Morton 3 participants 4 messages Sep 27, 2006 – Sep 28, 2006 Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix zeroing on exception in copy_*_user

I guess other architectures will need to do this. See 01408c4939479ec46c15aa7ef6e2406be50eeeca and 7c12d81134b130ccd4c286b434ca48c4cda71a2f for the rationale.

Begin forwarded message:

Date: Tue, 26 Sep 2006 23:03:58 GMT
From: Linux Kernel Mailing List <[email protected]>
To: [email protected]
Subject: [PATCH] Fix zeroing on exception in copy_*_user

commit 3022d734a54cbd2b65eea9a024564821101b4a9a
tree a1445aeaf8fbdf84898c8cdc13dd98c550b5be0f
parent f0f4c3432e5e1087b3a8c0e6bd4113d3c37497ff author Andi Kleen <[email protected]> 1159260759 +0200 committer Andi Kleen <[email protected]> 1159260759 +0200

[PATCH] Fix zeroing on exception in copy_*_user

- Don't zero for __copy_from_user_inatomic following i386. This will prevent spurious zeros for parallel file system writers when one does a exception
- The string instruction version didn't zero the output on exception. Oops.

Also I cleaned up the code a bit while I was at it and added a minor optimization to the string instruction path.

 arch/x86_64/kernel/x8664_ksyms.c |    1 
 arch/x86_64/lib/copy_user.S      |  124 ++++++++++++++++++++++++---------------
 include/asm-x86_64/uaccess.h     |    6 -
 3 files changed, 83 insertions(+), 48 deletions(-)
arch/x86_64/kernel/x8664_ksyms.c +1 -0
index 370952c..c3454af 100644
@@ -29,6 +29,7 @@ EXPORT_SYMBOL(__put_user_8);
 EXPORT_SYMBOL(copy_user_generic);
 EXPORT_SYMBOL(copy_from_user);
 EXPORT_SYMBOL(copy_to_user);
+EXPORT_SYMBOL(__copy_from_user_inatomic);
 
 EXPORT_SYMBOL(copy_page);
 EXPORT_SYMBOL(clear_page);
arch/x86_64/lib/copy_user.S +79 -45

201 lines not on this page · raw message

include/asm-x86_64/uaccess.h +3 -3
index 1e1fa00..bc68120 100644
@@ -238,6 +238,7 @@ #define __get_user_asm(x, addr, err, ity
 
 /* Handles exceptions in both to and from, but doesn't do access_ok */
 extern unsigned long copy_user_generic(void *to, const void *from, unsigned len); 
+extern unsigned long copy_user_generic_dontzero(void *to, const void *from, unsigned len);
 
 extern unsigned long copy_to_user(void __user *to, const void *from, unsigned len); 
 extern unsigned long copy_from_user(void *to, const void __user *from, unsigned len); 
@@ -303,7 +304,6 @@ static __always_inline int __copy_to_use
 	}
 }	
 
-
 static __always_inline int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
 { 
        int ret = 0;
@@ -352,7 +352,7 @@ long strlen_user(const char __user *str)
 unsigned long clear_user(void __user *mem, unsigned long len);
 unsigned long __clear_user(void __user *mem, unsigned long len);
 
-#define __copy_to_user_inatomic __copy_to_user
-#define __copy_from_user_inatomic __copy_from_user
+extern long __copy_from_user_inatomic(void *dst, const void __user *src, unsigned size);
+#define __copy_to_user_inatomic copy_user_generic
 
 #endif /* __X86_64_UACCESS_H */

-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#1 lore raw
Quoted 3 lines · Andrew Morton

I guess other architectures will need to do this. See 01408c4939479ec46c15aa7ef6e2406be50eeeca and 7c12d81134b130ccd4c286b434ca48c4cda71a2f for the rationale.

Urgh, s390 does not have the problem that is does pad the leftover bytes in __copy_from_user_inatomic but that is does NOT pad the leftover bytes in __copy_from_user ..

Signature · 8 lines
blue skies,
  Martin.

Martin Schwidefsky
Linux for zSeries Development & Services
IBM Deutschland Entwicklung GmbH

"Reality continues to ruin my life." - Calvin.
#2 lore raw
Quoted 9 lines · On Wed, 27 Sep 2006 11:31:32 +0200 Martin Schwidefsky <[email protected]>…
Quoted 3 lines · Andrew Morton

I guess other architectures will need to do this. See 01408c4939479ec46c15aa7ef6e2406be50eeeca and 7c12d81134b130ccd4c286b434ca48c4cda71a2f for the rationale.

Urgh, s390 does not have the problem that is does pad the leftover bytes in __copy_from_user_inatomic but that is does NOT pad the leftover bytes in __copy_from_user ..

That permits users to read uninitialised kernel memory by appending to a file from a bad address then reading the result back....

#3 lore raw

From: Andrew Morton <[email protected]>
Date: Wed, 27 Sep 2006 09:18:30 -0700

Quoted 8 lines
Quoted 5 lines · On Wed, 27 Sep 2006 11:31:32 +0200 Martin Schwidefsky <[email protected]>…
Quoted 3 lines · Andrew Morton

I guess other architectures will need to do this. See 01408c4939479ec46c15aa7ef6e2406be50eeeca and 7c12d81134b130ccd4c286b434ca48c4cda71a2f for the rationale.

Quoted 7 lines
Quoted 4 lines

Urgh, s390 does not have the problem that is does pad the leftover bytes in __copy_from_user_inatomic but that is does NOT pad the leftover bytes in __copy_from_user ..

That permits users to read uninitialised kernel memory by appending to a file from a bad address then reading the result back....

Right.

But wrt. *_inatomic() issue, you only need to add the new logic to avoid zeroing at the end on a fault _iff_ kmap_atomic() is relevent on your platform. In particular, it's necessary if kmap_atomic() disables preemption or anything like that.

So only a more limited set of platforms need to worry about this. As far as I can tell, this means:

i386
FRV
MIPS
PPC
SPARC32

I'll try to take care of sparc32.