提交 1d3c1324 编写于 作者: K Kees Cook

powerpc/uaccess: Enable hardened usercopy

Enables CONFIG_HARDENED_USERCOPY checks on powerpc.

Based on code from PaX and grsecurity.
Signed-off-by: NKees Cook <keescook@chromium.org>
Tested-by: NMichael Ellerman <mpe@ellerman.id.au>
上级 73d35887
...@@ -164,6 +164,7 @@ config PPC ...@@ -164,6 +164,7 @@ config PPC
select ARCH_HAS_UBSAN_SANITIZE_ALL select ARCH_HAS_UBSAN_SANITIZE_ALL
select ARCH_SUPPORTS_DEFERRED_STRUCT_PAGE_INIT select ARCH_SUPPORTS_DEFERRED_STRUCT_PAGE_INIT
select HAVE_LIVEPATCH if HAVE_DYNAMIC_FTRACE_WITH_REGS select HAVE_LIVEPATCH if HAVE_DYNAMIC_FTRACE_WITH_REGS
select HAVE_ARCH_HARDENED_USERCOPY
config GENERIC_CSUM config GENERIC_CSUM
def_bool CPU_LITTLE_ENDIAN def_bool CPU_LITTLE_ENDIAN
......
...@@ -310,10 +310,15 @@ static inline unsigned long copy_from_user(void *to, ...@@ -310,10 +310,15 @@ static inline unsigned long copy_from_user(void *to,
{ {
unsigned long over; unsigned long over;
if (access_ok(VERIFY_READ, from, n)) if (access_ok(VERIFY_READ, from, n)) {
if (!__builtin_constant_p(n))
check_object_size(to, n, false);
return __copy_tofrom_user((__force void __user *)to, from, n); return __copy_tofrom_user((__force void __user *)to, from, n);
}
if ((unsigned long)from < TASK_SIZE) { if ((unsigned long)from < TASK_SIZE) {
over = (unsigned long)from + n - TASK_SIZE; over = (unsigned long)from + n - TASK_SIZE;
if (!__builtin_constant_p(n - over))
check_object_size(to, n - over, false);
return __copy_tofrom_user((__force void __user *)to, from, return __copy_tofrom_user((__force void __user *)to, from,
n - over) + over; n - over) + over;
} }
...@@ -325,10 +330,15 @@ static inline unsigned long copy_to_user(void __user *to, ...@@ -325,10 +330,15 @@ static inline unsigned long copy_to_user(void __user *to,
{ {
unsigned long over; unsigned long over;
if (access_ok(VERIFY_WRITE, to, n)) if (access_ok(VERIFY_WRITE, to, n)) {
if (!__builtin_constant_p(n))
check_object_size(from, n, true);
return __copy_tofrom_user(to, (__force void __user *)from, n); return __copy_tofrom_user(to, (__force void __user *)from, n);
}
if ((unsigned long)to < TASK_SIZE) { if ((unsigned long)to < TASK_SIZE) {
over = (unsigned long)to + n - TASK_SIZE; over = (unsigned long)to + n - TASK_SIZE;
if (!__builtin_constant_p(n))
check_object_size(from, n - over, true);
return __copy_tofrom_user(to, (__force void __user *)from, return __copy_tofrom_user(to, (__force void __user *)from,
n - over) + over; n - over) + over;
} }
...@@ -372,6 +382,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to, ...@@ -372,6 +382,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
if (ret == 0) if (ret == 0)
return 0; return 0;
} }
if (!__builtin_constant_p(n))
check_object_size(to, n, false);
return __copy_tofrom_user((__force void __user *)to, from, n); return __copy_tofrom_user((__force void __user *)to, from, n);
} }
...@@ -398,6 +412,9 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to, ...@@ -398,6 +412,9 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
if (ret == 0) if (ret == 0)
return 0; return 0;
} }
if (!__builtin_constant_p(n))
check_object_size(from, n, true);
return __copy_tofrom_user(to, (__force const void __user *)from, n); return __copy_tofrom_user(to, (__force const void __user *)from, n);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册