Skip to content

Commit 49f10dd

Browse files
keesAlex Shi
authored andcommitted
ARM: uaccess: Enable hardened usercopy
Enables CONFIG_HARDENED_USERCOPY checks on arm. Based on code from PaX and grsecurity. Signed-off-by: Kees Cook <keescook@chromium.org> (cherry picked from commit dfd45b6103c973bfcea2341d89e36faf947dbc33) Signed-off-by: Alex Shi <alex.shi@linaro.org>
1 parent 4f80bcb commit 49f10dd

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

arch/arm/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ config ARM
3535
select HAVE_ARCH_BITREVERSE if (CPU_32v7M || CPU_32v7) && !CPU_32v6
3636
select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL && !CPU_ENDIAN_BE32
3737
select HAVE_ARCH_KGDB if !CPU_ENDIAN_BE32
38+
select HAVE_ARCH_HARDENED_USERCOPY
3839
select HAVE_ARCH_SECCOMP_FILTER if (AEABI && !OABI_COMPAT)
3940
select HAVE_ARCH_TRACEHOOK
4041
select HAVE_BPF_JIT

arch/arm/include/asm/uaccess.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,10 @@ arm_copy_from_user(void *to, const void __user *from, unsigned long n);
496496
static inline unsigned long __must_check
497497
__copy_from_user(void *to, const void __user *from, unsigned long n)
498498
{
499-
unsigned int __ua_flags = uaccess_save_and_enable();
499+
unsigned int __ua_flags;
500+
501+
check_object_size(to, n, false);
502+
__ua_flags = uaccess_save_and_enable();
500503
n = arm_copy_from_user(to, from, n);
501504
uaccess_restore(__ua_flags);
502505
return n;
@@ -511,11 +514,15 @@ static inline unsigned long __must_check
511514
__copy_to_user(void __user *to, const void *from, unsigned long n)
512515
{
513516
#ifndef CONFIG_UACCESS_WITH_MEMCPY
514-
unsigned int __ua_flags = uaccess_save_and_enable();
517+
unsigned int __ua_flags;
518+
519+
check_object_size(from, n, true);
520+
__ua_flags = uaccess_save_and_enable();
515521
n = arm_copy_to_user(to, from, n);
516522
uaccess_restore(__ua_flags);
517523
return n;
518524
#else
525+
check_object_size(from, n, true);
519526
return arm_copy_to_user(to, from, n);
520527
#endif
521528
}

0 commit comments

Comments
 (0)