Commit 50013ead authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Greg Kroah-Hartman

mm/uaccess: Use 'unsigned long' to placate UBSAN warnings on older GCC versions

[ Upstream commit 29da93fe ]

Randy reported objtool triggered on his (GCC-7.4) build:

  lib/strncpy_from_user.o: warning: objtool: strncpy_from_user()+0x315: call to __ubsan_handle_add_overflow() with UACCESS enabled
  lib/strnlen_user.o: warning: objtool: strnlen_user()+0x337: call to __ubsan_handle_sub_overflow() with UACCESS enabled

This is due to UBSAN generating signed-overflow-UB warnings where it
should not. Prior to GCC-8 UBSAN ignored -fwrapv (which the kernel
uses through -fno-strict-overflow).

Make the functions use 'unsigned long' throughout.
Reported-by: default avatarRandy Dunlap <rdunlap@infradead.org>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested
Acked-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: luto@kernel.org
Link: http://lkml.kernel.org/r/20190424072208.754094071@infradead.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent f08f10f7
...@@ -22,10 +22,11 @@ ...@@ -22,10 +22,11 @@
* hit it), 'max' is the address space maximum (and we return * hit it), 'max' is the address space maximum (and we return
* -EFAULT if we hit it). * -EFAULT if we hit it).
*/ */
static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max) static inline long do_strncpy_from_user(char *dst, const char __user *src,
unsigned long count, unsigned long max)
{ {
const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS; const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
long res = 0; unsigned long res = 0;
/* /*
* Truncate 'max' to the user-specified limit, so that * Truncate 'max' to the user-specified limit, so that
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max) static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
{ {
const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS; const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
long align, res = 0; unsigned long align, res = 0;
unsigned long c; unsigned long c;
/* /*
...@@ -41,7 +41,7 @@ static inline long do_strnlen_user(const char __user *src, unsigned long count, ...@@ -41,7 +41,7 @@ static inline long do_strnlen_user(const char __user *src, unsigned long count,
* Do everything aligned. But that means that we * Do everything aligned. But that means that we
* need to also expand the maximum.. * need to also expand the maximum..
*/ */
align = (sizeof(long) - 1) & (unsigned long)src; align = (sizeof(unsigned long) - 1) & (unsigned long)src;
src -= align; src -= align;
max += align; max += align;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment