Consolidate CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
Subsystems (5)
PATCH 1/1 Consolidate CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
The help text for this config is duplicated across the x86, parisc, and s390 Kconfig.debug files. Arnd Bergman noted that the help text was slightly misleading and should be fixed to state that enabling this option isn't a problem when using pre 4.4 gcc.
To simplify the rewording, consolidate the text into lib/Kconfig.debug and modify it there to be more explicit about when you should say N to this config.
Also, make the text a bit more generic by stating that this option enables compile time checks so we can cover architectures which emit warnings vs. ones which emit errors. The details of how an architecture decided to implement the checks isn't as important as the concept of compile time checking of copy_from_user() calls.
While we're doing this, remove all the copy_from_user_overflow() code that's duplicated many times and place it into lib/ so that any architecture supporting this option can get the function for free.
---
Per Helge Deller prodding me, I'm resending just this patch.
https://patchwork.kernel.org/patch/833182/
arch/parisc/Kconfig | 1 + arch/parisc/Kconfig.debug | 14 -------------- arch/s390/Kconfig | 1 + arch/s390/Kconfig.debug | 14 -------------- arch/s390/lib/Makefile | 1 - arch/s390/lib/usercopy.c | 8 -------- arch/sparc/lib/Makefile | 1 - arch/sparc/lib/usercopy.c | 9 --------- arch/tile/Kconfig | 8 +------- arch/tile/include/asm/uaccess.h | 7 ++++++- arch/tile/lib/uaccess.c | 8 -------- arch/x86/Kconfig | 1 + arch/x86/Kconfig.debug | 14 -------------- arch/x86/lib/usercopy_32.c | 6 ------ lib/Kconfig.debug | 18 ++++++++++++++++++ lib/Makefile | 1 + lib/usercopy.c | 9 +++++++++ 17 files changed, 38 insertions(+), 83 deletions(-) delete mode 100644 arch/s390/lib/usercopy.c delete mode 100644 arch/sparc/lib/usercopy.c create mode 100644 lib/usercopy.c
arch/parisc/Kconfig +1 -0
@@ -1,5 +1,6 @@ config PARISC def_bool y + select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS select HAVE_IDE select HAVE_OPROFILE select HAVE_FUNCTION_TRACER if 64BIT
arch/parisc/Kconfig.debug +0 -14
@@ -12,18 +12,4 @@ config DEBUG_RODATA portion of the kernel code won't be covered by a TLB anymore. If in doubt, say "N". -config DEBUG_STRICT_USER_COPY_CHECKS - bool "Strict copy size checks" - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING - ---help--- - Enabling this option turns a certain set of sanity checks for user - copy operations into compile time failures. - - The copy_from_user() etc checks are there to help test if there - are sufficient security checks on the length argument of - the copy operation, by having gcc prove that the argument is - within bounds. - - If unsure, or if you run an older (pre 4.4) gcc, say N. - endmenu
arch/s390/Kconfig +1 -0
@@ -91,6 +91,7 @@ config S390 select ARCH_INLINE_WRITE_UNLOCK_BH select ARCH_INLINE_WRITE_UNLOCK_IRQ select ARCH_INLINE_WRITE_UNLOCK_IRQRESTORE + select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS select ARCH_SAVE_PAGE_KEYS if HIBERNATION select ARCH_WANT_IPC_PARSE_VERSION select BUILDTIME_EXTABLE_SORT
arch/s390/Kconfig.debug +0 -14
@@ -17,20 +17,6 @@ config STRICT_DEVMEM If you are unsure, say Y. -config DEBUG_STRICT_USER_COPY_CHECKS - def_bool n - prompt "Strict user copy size checks" - ---help--- - Enabling this option turns a certain set of sanity checks for user - copy operations into compile time warnings. - - The copy_from_user() etc checks are there to help test if there - are sufficient security checks on the length argument of - the copy operation, by having gcc prove that the argument is - within bounds. - - If unsure, or if you run an older (pre 4.4) gcc, say N. - config S390_PTDUMP bool "Export kernel pagetable layout to userspace via debugfs" depends on DEBUG_KERNEL
arch/s390/lib/Makefile +0 -1
@@ -3,7 +3,6 @@ # lib-y += delay.o string.o uaccess_std.o uaccess_pt.o -obj-y += usercopy.o obj-$(CONFIG_32BIT) += div64.o qrnnd.o ucmpdi2.o mem32.o obj-$(CONFIG_64BIT) += mem64.o lib-$(CONFIG_64BIT) += uaccess_mvcos.o
arch/s390/lib/usercopy.c deleted +0 -8
@@ -1,8 +0,0 @@ -#include <linux/module.h> -#include <linux/bug.h> - -void copy_from_user_overflow (void ) -{ -WARN (1 ,"Buffer overflow detected!\n" ); -} -EXPORT_SYMBOL (copy_from_user_overflow);
arch/sparc/lib/Makefile +0 -1
@@ -45,4 +45,3 @@ obj-y += iomap.o obj-$(CONFIG_SPARC32) += atomic32.o ucmpdi2.o obj-y += ksyms.o obj-$(CONFIG_SPARC64) += PeeCeeI.o -obj-y += usercopy.o
arch/sparc/lib/usercopy.c deleted +0 -9
@@ -1,9 +0,0 @@ -#include <linux/module.h> -#include <linux/kernel.h> -#include <linux/bug.h> - -void copy_from_user_overflow (void ) -{ -WARN (1 ,"Buffer overflow detected!\n" ); -} -EXPORT_SYMBOL (copy_from_user_overflow);
arch/tile/Kconfig +1 -7
@@ -19,6 +19,7 @@ config TILE select HAVE_SYSCALL_WRAPPERS if TILEGX select HAVE_VIRT_TO_BUS select SYS_HYPERVISOR + select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS select ARCH_HAVE_NMI_SAFE_CMPXCHG select GENERIC_CLOCKEVENTS select MODULES_USE_ELF_RELA
@@ -117,13 +118,6 @@ config STRICT_DEVMEM config SMP def_bool y -# Allow checking for compile-time determined overflow errors in -# copy_from_user(). There are still unprovable places in the -# generic code as of 2.6.34, so this option is not really compatible -# with -Werror, which is more useful in general. -config DEBUG_COPY_FROM_USER - def_bool n - config HVC_TILE depends on TTY select HVC_DRIVER
arch/tile/include/asm/uaccess.h +6 -1
@@ -395,7 +395,12 @@ _copy_from_user(void *to, const void __user *from, unsigned long n)return n; } -#ifdef CONFIG_DEBUG_COPY_FROM_USER +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS +/* +* There are still unprovable places in the generic code as of 2.6.34, so this +* option is not really compatible with -Werror, which is more useful in +* general. +*/ extern void copy_from_user_overflow(void) __compiletime_warning("copy_from_user() size is not provably correct");
arch/tile/lib/uaccess.c +0 -8
@@ -22,11 +22,3 @@ int __range_ok(unsigned long addr, unsigned long size) is_arch_mappable_range(addr, size)); }EXPORT_SYMBOL (__range_ok); - -#ifdef CONFIG_DEBUG_COPY_FROM_USER -void copy_from_user_overflow (void ) -{ -WARN (1 ,"Buffer overflow detected!\n" ); -} -EXPORT_SYMBOL (copy_from_user_overflow); -#endif
arch/x86/Kconfig +1 -0
@@ -20,6 +20,7 @@ config X86_64 ### Arch settings config X86 def_bool y + select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS select HAVE_AOUT if X86_32 select HAVE_UNSTABLE_SCHED_CLOCK select ARCH_SUPPORTS_NUMA_BALANCING
arch/x86/Kconfig.debug +0 -14
@@ -292,20 +292,6 @@ config OPTIMIZE_INLINING If unsure, say N. -config DEBUG_STRICT_USER_COPY_CHECKS - bool "Strict copy size checks" - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING - ---help--- - Enabling this option turns a certain set of sanity checks for user - copy operations into compile time failures. - - The copy_from_user() etc checks are there to help test if there - are sufficient security checks on the length argument of - the copy operation, by having gcc prove that the argument is - within bounds. - - If unsure, or if you run an older (pre 4.4) gcc, say N. - config DEBUG_NMI_SELFTEST bool "NMI Selftest" depends on DEBUG_KERNEL && X86_LOCAL_APIC
arch/x86/lib/usercopy_32.c +0 -6
@@ -689,9 +689,3 @@ _copy_from_user(void *to, const void __user *from, unsigned long n)return n; }EXPORT_SYMBOL (_copy_from_user); - -void copy_from_user_overflow (void ) -{ -WARN (1 ,"Buffer overflow detected!\n" ); -} -EXPORT_SYMBOL (copy_from_user_overflow);
lib/Kconfig.debug +18 -0
@@ -1292,6 +1292,24 @@ config LATENCYTOP Enable this option if you want to use the LatencyTOP tool to find out which userspace is blocking on what kernel operations. +config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS + bool + +config DEBUG_STRICT_USER_COPY_CHECKS + bool "Strict user copy size checks" + depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING + help + Enabling this option turns a certain set of sanity checks for user + copy operations into compile time failures. + + The copy_from_user() etc checks are there to help test if there + are sufficient security checks on the length argument of + the copy operation, by having gcc prove that the argument is + within bounds. + + If unsure, say N. + source mm/Kconfig.debug source kernel/trace/Kconfig
lib/Makefile +1 -0
@@ -15,6 +15,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \ is_single_threaded.o plist.o decompress.o kobject_uevent.o \ earlycpio.o percpu-refcount.o +lib-$(CONFIG_ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS) += usercopy.o lib-$(CONFIG_MMU) += ioremap.o lib-$(CONFIG_SMP) += cpumask.o
lib/usercopy.c new file +9 -0
@@ -0,0 +1,9 @@ +#include <linux/export.h> +#include <linux/bug.h> +#include <linux/uaccess.h> + +void copy_from_user_overflow (void ) +{ +WARN (1 ,"Buffer overflow detected!\n" ); +} +EXPORT_SYMBOL (copy_from_user_overflow);
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
Re: [PATCH] Consolidate CONFIG_DEBUG_STRICT_USER_COPY_CHECK
Quoted 16 lines · Stephen Boyd
lib/Kconfig.debug +8
-0@@ -1292,6 +1292,24 @@ config LATENCYTOP Enable this option if you want to use the LatencyTOP tool to find out which userspace is blocking on what kernel operations. +config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS + bool + +config DEBUG_STRICT_USER_COPY_CHECKS + bool "Strict user copy size checks" + depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING + help
lib/Kconfig.debug config LATENCYTOP · line 1312
Quoted 10 lines
lib/Kconfig.debug +10
-0+ Enabling this option turns a certain set of sanity checks for user + copy operations into compile time failures. + + The copy_from_user() etc checks are there to help test if there + are sufficient security checks on the length argument of + the copy operation, by having gcc prove that the argument is + within bounds. + + If unsure, say N. +
Is there actually any architecture dependency left after this? I wonder if we actually need the ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS symbol, or could just show the DEBUG_STRICT_USER_COPY_CHECKS option on all architectures.
It's fine to do your patch as a first step though, which would not change the behavior.
lib/Makefile lib-y := ctype.o string.o vsprintf.o cmdline.o \ · line 21
Quoted 12 lines
lib/Makefile +1
-0@@ -15,6 +15,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \ is_single_threaded.o plist.o decompress.o kobject_uevent.o \ earlycpio.o percpu-refcount.o +lib-$(CONFIG_ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS) += usercopy.o lib-$(CONFIG_MMU) += ioremap.o lib-$(CONFIG_SMP) += cpumask.o
I think this should instead be
+lib-$(DEBUG_STRICT_USER_COPY_CHECKS) += usercopy.o
No point building that file if we are not using it.
Other than that,
Re: [PATCH] Consolidate CONFIG_DEBUG_STRICT_USER_COPY_CHECK
Quoted 32 lines · Arnd Bergmann
Quoted 16 lines · Stephen Boyd
lib/Kconfig.debug +8
-0@@ -1292,6 +1292,24 @@ config LATENCYTOP Enable this option if you want to use the LatencyTOP tool to find out which userspace is blocking on what kernel operations. +config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS + bool + +config DEBUG_STRICT_USER_COPY_CHECKS + bool "Strict user copy size checks" + depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING + helplib/Kconfig.debug config LATENCYTOP · line 1312
Quoted 10 lines
lib/Kconfig.debug +10
-0+ Enabling this option turns a certain set of sanity checks for user + copy operations into compile time failures. + + The copy_from_user() etc checks are there to help test if there + are sufficient security checks on the length argument of + the copy operation, by having gcc prove that the argument is + within bounds. + + If unsure, say N. +Is there actually any architecture dependency left after this? I wonder if we actually need the
ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKSsymbol, or could just show theDEBUG_STRICT_USER_COPY_CHECKSoption on all architectures.
Quoted 2 lines
It's fine to do your patch as a first step though, which would not change the behavior.
A lot of arches seem to not want to enable it because false positives are everywhere. It really depends on how good the compiler is at doing constant propagation and dead code removal.
Quoted 15 lines
lib/Makefile lib-y := ctype.o string.o vsprintf.o cmdline.o \ · line 21
Quoted 13 lines
lib/Makefile +1
-0@@ -15,6 +15,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \ is_single_threaded.o plist.o decompress.o kobject_uevent.o \ earlycpio.o percpu-refcount.o +lib-$(CONFIG_ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS) += usercopy.o lib-$(CONFIG_MMU) += ioremap.o lib-$(CONFIG_SMP) += cpumask.oI think this should instead be
Quoted 3 lines
+lib-$(DEBUG_STRICT_USER_COPY_CHECKS) += usercopy.o
No point building that file if we are not using it.
We still need it to link the kernel because the callers of the function don't have ifdefs. Also, all arches were doing an obj-y before, so this is equivalent.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Re: [PATCH] Consolidate CONFIG_DEBUG_STRICT_USER_COPY_CHECK
Quoted 33 lines · Stephen Boyd
Quoted 32 lines · Arnd Bergmann
Quoted 16 lines · Stephen Boyd
lib/Kconfig.debug +8
-0@@ -1292,6 +1292,24 @@ config LATENCYTOP Enable this option if you want to use the LatencyTOP tool to find out which userspace is blocking on what kernel operations. +config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS + bool + +config DEBUG_STRICT_USER_COPY_CHECKS + bool "Strict user copy size checks" + depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING + helplib/Kconfig.debug config LATENCYTOP · line 1312
Quoted 10 lines
lib/Kconfig.debug +10
-0+ Enabling this option turns a certain set of sanity checks for user + copy operations into compile time failures. + + The copy_from_user() etc checks are there to help test if there + are sufficient security checks on the length argument of + the copy operation, by having gcc prove that the argument is + within bounds. + + If unsure, say N. +Is there actually any architecture dependency left after this? I wonder if we actually need the
ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKSsymbol, or could just show theDEBUG_STRICT_USER_COPY_CHECKSoption on all architectures.
Quoted 6 lines
Quoted 2 lines
It's fine to do your patch as a first step though, which would not change the behavior.
A lot of arches seem to not want to enable it because false positives are everywhere. It really depends on how good the compiler is at doing constant propagation and dead code removal.
Ok, I see. Of course they would not need to enable that option, but I guess if we know that enabling it doesn't work, there is no point in providing the option.
Quoted 7 lines
Quoted 7 lines
lib/Kconfig.debug config LATENCYTOP · line 1315
Quoted 5 lines
lib/Kconfig.debug +1
-0+lib-$(CONFIG_ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS) += usercopy.o lib-$(CONFIG_MMU) += ioremap.o lib-$(CONFIG_SMP) += cpumask.oI think this should instead be
Quoted 7 lines
Quoted 3 lines
+lib-$(DEBUG_STRICT_USER_COPY_CHECKS) += usercopy.o
No point building that file if we are not using it.
We still need it to link the kernel because the callers of the function don't have ifdefs. Also, all arches were doing an obj-y before, so this is equivalent.
Ok.
Arnd
H. Peter Anvin
reviewerRe: [PATCH] Consolidate CONFIG_DEBUG_STRICT_USER_COPY_CHECK
In reply to Stephen BoydQuoted 8 lines · Stephen Boyd
Quoted 3 lines
It's fine to do your patch as a first step though, which would not change the behavior.
A lot of arches seem to not want to enable it because false positives are everywhere. It really depends on how good the compiler is at doing constant propagation and dead code removal.
Although some of the cases I have seen being flagged as "false positives" have been real bugs.
-hpa
Re: [PATCH] Consolidate CONFIG_DEBUG_STRICT_USER_COPY_CHECK
Hi all,
Quoted 3 lines · On Wed, 27 Feb 2013 14:19:16 -0800 "H. Peter Anvin" <[email protected]> wrote:
Although some of the cases I have seen being flagged as "false positives" have been real bugs.
[hijacking the thread :-)]
I have been getting this warning for a very long time ( which would be an error if CONFIG_DEBUG_STRICT_USER_COPY_CHECK was set):
i386 defconfig
i386-linux-gcc (GCC) 4.6.3
In file included from arch/x86/include/asm/uaccess.h:537:0,
from include/linux/uaccess.h:5,
from include/linux/highmem.h:8,
from include/linux/pagemap.h:10,
from fs/binfmt_misc.c:27:arch/x86/include/asm/uaccess_32.h: In function 'parse_command.part.2':arch/x86/include/asm/uaccess_32.h:211:26: warning: call to 'copy_from_user_overflow' declared with attribute warning: copy_from_user() buffer size is not provably correct [enabled by default]
Signature · 2 lines
Cheers, Stephen Rothwell [email protected]
H. Peter Anvin
reviewerRe: [PATCH] Consolidate CONFIG_DEBUG_STRICT_USER_COPY_CHECK
Quoted 15 lines · Stephen Rothwell
Hi all,
Quoted 3 lines · On Wed, 27 Feb 2013 14:19:16 -0800 "H. Peter Anvin" <[email protected]> wrote:
Although some of the cases I have seen being flagged as "false positives" have been real bugs.
[hijacking the thread :-)]
I have been getting this warning for a very long time ( which would be an error if
CONFIG_DEBUG_STRICT_USER_COPY_CHECKwas set):i386 defconfig i386-linux-gcc (GCC) 4.6.3
Quoted 9 lines
In file included from
arch/x86/include/asm/uaccess.h:537:0, frominclude/linux/uaccess.h:5, frominclude/linux/highmem.h:8, frominclude/linux/pagemap.h:10, fromfs/binfmt_misc.c:27:arch/x86/include/asm/uaccess_32.h: In function 'parse_command.part.2':arch/x86/include/asm/uaccess_32.h:211:26:
warning: call to 'copy_from_user_overflow' declared with attribute
warning:copy_from_user()buffer size is not provably correct [enabled by default]
OK, that is surprising, because that copy is very clearly properly guarded:
static int parse_command(const char __user *buffer, size_t count)
{
char s[4];
if (!count)
return 0;
if (count > 3)
return -EINVAL;
if (copy_from_user(s, buffer, count))
return -EFAULT;It isn't possible for count to be anything other than 1, 2 or 3 there, and it is very surprising that gcc can't see it.
This might be worth filing a gcc bug for.
-hpa
Re: [PATCH] Consolidate CONFIG_DEBUG_STRICT_USER_COPY_CHECK
In reply to Stephen RothwellQuoted 15 lines · Stephen Rothwell
Hi all,
Quoted 3 lines · On Wed, 27 Feb 2013 14:19:16 -0800 "H. Peter Anvin" <[email protected]> wrote:
Although some of the cases I have seen being flagged as "false positives" have been real bugs.
[hijacking the thread :-)]
I have been getting this warning for a very long time ( which would be an error if
CONFIG_DEBUG_STRICT_USER_COPY_CHECKwas set):i386 defconfig
i386-linux-gcc (GCC) 4.6.3
Quoted 8 lines
In file included from
arch/x86/include/asm/uaccess.h:537:0,from include/linux/uaccess.h:5, from include/linux/highmem.h:8, from include/linux/pagemap.h:10, from fs/binfmt_misc.c:27:
arch/x86/include/asm/uaccess_32.h: In function 'parse_command.part.2':arch/x86/include/asm/uaccess_32.h:211:26: warning: call to 'copy_from_user_overflow' declared with attribute warning:copy_from_user()buffer size is not provably correct [enabled by default]
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35392
the gcc folks finally fixed that one it seems
(but while there are some false positives, esp with older gcc, the majority were real originally.. just those all got fixed)
Re: [PATCH] Consolidate CONFIG_DEBUG_STRICT_USER_COPY_CHECK
In reply to H. Peter AnvinQuoted 9 lines · H. Peter Anvin
Quoted 6 lines · Stephen Boyd
Quoted 2 lines
It's fine to do your patch as a first step though, which would not change the behavior.
A lot of arches seem to not want to enable it because false positives are everywhere. It really depends on how good the compiler is at doing constant propagation and dead code removal.
Although some of the cases I have seen being flagged as "false positives" have been real bugs.
There were so many false-positives on x86_64 that Andrew eventually dropped my patch to add support for this option to the copy_from_user() function there.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
H. Peter Anvin
reviewerRe: [PATCH] Consolidate CONFIG_DEBUG_STRICT_USER_COPY_CHECK
Quoted 8 lines · Stephen Boyd
Quoted 7 lines · H. Peter Anvin
Quoted 6 lines · Stephen Boyd
Quoted 2 lines
It's fine to do your patch as a first step though, which would not change the behavior.
A lot of arches seem to not want to enable it because false positives are everywhere. It really depends on how good the compiler is at doing constant propagation and dead code removal.
Quoted 7 lines
Quoted 2 lines
Although some of the cases I have seen being flagged as "false positives" have been real bugs.
There were so many false-positives on
x86_64that Andrew eventually dropped my patch to add support for this option to thecopy_from_user()function there.
I would probably have taken it, especially if it came with more x86-64 to i386 unification.
It's an option, though.
-hpa
Re: [PATCH] Consolidate CONFIG_DEBUG_STRICT_USER_COPY_CHECK
Quoted 11 lines · H. Peter Anvin
Quoted 10 lines · Stephen Boyd
Quoted 9 lines · H. Peter Anvin
Quoted 6 lines · Stephen Boyd
Quoted 2 lines
It's fine to do your patch as a first step though, which would not change the behavior.
A lot of arches seem to not want to enable it because false positives are everywhere. It really depends on how good the compiler is at doing constant propagation and dead code removal.
Although some of the cases I have seen being flagged as "false positives" have been real bugs.
Quoted 8 lines
Quoted 4 lines
There were so many false-positives on
x86_64that Andrew eventually dropped my patch to add support for this option to thecopy_from_user()function there.I would probably have taken it, especially if it came with more x86-64 to i386 unification.
It's an option, though.
You acked the patch[1]. Will you pick it up?
[1] https://patchwork.kernel.org/patch/833192/
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
H. Peter Anvin
reviewerRe: [PATCH] Consolidate CONFIG_DEBUG_STRICT_USER_COPY_CHECK
Quoted 16 lines · Stephen Boyd
Quoted 15 lines · H. Peter Anvin
Quoted 14 lines · Stephen Boyd
Quoted 9 lines · H. Peter Anvin
Quoted 6 lines · Stephen Boyd
Quoted 2 lines
It's fine to do your patch as a first step though, which would not change the behavior.
A lot of arches seem to not want to enable it because false positives are everywhere. It really depends on how good the compiler is at doing constant propagation and dead code removal.
Although some of the cases I have seen being flagged as "false positives" have been real bugs.
There were so many false-positives on
x86_64that Andrew eventually dropped my patch to add support for this option to thecopy_from_user()function there.
Quoted 9 lines
Quoted 4 lines
I would probably have taken it, especially if it came with more x86-64 to i386 unification.
It's an option, though.
You acked the patch[1]. Will you pick it up?
I can, although I would prefer if it came with the uaccess/usercopy unification.
-hpa
Quoted 32 lines · Stephen Boyd
The help text for this config is duplicated across the x86, parisc, and s390
Kconfig.debugfiles. Arnd Bergman noted that the help text was slightly misleading and should be fixed to state that enabling this option isn't a problem when using pre 4.4 gcc.To simplify the rewording, consolidate the text into
lib/Kconfig.debugand modify it there to be more explicit about when you should say N to this config.Also, make the text a bit more generic by stating that this option enables compile time checks so we can cover architectures which emit warnings vs. ones which emit errors. The details of how an architecture decided to implement the checks isn't as important as the concept of compile time checking of
copy_from_user()calls.While we're doing this, remove all the
copy_from_user_overflow()code that's duplicated many times and place it intolib/so that any architecture supporting this option can get the function for free.Cc Arnd Bergmann <[email protected]>Cc Ingo Molnar <[email protected]>Cc H. Peter Anvin <[email protected]>Cc Arjan van de Ven <[email protected]>Cc Helge Deller <[email protected]>Cc Heiko Carstens <[email protected]>Cc Stephen Rothwell <[email protected]>Cc Chris Metcalf <[email protected]>Signed-off-by Stephen Boyd <[email protected]>
Quoted 3 lines
---
Per Helge Deller prodding me, I'm resending just this patch.
Yes, I found it in kernel patchwork and I think it's a good cleanup. Tested OK on parisc:
Quoted 313 lines
https://patchwork.kernel.org/patch/833182/
arch/parisc/Kconfig | 1 + arch/parisc/Kconfig.debug | 14 -------------- arch/s390/Kconfig | 1 + arch/s390/Kconfig.debug | 14 -------------- arch/s390/lib/Makefile | 1 - arch/s390/lib/usercopy.c | 8 -------- arch/sparc/lib/Makefile | 1 - arch/sparc/lib/usercopy.c | 9 --------- arch/tile/Kconfig | 8 +------- arch/tile/include/asm/uaccess.h | 7 ++++++- arch/tile/lib/uaccess.c | 8 -------- arch/x86/Kconfig | 1 + arch/x86/Kconfig.debug | 14 -------------- arch/x86/lib/usercopy_32.c | 6 ------ lib/Kconfig.debug | 18 ++++++++++++++++++ lib/Makefile | 1 + lib/usercopy.c | 9 +++++++++ 17 files changed, 38 insertions(+), 83 deletions(-) delete mode 100644 arch/s390/lib/usercopy.c delete mode 100644 arch/sparc/lib/usercopy.c create mode 100644 lib/usercopy.carch/parisc/Kconfig +1
-0@@ -1,5 +1,6 @@ config PARISC def_bool y + select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS select HAVE_IDE select HAVE_OPROFILE select HAVE_FUNCTION_TRACER if 64BITarch/parisc/Kconfig.debug +0
-14@@ -12,18 +12,4 @@ config DEBUG_RODATA portion of the kernel code won't be covered by a TLB anymore. If in doubt, say "N". -config DEBUG_STRICT_USER_COPY_CHECKS - bool "Strict copy size checks" - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING - ---help--- - Enabling this option turns a certain set of sanity checks for user - copy operations into compile time failures. - - The copy_from_user() etc checks are there to help test if there - are sufficient security checks on the length argument of - the copy operation, by having gcc prove that the argument is - within bounds. - - If unsure, or if you run an older (pre 4.4) gcc, say N. - endmenuarch/s390/Kconfig +1
-0@@ -91,6 +91,7 @@ config S390 select ARCH_INLINE_WRITE_UNLOCK_BH select ARCH_INLINE_WRITE_UNLOCK_IRQ select ARCH_INLINE_WRITE_UNLOCK_IRQRESTORE + select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS select ARCH_SAVE_PAGE_KEYS if HIBERNATION select ARCH_WANT_IPC_PARSE_VERSION select BUILDTIME_EXTABLE_SORTarch/s390/Kconfig.debug +0
-14@@ -17,20 +17,6 @@ config STRICT_DEVMEM If you are unsure, say Y. -config DEBUG_STRICT_USER_COPY_CHECKS - def_bool n - prompt "Strict user copy size checks" - ---help--- - Enabling this option turns a certain set of sanity checks for user - copy operations into compile time warnings. - - The copy_from_user() etc checks are there to help test if there - are sufficient security checks on the length argument of - the copy operation, by having gcc prove that the argument is - within bounds. - - If unsure, or if you run an older (pre 4.4) gcc, say N. - config S390_PTDUMP bool "Export kernel pagetable layout to userspace via debugfs" depends on DEBUG_KERNELarch/s390/lib/Makefile +0
-1@@ -3,7 +3,6 @@ # lib-y += delay.o string.o uaccess_std.o uaccess_pt.o -obj-y += usercopy.o obj-$(CONFIG_32BIT) += div64.o qrnnd.o ucmpdi2.o mem32.o obj-$(CONFIG_64BIT) += mem64.o lib-$(CONFIG_64BIT) += uaccess_mvcos.oarch/s390/lib/usercopy.c deleted +0
-8@@ -1,8 +0,0 @@ -#include <linux/module.h> -#include <linux/bug.h> - -void copy_from_user_overflow (void ) -{ -WARN (1 ,"Buffer overflow detected!\n" ); -} -EXPORT_SYMBOL (copy_from_user_overflow);arch/sparc/lib/Makefile +0
-1@@ -45,4 +45,3 @@ obj-y += iomap.o obj-$(CONFIG_SPARC32) += atomic32.o ucmpdi2.o obj-y += ksyms.o obj-$(CONFIG_SPARC64) += PeeCeeI.o -obj-y += usercopy.oarch/sparc/lib/usercopy.c deleted +0
-9@@ -1,9 +0,0 @@ -#include <linux/module.h> -#include <linux/kernel.h> -#include <linux/bug.h> - -void copy_from_user_overflow (void ) -{ -WARN (1 ,"Buffer overflow detected!\n" ); -} -EXPORT_SYMBOL (copy_from_user_overflow);arch/tile/Kconfig +1
-7@@ -19,6 +19,7 @@ config TILE select HAVE_SYSCALL_WRAPPERS if TILEGX select HAVE_VIRT_TO_BUS select SYS_HYPERVISOR + select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS select ARCH_HAVE_NMI_SAFE_CMPXCHG select GENERIC_CLOCKEVENTS select MODULES_USE_ELF_RELA@@ -117,13 +118,6 @@ config STRICT_DEVMEM config SMP def_bool y -# Allow checking for compile-time determined overflow errors in -# copy_from_user(). There are still unprovable places in the -# generic code as of 2.6.34, so this option is not really compatible -# with -Werror, which is more useful in general. -config DEBUG_COPY_FROM_USER - def_bool n - config HVC_TILE depends on TTY select HVC_DRIVERarch/tile/include/asm/uaccess.h +6
-1@@ -395,7 +395,12 @@ _copy_from_user(void *to, const void __user *from, unsigned long n)return n; } -#ifdef CONFIG_DEBUG_COPY_FROM_USER +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS +/* +* There are still unprovable places in the generic code as of 2.6.34, so this +* option is not really compatible with -Werror, which is more useful in +* general. +*/ extern void copy_from_user_overflow(void) __compiletime_warning("copy_from_user() size is not provably correct");arch/tile/lib/uaccess.c +0
-8@@ -22,11 +22,3 @@ int __range_ok(unsigned long addr, unsigned long size) is_arch_mappable_range(addr, size)); }EXPORT_SYMBOL (__range_ok); - -#ifdef CONFIG_DEBUG_COPY_FROM_USER -void copy_from_user_overflow (void ) -{ -WARN (1 ,"Buffer overflow detected!\n" ); -} -EXPORT_SYMBOL (copy_from_user_overflow); -#endif arch/x86/Kconfig +1
-0@@ -20,6 +20,7 @@ config X86_64 ### Arch settings config X86 def_bool y + select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS select HAVE_AOUT if X86_32 select HAVE_UNSTABLE_SCHED_CLOCK select ARCH_SUPPORTS_NUMA_BALANCINGarch/x86/Kconfig.debug +0
-14@@ -292,20 +292,6 @@ config OPTIMIZE_INLINING If unsure, say N. -config DEBUG_STRICT_USER_COPY_CHECKS - bool "Strict copy size checks" - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING - ---help--- - Enabling this option turns a certain set of sanity checks for user - copy operations into compile time failures. - - The copy_from_user() etc checks are there to help test if there - are sufficient security checks on the length argument of - the copy operation, by having gcc prove that the argument is - within bounds. - - If unsure, or if you run an older (pre 4.4) gcc, say N. - config DEBUG_NMI_SELFTEST bool "NMI Selftest" depends on DEBUG_KERNEL && X86_LOCAL_APICarch/x86/lib/usercopy_32.c +0
-6@@ -689,9 +689,3 @@ _copy_from_user(void *to, const void __user *from, unsigned long n)return n; }EXPORT_SYMBOL (_copy_from_user); - -void copy_from_user_overflow (void ) -{ -WARN (1 ,"Buffer overflow detected!\n" ); -} -EXPORT_SYMBOL (copy_from_user_overflow);lib/Kconfig.debug +18
-0@@ -1292,6 +1292,24 @@ config LATENCYTOP Enable this option if you want to use the LatencyTOP tool to find out which userspace is blocking on what kernel operations. +config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS + bool + +config DEBUG_STRICT_USER_COPY_CHECKS + bool "Strict user copy size checks" + depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING + help + Enabling this option turns a certain set of sanity checks for user + copy operations into compile time failures. + + The copy_from_user() etc checks are there to help test if there + are sufficient security checks on the length argument of + the copy operation, by having gcc prove that the argument is + within bounds. + + If unsure, say N. + source mm/Kconfig.debug source kernel/trace/Kconfiglib/Makefile +1
-0@@ -15,6 +15,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \ is_single_threaded.o plist.o decompress.o kobject_uevent.o \ earlycpio.o percpu-refcount.o +lib-$(CONFIG_ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS) += usercopy.o lib-$(CONFIG_MMU) += ioremap.o lib-$(CONFIG_SMP) += cpumask.olib/usercopy.c new file +9
-0@@ -0,0 +1,9 @@ +#include <linux/export.h> +#include <linux/bug.h> +#include <linux/uaccess.h> + +void copy_from_user_overflow (void ) +{ +WARN (1 ,"Buffer overflow detected!\n" ); +} +EXPORT_SYMBOL (copy_from_user_overflow);