Skip to content

Commit b75b9b9

Browse files
Phil Elwellpopcornmix
Phil Elwell
authored andcommitted
copy_from_user: CPU_SW_DOMAIN_PAN compatibility
The downstream copy_from_user acceleration must also play nice with CONFIG_CPU_SW_DOMAIN_PAN. See: #1381 Signed-off-by: Phil Elwell <[email protected]>
1 parent 0a60763 commit b75b9b9

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

arch/arm/lib/uaccess_with_memcpy.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ __copy_to_user_memcpy(void __user *to, const void *from, unsigned long n)
186186
unsigned long noinline
187187
__copy_from_user_memcpy(void *to, const void __user *from, unsigned long n)
188188
{
189+
unsigned long ua_flags;
189190
int atomic;
190191

191192
if (unlikely(segment_eq(get_fs(), KERNEL_DS))) {
@@ -217,7 +218,9 @@ __copy_from_user_memcpy(void *to, const void __user *from, unsigned long n)
217218
if (tocopy > n)
218219
tocopy = n;
219220

221+
ua_flags = uaccess_save_and_enable();
220222
memcpy(to, (const void *)from, tocopy);
223+
uaccess_restore(ua_flags);
221224
to += tocopy;
222225
from += tocopy;
223226
n -= tocopy;
@@ -261,9 +264,14 @@ arm_copy_from_user(void *to, const void __user *from, unsigned long n)
261264
* With frame pointer disabled, tail call optimization kicks in
262265
* as well making this test almost invisible.
263266
*/
264-
if (n < COPY_FROM_USER_THRESHOLD)
265-
return __copy_from_user_std(to, from, n);
266-
return __copy_from_user_memcpy(to, from, n);
267+
if (n < COPY_TO_USER_THRESHOLD) {
268+
unsigned long ua_flags = uaccess_save_and_enable();
269+
n = __copy_from_user_std(to, from, n);
270+
uaccess_restore(ua_flags);
271+
} else {
272+
n = __copy_from_user_memcpy(to, from, n);
273+
}
274+
return n;
267275
}
268276

269277
static unsigned long noinline

0 commit comments

Comments
 (0)