Skip to content

Commit 17427c2

Browse files
keesAlex Shi
authored andcommitted
sparc/uaccess: Enable hardened usercopy
Enables CONFIG_HARDENED_USERCOPY checks on sparc. Based on code from PaX and grsecurity. Signed-off-by: Kees Cook <keescook@chromium.org> (cherry picked from commit 9d9208a15800f9f06f102f9aac1e8b323c3b8575) Signed-off-by: Alex Shi <alex.shi@linaro.org>
1 parent 225237b commit 17427c2

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

arch/sparc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ config SPARC
4343
select ODD_RT_SIGACTION
4444
select OLD_SIGSUSPEND
4545
select ARCH_HAS_SG_CHAIN
46+
select HAVE_ARCH_HARDENED_USERCOPY
4647

4748
config SPARC32
4849
def_bool !64BIT

arch/sparc/include/asm/uaccess_32.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,22 +313,28 @@ unsigned long __copy_user(void __user *to, const void __user *from, unsigned lon
313313

314314
static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
315315
{
316-
if (n && __access_ok((unsigned long) to, n))
316+
if (n && __access_ok((unsigned long) to, n)) {
317+
if (!__builtin_constant_p(n))
318+
check_object_size(from, n, true);
317319
return __copy_user(to, (__force void __user *) from, n);
318-
else
320+
} else
319321
return n;
320322
}
321323

322324
static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
323325
{
326+
if (!__builtin_constant_p(n))
327+
check_object_size(from, n, true);
324328
return __copy_user(to, (__force void __user *) from, n);
325329
}
326330

327331
static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
328332
{
329-
if (n && __access_ok((unsigned long) from, n))
333+
if (n && __access_ok((unsigned long) from, n)) {
334+
if (!__builtin_constant_p(n))
335+
check_object_size(to, n, false);
330336
return __copy_user((__force void __user *) to, from, n);
331-
else
337+
} else
332338
return n;
333339
}
334340

arch/sparc/include/asm/uaccess_64.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,12 @@ unsigned long copy_from_user_fixup(void *to, const void __user *from,
250250
static inline unsigned long __must_check
251251
copy_from_user(void *to, const void __user *from, unsigned long size)
252252
{
253-
unsigned long ret = ___copy_from_user(to, from, size);
253+
unsigned long ret;
254254

255+
if (!__builtin_constant_p(size))
256+
check_object_size(to, size, false);
257+
258+
ret = ___copy_from_user(to, from, size);
255259
if (unlikely(ret))
256260
ret = copy_from_user_fixup(to, from, size);
257261

@@ -267,8 +271,11 @@ unsigned long copy_to_user_fixup(void __user *to, const void *from,
267271
static inline unsigned long __must_check
268272
copy_to_user(void __user *to, const void *from, unsigned long size)
269273
{
270-
unsigned long ret = ___copy_to_user(to, from, size);
274+
unsigned long ret;
271275

276+
if (!__builtin_constant_p(size))
277+
check_object_size(from, size, true);
278+
ret = ___copy_to_user(to, from, size);
272279
if (unlikely(ret))
273280
ret = copy_to_user_fixup(to, from, size);
274281
return ret;

0 commit comments

Comments
 (0)