aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-05-22 20:21:27 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-05-22 20:21:27 -0400
commitbd28b14591b98f696bc9f94c5ba2e598ca487dfd (patch)
tree5cd165412fa7dec2dbbac28ff6d8d5b12d3011f4
parent5b09c3edecd37ec1a52fbd5ae97a19734edc7a77 (diff)
x86: remove more uaccess_32.h complexity
I'm looking at trying to possibly merge the 32-bit and 64-bit versions of the x86 uaccess.h implementation, but first this needs to be cleaned up. For example, the 32-bit version of "__copy_from_user_inatomic()" is mostly the special cases for the constant size, and it's actually almost never relevant. Most users aren't actually using a constant size anyway, and the few cases that do small constant copies are better off just using __get_user() instead. So get rid of the unnecessary complexity. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--arch/x86/include/asm/uaccess_32.h26
-rw-r--r--kernel/events/uprobes.c3
-rw-r--r--kernel/futex.c2
-rw-r--r--mm/maccess.c3
4 files changed, 3 insertions, 31 deletions
diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
index 537cc883ea29..4b32da24faaf 100644
--- a/arch/x86/include/asm/uaccess_32.h
+++ b/arch/x86/include/asm/uaccess_32.h
@@ -65,32 +65,6 @@ __copy_to_user(void __user *to, const void *from, unsigned long n)
65static __always_inline unsigned long 65static __always_inline unsigned long
66__copy_from_user_inatomic(void *to, const void __user *from, unsigned long n) 66__copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
67{ 67{
68 /* Avoid zeroing the tail if the copy fails..
69 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
70 * but as the zeroing behaviour is only significant when n is not
71 * constant, that shouldn't be a problem.
72 */
73 if (__builtin_constant_p(n)) {
74 unsigned long ret;
75
76 switch (n) {
77 case 1:
78 __uaccess_begin();
79 __get_user_size(*(u8 *)to, from, 1, ret, 1);
80 __uaccess_end();
81 return ret;
82 case 2:
83 __uaccess_begin();
84 __get_user_size(*(u16 *)to, from, 2, ret, 2);
85 __uaccess_end();
86 return ret;
87 case 4:
88 __uaccess_begin();
89 __get_user_size(*(u32 *)to, from, 4, ret, 4);
90 __uaccess_end();
91 return ret;
92 }
93 }
94 return __copy_from_user_ll_nozero(to, from, n); 68 return __copy_from_user_ll_nozero(to, from, n);
95} 69}
96 70
diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
index 7edc95edfaee..c01f733ff2e1 100644
--- a/kernel/events/uprobes.c
+++ b/kernel/events/uprobes.c
@@ -1694,8 +1694,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
1694 int result; 1694 int result;
1695 1695
1696 pagefault_disable(); 1696 pagefault_disable();
1697 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr, 1697 result = __get_user(opcode, (uprobe_opcode_t __user *)vaddr);
1698 sizeof(opcode));
1699 pagefault_enable(); 1698 pagefault_enable();
1700 1699
1701 if (likely(result == 0)) 1700 if (likely(result == 0))
diff --git a/kernel/futex.c b/kernel/futex.c
index c20f06f38ef3..ee25f5ba4aca 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -729,7 +729,7 @@ static int get_futex_value_locked(u32 *dest, u32 __user *from)
729 int ret; 729 int ret;
730 730
731 pagefault_disable(); 731 pagefault_disable();
732 ret = __copy_from_user_inatomic(dest, from, sizeof(u32)); 732 ret = __get_user(*dest, from);
733 pagefault_enable(); 733 pagefault_enable();
734 734
735 return ret ? -EFAULT : 0; 735 return ret ? -EFAULT : 0;
diff --git a/mm/maccess.c b/mm/maccess.c
index d159b1c96e48..78f9274dd49d 100644
--- a/mm/maccess.c
+++ b/mm/maccess.c
@@ -96,8 +96,7 @@ long strncpy_from_unsafe(char *dst, const void *unsafe_addr, long count)
96 pagefault_disable(); 96 pagefault_disable();
97 97
98 do { 98 do {
99 ret = __copy_from_user_inatomic(dst++, 99 ret = __get_user(*dst++, (const char __user __force *)src++);
100 (const void __user __force *)src++, 1);
101 } while (dst[-1] && ret == 0 && src - unsafe_addr < count); 100 } while (dst[-1] && ret == 0 && src - unsafe_addr < count);
102 101
103 dst[-1] = '\0'; 102 dst[-1] = '\0';