Skip to content

Commit 225237b

Browse files
keesAlex Shi
authored andcommitted
powerpc/uaccess: Enable hardened usercopy
Enables CONFIG_HARDENED_USERCOPY checks on powerpc. Based on code from PaX and grsecurity. Signed-off-by: Kees Cook <keescook@chromium.org> Tested-by: Michael Ellerman <mpe@ellerman.id.au> (cherry picked from commit 1d3c1324746fed0e34a5b94d3ed303e7521ed603) Signed-off-by: Alex Shi <alex.shi@linaro.org>
1 parent 434bef2 commit 225237b

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

arch/powerpc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ config PPC
160160
select EDAC_ATOMIC_SCRUB
161161
select ARCH_HAS_DMA_SET_COHERENT_MASK
162162
select HAVE_ARCH_SECCOMP_FILTER
163+
select HAVE_ARCH_HARDENED_USERCOPY
163164

164165
config GENERIC_CSUM
165166
def_bool CPU_LITTLE_ENDIAN

arch/powerpc/include/asm/uaccess.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,15 @@ static inline unsigned long copy_from_user(void *to,
325325
{
326326
unsigned long over;
327327

328-
if (access_ok(VERIFY_READ, from, n))
328+
if (access_ok(VERIFY_READ, from, n)) {
329+
if (!__builtin_constant_p(n))
330+
check_object_size(to, n, false);
329331
return __copy_tofrom_user((__force void __user *)to, from, n);
332+
}
330333
if ((unsigned long)from < TASK_SIZE) {
331334
over = (unsigned long)from + n - TASK_SIZE;
335+
if (!__builtin_constant_p(n - over))
336+
check_object_size(to, n - over, false);
332337
return __copy_tofrom_user((__force void __user *)to, from,
333338
n - over) + over;
334339
}
@@ -340,10 +345,15 @@ static inline unsigned long copy_to_user(void __user *to,
340345
{
341346
unsigned long over;
342347

343-
if (access_ok(VERIFY_WRITE, to, n))
348+
if (access_ok(VERIFY_WRITE, to, n)) {
349+
if (!__builtin_constant_p(n))
350+
check_object_size(from, n, true);
344351
return __copy_tofrom_user(to, (__force void __user *)from, n);
352+
}
345353
if ((unsigned long)to < TASK_SIZE) {
346354
over = (unsigned long)to + n - TASK_SIZE;
355+
if (!__builtin_constant_p(n))
356+
check_object_size(from, n - over, true);
347357
return __copy_tofrom_user(to, (__force void __user *)from,
348358
n - over) + over;
349359
}
@@ -387,6 +397,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
387397
if (ret == 0)
388398
return 0;
389399
}
400+
401+
if (!__builtin_constant_p(n))
402+
check_object_size(to, n, false);
403+
390404
return __copy_tofrom_user((__force void __user *)to, from, n);
391405
}
392406

@@ -413,6 +427,9 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
413427
if (ret == 0)
414428
return 0;
415429
}
430+
if (!__builtin_constant_p(n))
431+
check_object_size(from, n, true);
432+
416433
return __copy_tofrom_user(to, (__force const void __user *)from, n);
417434
}
418435

0 commit comments

Comments
 (0)