Skip to content

Commit 41a69b5

Browse files
torvaldsAlex Shi
authored andcommitted
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> (cherry picked from commit bd28b14591b98f696bc9f94c5ba2e598ca487dfd) Signed-off-by: Alex Shi <alex.shi@linaro.org>
1 parent 30e3024 commit 41a69b5

4 files changed

Lines changed: 3 additions & 31 deletions

File tree

arch/x86/include/asm/uaccess_32.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,32 +65,6 @@ __copy_to_user(void __user *to, const void *from, unsigned long n)
6565
static __always_inline unsigned long
6666
__copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
6767
{
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-
}
9468
return __copy_from_user_ll_nozero(to, from, n);
9569
}
9670

kernel/events/uprobes.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,8 +1692,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
16921692
int result;
16931693

16941694
pagefault_disable();
1695-
result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
1696-
sizeof(opcode));
1695+
result = __get_user(opcode, (uprobe_opcode_t __user *)vaddr);
16971696
pagefault_enable();
16981697

16991698
if (likely(result == 0))

kernel/futex.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ static int get_futex_value_locked(u32 *dest, u32 __user *from)
681681
int ret;
682682

683683
pagefault_disable();
684-
ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
684+
ret = __get_user(*dest, from);
685685
pagefault_enable();
686686

687687
return ret ? -EFAULT : 0;

mm/maccess.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ long strncpy_from_unsafe(char *dst, const void *unsafe_addr, long count)
9696
pagefault_disable();
9797

9898
do {
99-
ret = __copy_from_user_inatomic(dst++,
100-
(const void __user __force *)src++, 1);
99+
ret = __get_user(*dst++, (const char __user __force *)src++);
101100
} while (dst[-1] && ret == 0 && src - unsafe_addr < count);
102101

103102
dst[-1] = '\0';

0 commit comments

Comments
 (0)