aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Poimboeuf <jpoimboe@redhat.com>2016-08-30 09:04:16 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-08-30 13:10:21 -0400
commit0d025d271e55f3de21f0aaaf54b42d20404d2b23 (patch)
tree0366bf0d52f018949b221276948224abed2c25ad
parentd8dc020cac1d5335cab3ffadb1964ad83c2f8729 (diff)
mm/usercopy: get rid of CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
There are three usercopy warnings which are currently being silenced for gcc 4.6 and newer: 1) "copy_from_user() buffer size is too small" compile warning/error This is a static warning which happens when object size and copy size are both const, and copy size > object size. I didn't see any false positives for this one. So the function warning attribute seems to be working fine here. Note this scenario is always a bug and so I think it should be changed to *always* be an error, regardless of CONFIG_DEBUG_STRICT_USER_COPY_CHECKS. 2) "copy_from_user() buffer size is not provably correct" compile warning This is another static warning which happens when I enable __compiletime_object_size() for new compilers (and CONFIG_DEBUG_STRICT_USER_COPY_CHECKS). It happens when object size is const, but copy size is *not*. In this case there's no way to compare the two at build time, so it gives the warning. (Note the warning is a byproduct of the fact that gcc has no way of knowing whether the overflow function will be called, so the call isn't dead code and the warning attribute is activated.) So this warning seems to only indicate "this is an unusual pattern, maybe you should check it out" rather than "this is a bug". I get 102(!) of these warnings with allyesconfig and the __compiletime_object_size() gcc check removed. I don't know if there are any real bugs hiding in there, but from looking at a small sample, I didn't see any. According to Kees, it does sometimes find real bugs. But the false positive rate seems high. 3) "Buffer overflow detected" runtime warning This is a runtime warning where object size is const, and copy size > object size. All three warnings (both static and runtime) were completely disabled for gcc 4.6 with the following commit: 2fb0815c9ee6 ("gcc4: disable __compiletime_object_size for GCC 4.6+") That commit mistakenly assumed that the false positives were caused by a gcc bug in __compiletime_object_size(). But in fact, __compiletime_object_size() seems to be working fine. The false positives were instead triggered by #2 above. (Though I don't have an explanation for why the warnings supposedly only started showing up in gcc 4.6.) So remove warning #2 to get rid of all the false positives, and re-enable warnings #1 and #3 by reverting the above commit. Furthermore, since #1 is a real bug which is detected at compile time, upgrade it to always be an error. Having done all that, CONFIG_DEBUG_STRICT_USER_COPY_CHECKS is no longer needed. Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Kees Cook <keescook@chromium.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@kernel.org> Cc: "H . Peter Anvin" <hpa@zytor.com> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Brian Gerst <brgerst@gmail.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Byungchul Park <byungchul.park@lge.com> Cc: Nilay Vaish <nilayvaish@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--arch/parisc/Kconfig1
-rw-r--r--arch/parisc/configs/c8000_defconfig1
-rw-r--r--arch/parisc/configs/generic-64bit_defconfig1
-rw-r--r--arch/parisc/include/asm/uaccess.h22
-rw-r--r--arch/s390/Kconfig1
-rw-r--r--arch/s390/configs/default_defconfig1
-rw-r--r--arch/s390/configs/gcov_defconfig1
-rw-r--r--arch/s390/configs/performance_defconfig1
-rw-r--r--arch/s390/defconfig1
-rw-r--r--arch/s390/include/asm/uaccess.h19
-rw-r--r--arch/tile/Kconfig1
-rw-r--r--arch/tile/include/asm/uaccess.h22
-rw-r--r--arch/x86/Kconfig1
-rw-r--r--arch/x86/include/asm/uaccess.h69
-rw-r--r--include/asm-generic/uaccess.h1
-rw-r--r--include/linux/compiler-gcc.h2
-rw-r--r--lib/Kconfig.debug18
-rw-r--r--lib/Makefile1
-rw-r--r--lib/usercopy.c9
19 files changed, 45 insertions, 128 deletions
diff --git a/arch/parisc/Kconfig b/arch/parisc/Kconfig
index cd8778103165..af12c2db9bb8 100644
--- a/arch/parisc/Kconfig
+++ b/arch/parisc/Kconfig
@@ -1,6 +1,5 @@
1config PARISC 1config PARISC
2 def_bool y 2 def_bool y
3 select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
4 select ARCH_MIGHT_HAVE_PC_PARPORT 3 select ARCH_MIGHT_HAVE_PC_PARPORT
5 select HAVE_IDE 4 select HAVE_IDE
6 select HAVE_OPROFILE 5 select HAVE_OPROFILE
diff --git a/arch/parisc/configs/c8000_defconfig b/arch/parisc/configs/c8000_defconfig
index 1a8f6f95689e..f6a4c016304b 100644
--- a/arch/parisc/configs/c8000_defconfig
+++ b/arch/parisc/configs/c8000_defconfig
@@ -245,7 +245,6 @@ CONFIG_DEBUG_RT_MUTEXES=y
245CONFIG_PROVE_RCU_DELAY=y 245CONFIG_PROVE_RCU_DELAY=y
246CONFIG_DEBUG_BLOCK_EXT_DEVT=y 246CONFIG_DEBUG_BLOCK_EXT_DEVT=y
247CONFIG_LATENCYTOP=y 247CONFIG_LATENCYTOP=y
248CONFIG_DEBUG_STRICT_USER_COPY_CHECKS=y
249CONFIG_KEYS=y 248CONFIG_KEYS=y
250# CONFIG_CRYPTO_HW is not set 249# CONFIG_CRYPTO_HW is not set
251CONFIG_FONTS=y 250CONFIG_FONTS=y
diff --git a/arch/parisc/configs/generic-64bit_defconfig b/arch/parisc/configs/generic-64bit_defconfig
index 7e0792658952..c564e6e1fa23 100644
--- a/arch/parisc/configs/generic-64bit_defconfig
+++ b/arch/parisc/configs/generic-64bit_defconfig
@@ -291,7 +291,6 @@ CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC=y
291CONFIG_BOOTPARAM_HUNG_TASK_PANIC=y 291CONFIG_BOOTPARAM_HUNG_TASK_PANIC=y
292# CONFIG_SCHED_DEBUG is not set 292# CONFIG_SCHED_DEBUG is not set
293CONFIG_TIMER_STATS=y 293CONFIG_TIMER_STATS=y
294CONFIG_DEBUG_STRICT_USER_COPY_CHECKS=y
295CONFIG_CRYPTO_MANAGER=y 294CONFIG_CRYPTO_MANAGER=y
296CONFIG_CRYPTO_ECB=m 295CONFIG_CRYPTO_ECB=m
297CONFIG_CRYPTO_PCBC=m 296CONFIG_CRYPTO_PCBC=m
diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
index 0f59fd9ca205..e9150487e20d 100644
--- a/arch/parisc/include/asm/uaccess.h
+++ b/arch/parisc/include/asm/uaccess.h
@@ -208,13 +208,13 @@ unsigned long copy_in_user(void __user *dst, const void __user *src, unsigned lo
208#define __copy_to_user_inatomic __copy_to_user 208#define __copy_to_user_inatomic __copy_to_user
209#define __copy_from_user_inatomic __copy_from_user 209#define __copy_from_user_inatomic __copy_from_user
210 210
211extern void copy_from_user_overflow(void) 211extern void __compiletime_error("usercopy buffer size is too small")
212#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS 212__bad_copy_user(void);
213 __compiletime_error("copy_from_user() buffer size is not provably correct") 213
214#else 214static inline void copy_user_overflow(int size, unsigned long count)
215 __compiletime_warning("copy_from_user() buffer size is not provably correct") 215{
216#endif 216 WARN(1, "Buffer overflow detected (%d < %lu)!\n", size, count);
217; 217}
218 218
219static inline unsigned long __must_check copy_from_user(void *to, 219static inline unsigned long __must_check copy_from_user(void *to,
220 const void __user *from, 220 const void __user *from,
@@ -223,10 +223,12 @@ static inline unsigned long __must_check copy_from_user(void *to,
223 int sz = __compiletime_object_size(to); 223 int sz = __compiletime_object_size(to);
224 int ret = -EFAULT; 224 int ret = -EFAULT;
225 225
226 if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n)) 226 if (likely(sz == -1 || sz >= n))
227 ret = __copy_from_user(to, from, n); 227 ret = __copy_from_user(to, from, n);
228 else 228 else if (!__builtin_constant_p(n))
229 copy_from_user_overflow(); 229 copy_user_overflow(sz, n);
230 else
231 __bad_copy_user();
230 232
231 return ret; 233 return ret;
232} 234}
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index e751fe25d6ab..c109f073d454 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -68,7 +68,6 @@ config DEBUG_RODATA
68config S390 68config S390
69 def_bool y 69 def_bool y
70 select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE 70 select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
71 select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
72 select ARCH_HAS_DEVMEM_IS_ALLOWED 71 select ARCH_HAS_DEVMEM_IS_ALLOWED
73 select ARCH_HAS_ELF_RANDOMIZE 72 select ARCH_HAS_ELF_RANDOMIZE
74 select ARCH_HAS_GCOV_PROFILE_ALL 73 select ARCH_HAS_GCOV_PROFILE_ALL
diff --git a/arch/s390/configs/default_defconfig b/arch/s390/configs/default_defconfig
index 26e0c7f08814..412b1bd21029 100644
--- a/arch/s390/configs/default_defconfig
+++ b/arch/s390/configs/default_defconfig
@@ -602,7 +602,6 @@ CONFIG_FAIL_FUTEX=y
602CONFIG_FAULT_INJECTION_DEBUG_FS=y 602CONFIG_FAULT_INJECTION_DEBUG_FS=y
603CONFIG_FAULT_INJECTION_STACKTRACE_FILTER=y 603CONFIG_FAULT_INJECTION_STACKTRACE_FILTER=y
604CONFIG_LATENCYTOP=y 604CONFIG_LATENCYTOP=y
605CONFIG_DEBUG_STRICT_USER_COPY_CHECKS=y
606CONFIG_IRQSOFF_TRACER=y 605CONFIG_IRQSOFF_TRACER=y
607CONFIG_PREEMPT_TRACER=y 606CONFIG_PREEMPT_TRACER=y
608CONFIG_SCHED_TRACER=y 607CONFIG_SCHED_TRACER=y
diff --git a/arch/s390/configs/gcov_defconfig b/arch/s390/configs/gcov_defconfig
index 24879dab47bc..bec279eb4b93 100644
--- a/arch/s390/configs/gcov_defconfig
+++ b/arch/s390/configs/gcov_defconfig
@@ -552,7 +552,6 @@ CONFIG_NOTIFIER_ERROR_INJECTION=m
552CONFIG_CPU_NOTIFIER_ERROR_INJECT=m 552CONFIG_CPU_NOTIFIER_ERROR_INJECT=m
553CONFIG_PM_NOTIFIER_ERROR_INJECT=m 553CONFIG_PM_NOTIFIER_ERROR_INJECT=m
554CONFIG_LATENCYTOP=y 554CONFIG_LATENCYTOP=y
555CONFIG_DEBUG_STRICT_USER_COPY_CHECKS=y
556CONFIG_BLK_DEV_IO_TRACE=y 555CONFIG_BLK_DEV_IO_TRACE=y
557# CONFIG_KPROBE_EVENT is not set 556# CONFIG_KPROBE_EVENT is not set
558CONFIG_TRACE_ENUM_MAP_FILE=y 557CONFIG_TRACE_ENUM_MAP_FILE=y
diff --git a/arch/s390/configs/performance_defconfig b/arch/s390/configs/performance_defconfig
index a5c1e5f2a0ca..1751446a5bbb 100644
--- a/arch/s390/configs/performance_defconfig
+++ b/arch/s390/configs/performance_defconfig
@@ -549,7 +549,6 @@ CONFIG_TIMER_STATS=y
549CONFIG_RCU_TORTURE_TEST=m 549CONFIG_RCU_TORTURE_TEST=m
550CONFIG_RCU_CPU_STALL_TIMEOUT=60 550CONFIG_RCU_CPU_STALL_TIMEOUT=60
551CONFIG_LATENCYTOP=y 551CONFIG_LATENCYTOP=y
552CONFIG_DEBUG_STRICT_USER_COPY_CHECKS=y
553CONFIG_SCHED_TRACER=y 552CONFIG_SCHED_TRACER=y
554CONFIG_FTRACE_SYSCALLS=y 553CONFIG_FTRACE_SYSCALLS=y
555CONFIG_STACK_TRACER=y 554CONFIG_STACK_TRACER=y
diff --git a/arch/s390/defconfig b/arch/s390/defconfig
index 73610f2e3b4f..2d40ef0a6295 100644
--- a/arch/s390/defconfig
+++ b/arch/s390/defconfig
@@ -172,7 +172,6 @@ CONFIG_DEBUG_NOTIFIERS=y
172CONFIG_RCU_CPU_STALL_TIMEOUT=60 172CONFIG_RCU_CPU_STALL_TIMEOUT=60
173CONFIG_RCU_TRACE=y 173CONFIG_RCU_TRACE=y
174CONFIG_LATENCYTOP=y 174CONFIG_LATENCYTOP=y
175CONFIG_DEBUG_STRICT_USER_COPY_CHECKS=y
176CONFIG_SCHED_TRACER=y 175CONFIG_SCHED_TRACER=y
177CONFIG_FTRACE_SYSCALLS=y 176CONFIG_FTRACE_SYSCALLS=y
178CONFIG_TRACER_SNAPSHOT_PER_CPU_SWAP=y 177CONFIG_TRACER_SNAPSHOT_PER_CPU_SWAP=y
diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
index 9b49cf1daa8f..95aefdba4be2 100644
--- a/arch/s390/include/asm/uaccess.h
+++ b/arch/s390/include/asm/uaccess.h
@@ -311,6 +311,14 @@ int __get_user_bad(void) __attribute__((noreturn));
311#define __put_user_unaligned __put_user 311#define __put_user_unaligned __put_user
312#define __get_user_unaligned __get_user 312#define __get_user_unaligned __get_user
313 313
314extern void __compiletime_error("usercopy buffer size is too small")
315__bad_copy_user(void);
316
317static inline void copy_user_overflow(int size, unsigned long count)
318{
319 WARN(1, "Buffer overflow detected (%d < %lu)!\n", size, count);
320}
321
314/** 322/**
315 * copy_to_user: - Copy a block of data into user space. 323 * copy_to_user: - Copy a block of data into user space.
316 * @to: Destination address, in user space. 324 * @to: Destination address, in user space.
@@ -332,12 +340,6 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
332 return __copy_to_user(to, from, n); 340 return __copy_to_user(to, from, n);
333} 341}
334 342
335void copy_from_user_overflow(void)
336#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
337__compiletime_warning("copy_from_user() buffer size is not provably correct")
338#endif
339;
340
341/** 343/**
342 * copy_from_user: - Copy a block of data from user space. 344 * copy_from_user: - Copy a block of data from user space.
343 * @to: Destination address, in kernel space. 345 * @to: Destination address, in kernel space.
@@ -362,7 +364,10 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
362 364
363 might_fault(); 365 might_fault();
364 if (unlikely(sz != -1 && sz < n)) { 366 if (unlikely(sz != -1 && sz < n)) {
365 copy_from_user_overflow(); 367 if (!__builtin_constant_p(n))
368 copy_user_overflow(sz, n);
369 else
370 __bad_copy_user();
366 return n; 371 return n;
367 } 372 }
368 return __copy_from_user(to, from, n); 373 return __copy_from_user(to, from, n);
diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
index 4820a02838ac..78da75b670bc 100644
--- a/arch/tile/Kconfig
+++ b/arch/tile/Kconfig
@@ -4,7 +4,6 @@
4config TILE 4config TILE
5 def_bool y 5 def_bool y
6 select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE 6 select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
7 select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
8 select ARCH_HAS_DEVMEM_IS_ALLOWED 7 select ARCH_HAS_DEVMEM_IS_ALLOWED
9 select ARCH_HAVE_NMI_SAFE_CMPXCHG 8 select ARCH_HAVE_NMI_SAFE_CMPXCHG
10 select ARCH_WANT_FRAME_POINTERS 9 select ARCH_WANT_FRAME_POINTERS
diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
index 0a9c4265763b..a77369e91e54 100644
--- a/arch/tile/include/asm/uaccess.h
+++ b/arch/tile/include/asm/uaccess.h
@@ -416,14 +416,13 @@ _copy_from_user(void *to, const void __user *from, unsigned long n)
416 return n; 416 return n;
417} 417}
418 418
419#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS 419extern void __compiletime_error("usercopy buffer size is too small")
420/* 420__bad_copy_user(void);
421 * There are still unprovable places in the generic code as of 2.6.34, so this 421
422 * option is not really compatible with -Werror, which is more useful in 422static inline void copy_user_overflow(int size, unsigned long count)
423 * general. 423{
424 */ 424 WARN(1, "Buffer overflow detected (%d < %lu)!\n", size, count);
425extern void copy_from_user_overflow(void) 425}
426 __compiletime_warning("copy_from_user() size is not provably correct");
427 426
428static inline unsigned long __must_check copy_from_user(void *to, 427static inline unsigned long __must_check copy_from_user(void *to,
429 const void __user *from, 428 const void __user *from,
@@ -433,14 +432,13 @@ static inline unsigned long __must_check copy_from_user(void *to,
433 432
434 if (likely(sz == -1 || sz >= n)) 433 if (likely(sz == -1 || sz >= n))
435 n = _copy_from_user(to, from, n); 434 n = _copy_from_user(to, from, n);
435 else if (!__builtin_constant_p(n))
436 copy_user_overflow(sz, n);
436 else 437 else
437 copy_from_user_overflow(); 438 __bad_copy_user();
438 439
439 return n; 440 return n;
440} 441}
441#else
442#define copy_from_user _copy_from_user
443#endif
444 442
445#ifdef __tilegx__ 443#ifdef __tilegx__
446/** 444/**
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index c580d8c33562..2a1f0ce7c59a 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -24,7 +24,6 @@ config X86
24 select ARCH_DISCARD_MEMBLOCK 24 select ARCH_DISCARD_MEMBLOCK
25 select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI 25 select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI
26 select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE 26 select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
27 select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
28 select ARCH_HAS_DEVMEM_IS_ALLOWED 27 select ARCH_HAS_DEVMEM_IS_ALLOWED
29 select ARCH_HAS_ELF_RANDOMIZE 28 select ARCH_HAS_ELF_RANDOMIZE
30 select ARCH_HAS_FAST_MULTIPLIER 29 select ARCH_HAS_FAST_MULTIPLIER
diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index a0ae610b9280..c3f291195294 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -697,43 +697,14 @@ unsigned long __must_check _copy_from_user(void *to, const void __user *from,
697unsigned long __must_check _copy_to_user(void __user *to, const void *from, 697unsigned long __must_check _copy_to_user(void __user *to, const void *from,
698 unsigned n); 698 unsigned n);
699 699
700#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS 700extern void __compiletime_error("usercopy buffer size is too small")
701# define copy_user_diag __compiletime_error 701__bad_copy_user(void);
702#else
703# define copy_user_diag __compiletime_warning
704#endif
705
706extern void copy_user_diag("copy_from_user() buffer size is too small")
707copy_from_user_overflow(void);
708extern void copy_user_diag("copy_to_user() buffer size is too small")
709copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
710
711#undef copy_user_diag
712
713#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
714
715extern void
716__compiletime_warning("copy_from_user() buffer size is not provably correct")
717__copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
718#define __copy_from_user_overflow(size, count) __copy_from_user_overflow()
719
720extern void
721__compiletime_warning("copy_to_user() buffer size is not provably correct")
722__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
723#define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
724
725#else
726 702
727static inline void 703static inline void copy_user_overflow(int size, unsigned long count)
728__copy_from_user_overflow(int size, unsigned long count)
729{ 704{
730 WARN(1, "Buffer overflow detected (%d < %lu)!\n", size, count); 705 WARN(1, "Buffer overflow detected (%d < %lu)!\n", size, count);
731} 706}
732 707
733#define __copy_to_user_overflow __copy_from_user_overflow
734
735#endif
736
737static inline unsigned long __must_check 708static inline unsigned long __must_check
738copy_from_user(void *to, const void __user *from, unsigned long n) 709copy_from_user(void *to, const void __user *from, unsigned long n)
739{ 710{
@@ -743,31 +714,13 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
743 714
744 kasan_check_write(to, n); 715 kasan_check_write(to, n);
745 716
746 /*
747 * While we would like to have the compiler do the checking for us
748 * even in the non-constant size case, any false positives there are
749 * a problem (especially when DEBUG_STRICT_USER_COPY_CHECKS, but even
750 * without - the [hopefully] dangerous looking nature of the warning
751 * would make people go look at the respecitive call sites over and
752 * over again just to find that there's no problem).
753 *
754 * And there are cases where it's just not realistic for the compiler
755 * to prove the count to be in range. For example when multiple call
756 * sites of a helper function - perhaps in different source files -
757 * all doing proper range checking, yet the helper function not doing
758 * so again.
759 *
760 * Therefore limit the compile time checking to the constant size
761 * case, and do only runtime checking for non-constant sizes.
762 */
763
764 if (likely(sz < 0 || sz >= n)) { 717 if (likely(sz < 0 || sz >= n)) {
765 check_object_size(to, n, false); 718 check_object_size(to, n, false);
766 n = _copy_from_user(to, from, n); 719 n = _copy_from_user(to, from, n);
767 } else if (__builtin_constant_p(n)) 720 } else if (!__builtin_constant_p(n))
768 copy_from_user_overflow(); 721 copy_user_overflow(sz, n);
769 else 722 else
770 __copy_from_user_overflow(sz, n); 723 __bad_copy_user();
771 724
772 return n; 725 return n;
773} 726}
@@ -781,21 +734,17 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
781 734
782 might_fault(); 735 might_fault();
783 736
784 /* See the comment in copy_from_user() above. */
785 if (likely(sz < 0 || sz >= n)) { 737 if (likely(sz < 0 || sz >= n)) {
786 check_object_size(from, n, true); 738 check_object_size(from, n, true);
787 n = _copy_to_user(to, from, n); 739 n = _copy_to_user(to, from, n);
788 } else if (__builtin_constant_p(n)) 740 } else if (!__builtin_constant_p(n))
789 copy_to_user_overflow(); 741 copy_user_overflow(sz, n);
790 else 742 else
791 __copy_to_user_overflow(sz, n); 743 __bad_copy_user();
792 744
793 return n; 745 return n;
794} 746}
795 747
796#undef __copy_from_user_overflow
797#undef __copy_to_user_overflow
798
799/* 748/*
800 * We rely on the nested NMI work to allow atomic faults from the NMI path; the 749 * We rely on the nested NMI work to allow atomic faults from the NMI path; the
801 * nested NMI paths are careful to preserve CR2. 750 * nested NMI paths are careful to preserve CR2.
diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
index 1bfa602958f2..5dea1fb6979c 100644
--- a/include/asm-generic/uaccess.h
+++ b/include/asm-generic/uaccess.h
@@ -72,6 +72,7 @@ struct exception_table_entry
72/* Returns 0 if exception not found and fixup otherwise. */ 72/* Returns 0 if exception not found and fixup otherwise. */
73extern unsigned long search_exception_table(unsigned long); 73extern unsigned long search_exception_table(unsigned long);
74 74
75
75/* 76/*
76 * architectures with an MMU should override these two 77 * architectures with an MMU should override these two
77 */ 78 */
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 8dbc8929a6a0..573c5a18908f 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -158,7 +158,7 @@
158#define __compiler_offsetof(a, b) \ 158#define __compiler_offsetof(a, b) \
159 __builtin_offsetof(a, b) 159 __builtin_offsetof(a, b)
160 160
161#if GCC_VERSION >= 40100 && GCC_VERSION < 40600 161#if GCC_VERSION >= 40100
162# define __compiletime_object_size(obj) __builtin_object_size(obj, 0) 162# define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
163#endif 163#endif
164 164
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 2307d7c89dac..2e2cca509231 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1686,24 +1686,6 @@ config LATENCYTOP
1686 Enable this option if you want to use the LatencyTOP tool 1686 Enable this option if you want to use the LatencyTOP tool
1687 to find out which userspace is blocking on what kernel operations. 1687 to find out which userspace is blocking on what kernel operations.
1688 1688
1689config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
1690 bool
1691
1692config DEBUG_STRICT_USER_COPY_CHECKS
1693 bool "Strict user copy size checks"
1694 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
1695 depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
1696 help
1697 Enabling this option turns a certain set of sanity checks for user
1698 copy operations into compile time failures.
1699
1700 The copy_from_user() etc checks are there to help test if there
1701 are sufficient security checks on the length argument of
1702 the copy operation, by having gcc prove that the argument is
1703 within bounds.
1704
1705 If unsure, say N.
1706
1707source kernel/trace/Kconfig 1689source kernel/trace/Kconfig
1708 1690
1709menu "Runtime Testing" 1691menu "Runtime Testing"
diff --git a/lib/Makefile b/lib/Makefile
index cfa68eb269e4..5dc77a8ec297 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -24,7 +24,6 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
24 is_single_threaded.o plist.o decompress.o kobject_uevent.o \ 24 is_single_threaded.o plist.o decompress.o kobject_uevent.o \
25 earlycpio.o seq_buf.o nmi_backtrace.o nodemask.o 25 earlycpio.o seq_buf.o nmi_backtrace.o nodemask.o
26 26
27obj-$(CONFIG_ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS) += usercopy.o
28lib-$(CONFIG_MMU) += ioremap.o 27lib-$(CONFIG_MMU) += ioremap.o
29lib-$(CONFIG_SMP) += cpumask.o 28lib-$(CONFIG_SMP) += cpumask.o
30lib-$(CONFIG_HAS_DMA) += dma-noop.o 29lib-$(CONFIG_HAS_DMA) += dma-noop.o
diff --git a/lib/usercopy.c b/lib/usercopy.c
deleted file mode 100644
index 4f5b1ddbcd25..000000000000
--- a/lib/usercopy.c
+++ /dev/null
@@ -1,9 +0,0 @@
1#include <linux/export.h>
2#include <linux/bug.h>
3#include <linux/uaccess.h>
4
5void copy_from_user_overflow(void)
6{
7 WARN(1, "Buffer overflow detected!\n");
8}
9EXPORT_SYMBOL(copy_from_user_overflow);