strict user copy checks on x86_64
Subsystems (16)
cover strict user copy checks on x86_64
It turns out that strict user copy checks (also known as CONFIG_DEBUG_STRICT_USER_COPY_CHECKS) isn't actually implemented on x86_64 and thus we aren't catching potential security holes at compile time.
This series adds support for strict user copy checks on x86_64 and silences all the benign warnings in the x86_64 allyesconfig.
The final patch consolidates the config option as its duplicated across mutliple arches. I don't know what tree this series should go through so I tried to send the individual driver patches to the respective maintainers.
Stephen Boyd (9):
iwlegacy: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
iwlwifi: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning [SCSI] lpfc: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
debugfs: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
kprobes: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
Bluetooth: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
ASoC: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
x86: Implement strict user copy checks for x86_64 Consolidate CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
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 | 8 -------- 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/include/asm/uaccess_64.h | 12 +++++++++--- arch/x86/lib/usercopy_32.c | 6 ------ drivers/net/wireless/iwlegacy/iwl-4965-rs.c | 2 +- drivers/net/wireless/iwlwifi/iwl-agn-rs.c | 2 +- drivers/scsi/lpfc/lpfc_debugfs.c | 3 ++- fs/debugfs/file.c | 2 +- kernel/kprobes.c | 2 +- lib/Kconfig.debug | 18 ++++++++++++++++++ lib/Makefile | 1 + lib/usercopy.c | 8 ++++++++ net/bluetooth/rfcomm/sock.c | 3 ++- sound/soc/soc-core.c | 2 +- 25 files changed, 55 insertions(+), 92 deletions(-) delete mode 100644 arch/s390/lib/usercopy.c delete mode 100644 arch/sparc/lib/usercopy.c create mode 100644 lib/usercopy.c
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
PATCH 2/9 iwlwifi: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
Enabling DEBUG_STRICT_USER_COPY_CHECKS causes the following warning:
In file included from arch/x86/include/asm/uaccess.h:573,
from include/net/checksum.h:25,
from include/linux/skbuff.h:28,
from drivers/net/wireless/iwlwifi/iwl-agn-rs.c:28:
In function 'copy_from_user',
inlined from 'rs_sta_dbgfs_scale_table_write' at drivers/net/wireless/iwlwifi/iwl-agn-rs.c:3099:arch/x86/include/asm/uaccess_64.h:65:
warning: call to 'copy_from_user_overflow' declared with attribute warning: copy_from_user() buffer size is not provably correct
presumably due to buf_size being signed causing GCC to fail to see that buf_size can't become negative.
--- drivers/net/wireless/iwlwifi/iwl-agn-rs.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/wireless/iwlwifi/iwl-agn-rs.c +1 -1
@@ -3087,7 +3087,7 @@ static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file,struct iwl_lq_sta *lq_sta = file->private_data;struct iwl_priv *priv;char buf[64 ]; -int buf_size; +size_t buf_size;u32 parsed_rate;struct iwl_station_priv *sta_priv = container_of(lq_sta, struct iwl_station_priv, lq_sta);
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
PATCH 3/9 lpfc: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
In reply to Stephen BoydEnabling DEBUG_STRICT_USER_COPY_CHECKS causes the following warning:
In file included from arch/x86/include/asm/uaccess.h:573,
from include/linux/uaccess.h:5,
from include/linux/highmem.h:7,
from include/linux/pagemap.h:10, from include/linux/blkdev.h:12,
from drivers/scsi/lpfc/lpfc_debugfs.c:21:
In function 'copy_from_user':arch/x86/include/asm/uaccess_64.h:65:
warning: call to 'copy_from_user_overflow' declared with attribute warning: copy_from_user() buffer size is not provably correct
presumably due to buf_size being signed causing GCC to fail to see that buf_size can't become negative.
--- drivers/scsi/lpfc/lpfc_debugfs.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/scsi/lpfc/lpfc_debugfs.c +2 -1
@@ -1305,7 +1305,8 @@ static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes, {char mybuf[64 ];char *pbuf, *step_str; -int bsize, i; +int i; +size_t bsize;/* Protect copy from user */ if (!access_ok (VERIFY_READ , buf, nbytes))
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
PATCH 6/9 Bluetooth: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
In reply to Stephen BoydEnabling DEBUG_STRICT_USER_COPY_CHECKS causes the following warning:
In function 'copy_from_user',
inlined from 'rfcomm_sock_setsockopt' at net/bluetooth/rfcomm/sock.c:705:arch/x86/include/asm/uaccess_64.h:65:
warning: call to 'copy_from_user_overflow' declared with attribute warning: copy_from_user() buffer size is not provably correct
presumably due to buf_size being signed causing GCC to fail to see that buf_size can't become negative.
--- net/bluetooth/rfcomm/sock.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
net/bluetooth/rfcomm/sock.c +2 -1
@@ -679,7 +679,8 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c {struct sock *sk = sock->sk;struct bt_security sec; -int len, err =0 ; +int err =0 ; +size_t len;u32 opt;BT_DBG ("sk %p" , sk);
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
PATCH 7/9 ASoC: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
In reply to Stephen BoydEnabling DEBUG_STRICT_USER_COPY_CHECKS causes the following warning:
In file included from arch/x86/include/asm/uaccess.h:573,
from include/linux/poll.h:14,
from include/sound/pcm.h:29,
from include/sound/ac97_codec.h:31,
from sound/soc/soc-core.c:34:In function 'copy_from_user',
inlined from 'codec_reg_write_file' at sound/soc/soc-core.c:252:arch/x86/include/asm/uaccess_64.h:65:
warning: call to 'copy_from_user_overflow' declared with attribute warning: copy_from_user() buffer size is not provably correct
presumably due to buf_size being signed causing GCC to fail to see that buf_size can't become negative.
--- sound/soc/soc-core.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
sound/soc/soc-core.c +1 -1
@@ -242,7 +242,7 @@ static ssize_t codec_reg_write_file(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { char buf[32]; -int buf_size; +size_t buf_size;char *start = buf;unsigned long reg, value;int step =1 ;
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
PATCH 9/9 Consolidate CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
In reply to Stephen BoydThe 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.
--- 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 | 8 -------- 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 ------ arch/x86/lib/usercopy_64.c | 6 ------ lib/Kconfig.debug | 18 ++++++++++++++++++ lib/Makefile | 1 + lib/usercopy.c | 8 ++++++++ 18 files changed, 37 insertions(+), 88 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
@@ -15,6 +15,7 @@ config PARISC select HAVE_GENERIC_HARDIRQS select GENERIC_IRQ_PROBE select IRQ_PER_CPU + select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS help The PA-RISC microprocessor is designed by Hewlett-Packard and used
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
@@ -116,6 +116,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 config SCHED_OMIT_FRAME_POINTER def_bool y
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 DEBUG_SET_MODULE_RONX def_bool y depends on MODULES
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 lib-$(CONFIG_64BIT) += uaccess_mvcos.o lib-$(CONFIG_SMP) += spinlock.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
@@ -44,4 +44,3 @@ obj-y += iomap.o obj-$(CONFIG_SPARC32) += atomic32.o obj-y += ksyms.o obj-$(CONFIG_SPARC64) += PeeCeeI.o -obj-y += usercopy.o
arch/sparc/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/tile/Kconfig +1 -7
@@ -12,6 +12,7 @@ config TILE select GENERIC_IRQ_PROBE select GENERIC_PENDING_IRQ if SMP select GENERIC_IRQ_SHOW + select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS # FIXME: investigate whether we need/want these options. # select HAVE_IOREMAP_PROT
@@ -96,13 +97,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 select HVC_DRIVER def_bool y
arch/tile/include/asm/uaccess.h +6 -1
@@ -353,7 +353,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
@@ -72,6 +72,7 @@ config X86 select IRQ_FORCED_THREADING select USE_GENERIC_SMP_HELPERS if SMP select ARCH_NO_SYSDEV_OPS + select ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS config INSTRUCTION_DECODER def_bool (KPROBES || PERF_EVENTS)
arch/x86/Kconfig.debug +0 -14
@@ -290,18 +290,4 @@ 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. - endmenu
arch/x86/lib/usercopy_32.c +0 -6
@@ -883,9 +883,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);
arch/x86/lib/usercopy_64.c +0 -6
@@ -181,9 +181,3 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)break ;return len; } - -void copy_from_user_overflow (void ) -{ -WARN (1 ,"Buffer overflow detected!\n" ); -} -EXPORT_SYMBOL (copy_from_user_overflow);
lib/Kconfig.debug +18 -0
@@ -1096,6 +1096,24 @@ config SYSCTL_SYSCALL_CHECK to properly maintain and use. This enables checks that help you to keep things correct. +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
@@ -14,6 +14,7 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \ proportions.o prio_heap.o ratelimit.o show_mem.o \ is_single_threaded.o plist.o decompress.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 +8 -0
@@ -0,0 +1,8 @@ +#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);
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
PATCH 1/9 iwlegacy: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
In reply to Stephen BoydEnabling DEBUG_STRICT_USER_COPY_CHECKS causes the following warning:
In file included from arch/x86/include/asm/uaccess.h:573,
from include/net/checksum.h:25,
from include/linux/skbuff.h:28,
from drivers/net/wireless/iwlegacy/iwl-4965-rs.c:28:In function 'copy_from_user',
inlined from 'iwl4965_rs_sta_dbgfs_scale_table_write' at drivers/net/wireless/iwlegacy/iwl-4965-rs.c:2616:arch/x86/include/asm/uaccess_64.h:65:
warning: call to 'copy_from_user_overflow' declared with attribute warning: copy_from_user() buffer size is not provably correct
presumably due to buf_size being signed causing GCC to fail to see that buf_size can't become negative.
--- drivers/net/wireless/iwlegacy/iwl-4965-rs.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/wireless/iwlegacy/iwl-4965-rs.c +1 -1
@@ -2604,7 +2604,7 @@ static ssize_t iwl4965_rs_sta_dbgfs_scale_table_write(struct file *file,struct iwl_lq_sta *lq_sta = file->private_data;struct iwl_priv *priv;char buf[64 ]; -int buf_size; +size_t buf_size;u32 parsed_rate;struct iwl_station_priv *sta_priv = container_of(lq_sta, struct iwl_station_priv, lq_sta);
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
PATCH 5/9 kprobes: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
In reply to Stephen BoydEnabling DEBUG_STRICT_USER_COPY_CHECKS causes the following warning:
In file included from arch/x86/include/asm/uaccess.h:573,
from kernel/kprobes.c:55:
In function 'copy_from_user',
inlined from 'write_enabled_file_bool' at kernel/kprobes.c:2191:arch/x86/include/asm/uaccess_64.h:65:
warning: call to 'copy_from_user_overflow' declared with attribute warning: copy_from_user() buffer size is not provably correct
presumably due to buf_size being signed causing GCC to fail to see that buf_size can't become negative.
--- kernel/kprobes.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/kprobes.c +1 -1
@@ -2185,7 +2185,7 @@ static ssize_t write_enabled_file_bool(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { char buf[32]; -int buf_size; +size_t buf_size; buf_size =min (count, (sizeof (buf)-1 ));if (copy_from_user (buf, user_buf, buf_size))
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
PATCH 4/9 debugfs: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
In reply to Stephen BoydEnabling DEBUG_STRICT_USER_COPY_CHECKS causes the following warning:
In file included from arch/x86/include/asm/uaccess.h:573,
from include/linux/uaccess.h:5,
from include/linux/highmem.h:7,
from include/linux/pagemap.h:10,
from fs/debugfs/file.c:18:In function 'copy_from_user',
inlined from 'write_file_bool' at fs/debugfs/file.c:435:arch/x86/include/asm/uaccess_64.h:65: warning: call to 'copy_from_user_overflow' declared with attribute warning:copy_from_user() buffer size is not provably correct
presumably due to buf_size being signed causing GCC to fail to see that buf_size can't become negative.
--- fs/debugfs/file.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
fs/debugfs/file.c +1 -1
@@ -428,7 +428,7 @@ static ssize_t write_file_bool(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { char buf[32]; -int buf_size; +size_t buf_size;u32 *val = file->private_data; buf_size =min (count, (sizeof (buf)-1 ));
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
PATCH 8/9 x86: Implement strict user copy checks for x86_64
In reply to Stephen BoydStrict user copy checks are only really supported on x86_32 even though the config option is selectable on x86_64. Add the necessary support to the 64 bit code to trigger copy_from_user() warnings at compile time.
--- arch/x86/include/asm/uaccess_64.h | 12 +++++++++--- arch/x86/lib/usercopy_64.c | 6 ++++++ 2 files changed, 15 insertions(+), 3 deletions(-)
arch/x86/include/asm/uaccess_64.h +9 -3
@@ -44,6 +44,14 @@ _copy_from_user(void *to, const void __user *from, unsigned len);__must_check unsigned long copy_in_user (void __user *to,const void __user *from,unsigned len); +extern void copy_from_user_overflow(void) +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS + __compiletime_error("copy_from_user() buffer size is not provably correct") +#else + __compiletime_warning("copy_from_user() buffer size is not provably correct") +#endif +; +static inline unsigned long __must_check copy_from_user (void *to,const void __user *from,unsigned long n)
@@ -53,10 +61,8 @@ static inline unsigned long __must_check copy_from_user(void *to,might_fault ();if (likely (sz ==-1 || sz >= n)) n =_copy_from_user (to, from, n); -#ifdef CONFIG_DEBUG_VM else - WARN(1, "Buffer overflow detected!\n"); -#endif +copy_from_user_overflow ();return n; }
arch/x86/lib/usercopy_64.c +6 -0
@@ -181,3 +181,9 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)break ;return len; } + +void copy_from_user_overflow (void ) +{ +WARN (1 ,"Buffer overflow detected!\n" ); +} +EXPORT_SYMBOL (copy_from_user_overflow);
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Re: [PATCH 2/9] iwlwifi: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
In reply to Stephen BoydQuoted 15 lines · Stephen Boyd
Enabling
DEBUG_STRICT_USER_COPY_CHECKScauses the following warning:In file included from
arch/x86/include/asm/uaccess.h:573,
frominclude/net/checksum.h:25,
frominclude/linux/skbuff.h:28,
fromdrivers/net/wireless/iwlwifi/iwl-agn-rs.c:28:
In function 'copy_from_user',
inlined from 'rs_sta_dbgfs_scale_table_write' atdrivers/net/wireless/iwlwifi/iwl-agn-rs.c:3099:arch/x86/include/asm/uaccess_64.h:65:
warning: call to 'copy_from_user_overflow' declared with attribute warning:copy_from_user()buffer size is not provably correct
Quoted 5 lines
presumably due to
buf_sizebeing signed causing GCC to fail to see thatbuf_sizecan't become negative.Cc Wey-Yi Guy <[email protected]>Signed-off-by Stephen Boyd <[email protected]>
Quoted 4 lines
--- drivers/net/wireless/iwlwifi/iwl-agn-rs.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Thank you
Wey
Re: [PATCH 1/9] iwlegacy: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
In reply to Stephen BoydQuoted 15 lines · Stephen Boyd
Enabling
DEBUG_STRICT_USER_COPY_CHECKScauses the following warning:In file included from
arch/x86/include/asm/uaccess.h:573,from include/net/checksum.h:25, from include/linux/skbuff.h:28, from drivers/net/wireless/iwlegacy/iwl-4965-rs.c:28:In function '
copy_from_user',
inlined from 'iwl4965_rs_sta_dbgfs_scale_table_write' atdrivers/net/wireless/iwlegacy/iwl-4965-rs.c:2616:arch/x86/include/asm/uaccess_64.h:65:
warning: call to 'copy_from_user_overflow' declared with attribute warning:copy_from_user()buffer size is not provably correct
Quoted 9 lines
presumably due to
buf_sizebeing signed causing GCC to fail to see thatbuf_sizecan't become negative.Cc Johannes Berg <[email protected]>Signed-off-by Stephen Boyd <[email protected]>--- drivers/net/wireless/iwlegacy/iwl-4965-rs.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
Stanislaw Gruszka <[email protected]> is the maintainer for iwlegacy
Thanks
Wey
Re: [PATCH 5/9] kprobes: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
In reply to Stephen BoydQuoted 13 lines · Stephen Boyd
Enabling
DEBUG_STRICT_USER_COPY_CHECKScauses the following warning:In file included from
arch/x86/include/asm/uaccess.h:573,
fromkernel/kprobes.c:55:
In function 'copy_from_user',
inlined from 'write_enabled_file_bool' atkernel/kprobes.c:2191:arch/x86/include/asm/uaccess_64.h:65:
warning: call to 'copy_from_user_overflow' declared with attribute warning:copy_from_user()buffer size is not provably correct
Quoted 2 lines
presumably due to
buf_sizebeing signed causing GCC to fail to see thatbuf_sizecan't become negative.
Good catch! At least, since the "count" is size_t, buf_size should be size_t too.
Thank you!
Quoted 23 lines
Cc Ananth N Mavinakayanahalli <[email protected]>Cc Anil S Keshavamurthy <[email protected]>Cc David S. Miller <[email protected]>Cc Masami Hiramatsu <[email protected]>Signed-off-by Stephen Boyd <[email protected]>--- kernel/kprobes.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)kernel/kprobes.c +1
-1@@ -2185,7 +2185,7 @@ static ssize_t write_enabled_file_bool(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { char buf[32]; -int buf_size; +size_t buf_size; buf_size =min (count, (sizeof (buf)-1 ));if (copy_from_user (buf, user_buf, buf_size))
Signature · 4 lines
Masami HIRAMATSU Software Platform Research Dept. Linux Technology Center Hitachi, Ltd., Yokohama Research Laboratory E-mail: [email protected]
Re: [PATCH 9/9] Consolidate CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
In reply to Stephen BoydQuoted 21 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.
Quoted 4 lines
--- arch/tile/Kconfig | 8 +------- arch/tile/include/asm/uaccess.h | 7 ++++++- arch/tile/lib/uaccess.c | 8 --------
Signature · 2 lines
Chris Metcalf, Tilera Corp. http://www.tilera.com
Re: [PATCH 9/9] Consolidate CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
In reply to Stephen BoydQuoted 46 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 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]>--- 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 | 8 -------- 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 ------
Quoted 8 lines
arch/x86/lib/usercopy_64.c | 6 ------ lib/Kconfig.debug | 18 ++++++++++++++++++ lib/Makefile | 1 + lib/usercopy.c | 8 ++++++++ 18 files changed, 37 insertions(+), 88 deletions(-) delete mode 100644 arch/s390/lib/usercopy.c delete mode 100644 arch/sparc/lib/usercopy.c create mode 100644 lib/usercopy.c
Very nice!
Ingo
Re: [PATCH 1/9] iwlegacy: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
In reply to Stephen BoydQuoted 29 lines · Stephen Boyd
Enabling
DEBUG_STRICT_USER_COPY_CHECKScauses the following warning:In file included from
arch/x86/include/asm/uaccess.h:573,from include/net/checksum.h:25, from include/linux/skbuff.h:28, from drivers/net/wireless/iwlegacy/iwl-4965-rs.c:28:In function '
copy_from_user',
inlined from 'iwl4965_rs_sta_dbgfs_scale_table_write' atdrivers/net/wireless/iwlegacy/iwl-4965-rs.c:2616:arch/x86/include/asm/uaccess_64.h:65:
warning: call to 'copy_from_user_overflow' declared with attribute warning:copy_from_user()buffer size is not provably correctpresumably due to
buf_sizebeing signed causing GCC to fail to see thatbuf_sizecan't become negative.Cc Johannes Berg <[email protected]>Signed-off-by Stephen Boyd <[email protected]>--- drivers/net/wireless/iwlegacy/iwl-4965-rs.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)drivers/net/wireless/iwlegacy/iwl-4965-rs.c +0
-0
drivers/net/wireless/iwlegacy/iwl-4965-rs.c static ssize_t iwl4965_rs_sta_dbgfs_scale_table_write(struct file *file, · line 2607
Quoted 5 lines
drivers/net/wireless/iwlegacy/iwl-4965-rs.c +1
-1@@ -2604,7 +2604,7 @@ static ssize_t iwl4965_rs_sta_dbgfs_scale_table_write(struct file *file,struct iwl_lq_sta *lq_sta = file->private_data;struct iwl_priv *priv;char buf[64 ]; -int buf_size; +size_t buf_size;
ACK, but we have more of that, perhaps you would like to fix them all. If you don't want to, I'll do it. Note this can be easily done by:
sed -i 's/int buf_size;/size_t buf_size;/g' drivers/net/wireless/iwlegacy/*.[ch]
Stanislaw
Re: [PATCH 8/9] x86: Implement strict user copy checks for x86_64
In reply to Stephen BoydQuoted 11 lines · Stephen Boyd
Strict user copy checks are only really supported on
x86_32even though the config option is selectable onx86_64. Add the necessary support to the 64 bit code to triggercopy_from_user()warnings at compile time.Signed-off-by Stephen Boyd <[email protected]>--- arch/x86/include/asm/uaccess_64.h | 12 +++++++++--- arch/x86/lib/usercopy_64.c | 6 ++++++ 2 files changed, 15 insertions(+), 3 deletions(-)
Very nice!
Thanks,
Ingo
Re: [PATCH 9/9] Consolidate CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
In reply to Stephen BoydQuoted 21 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.
Quoted 10 lines
Cc Arnd Bergmann <[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]>
Thanks for following up on this
Gustavo F. Padovan
AppliedRe: [PATCH 6/9] Bluetooth: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
In reply to Stephen BoydHi Stephen,
Quoted 14 lines · Stephen Boyd
Enabling
DEBUG_STRICT_USER_COPY_CHECKScauses the following warning:In function '
copy_from_user',
inlined from 'rfcomm_sock_setsockopt' atnet/bluetooth/rfcomm/sock.c:705:arch/x86/include/asm/uaccess_64.h:65:
warning: call to 'copy_from_user_overflow' declared with attribute warning:copy_from_user()buffer size is not provably correctpresumably due to
buf_sizebeing signed causing GCC to fail to see thatbuf_sizecan't become negative.
Quoted 6 lines
Cc Marcel Holtmann <[email protected]>Cc Gustavo F. Padovan <[email protected]>Signed-off-by Stephen Boyd <[email protected]>--- net/bluetooth/rfcomm/sock.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
Applied, thanks.
Signature · 2 lines
Gustavo F. Padovan http://profusion.mobi
Re: [PATCH 4/9] debugfs: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
In reply to Stephen BoydQuoted 27 lines · Stephen Boyd
Enabling
DEBUG_STRICT_USER_COPY_CHECKScauses the following warning:In file included from
arch/x86/include/asm/uaccess.h:573,from include/linux/uaccess.h:5, from include/linux/highmem.h:7, from include/linux/pagemap.h:10, from fs/debugfs/file.c:18:In function '
copy_from_user',
inlined from 'write_file_bool' atfs/debugfs/file.c:435:arch/x86/include/asm/uaccess_64.h:65: warning: call to 'copy_from_user_overflow' declared with attribute warning:copy_from_user()buffer size is not provably correctpresumably due to
buf_sizebeing signed causing GCC to fail to see thatbuf_sizecan't become negative.Signed-off-by Stephen Boyd <[email protected]>--- fs/debugfs/file.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)fs/debugfs/file.c +0
-0
fs/debugfs/file.c static ssize_t write_file_bool(struct file *file, const char __user *user_buf, · line 432
Quoted 6 lines
fs/debugfs/file.c +1
-1@@ -428,7 +428,7 @@ static ssize_t write_file_bool(struct file *file, const char __user *user_buf, size_t count, loff_t *ppos) { char buf[32]; -int buf_size; +size_t buf_size;u32 *val = file->private_data;
What tree did you make this against? It doesn't apply to the linux-next tree :(
Anyway, I can hand edit it, not that big of a deal, but be more careful the next time around.
greg k-h
Re: [PATCH 7/9] ASoC: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
In reply to Stephen BoydQuoted 16 lines · Stephen Boyd
Enabling
DEBUG_STRICT_USER_COPY_CHECKScauses the following warning:In file included from
arch/x86/include/asm/uaccess.h:573,from include/linux/poll.h:14, from include/sound/pcm.h:29, from include/sound/ac97_codec.h:31, from sound/soc/soc-core.c:34:In function '
copy_from_user',
inlined from 'codec_reg_write_file' atsound/soc/soc-core.c:252:arch/x86/include/asm/uaccess_64.h:65:
warning: call to 'copy_from_user_overflow' declared with attribute warning:copy_from_user()buffer size is not provably correct
Quoted 6 lines
presumably due to
buf_sizebeing signed causing GCC to fail to see thatbuf_sizecan't become negative.Cc Liam Girdwood <[email protected]>Cc Mark Brown <[email protected]>Signed-off-by Stephen Boyd <[email protected]>
Re: [PATCH 3/9] [SCSI] lpfc: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
In reply to Stephen BoydThanks
-- james
Quoted 38 lines · Stephen Boyd
Enabling
DEBUG_STRICT_USER_COPY_CHECKScauses the following warning:In file included from
arch/x86/include/asm/uaccess.h:573,
frominclude/linux/uaccess.h:5, frominclude/linux/highmem.h:7, frominclude/linux/pagemap.h:10, frominclude/linux/blkdev.h:12, fromdrivers/scsi/lpfc/lpfc_debugfs.c:21:
In function 'copy_from_user':arch/x86/include/asm/uaccess_64.h:65:
warning: call to 'copy_from_user_overflow' declared with attribute warning:copy_from_user()buffer size is not provably correctpresumably due to
buf_sizebeing signed causing GCC to fail to see thatbuf_sizecan't become negative.Cc James Smart<[email protected]>Signed-off-by Stephen Boyd<[email protected]>--- drivers/scsi/lpfc/lpfc_debugfs.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)drivers/scsi/lpfc/lpfc_debugfs.c +2
-1@@ -1305,7 +1305,8 @@ static int lpfc_idiag_cmd_get(const char __user *buf, size_t nbytes, {char mybuf[64 ];char *pbuf, *step_str; -int bsize, i; +int i; +size_t bsize;/* Protect copy from user */ if (!access_ok (VERIFY_READ , buf, nbytes))
Hi Andrew,
(I don't know who to pick on sorry)
Quoted 13 lines · Stephen Boyd
It turns out that strict user copy checks (also known as
CONFIG_DEBUG_STRICT_USER_COPY_CHECKS) isn't actually implemented onx86_64and thus we aren't catching potential security holes at compile time.This series adds support for strict user copy checks on
x86_64and silences all the benign warnings in thex86_64allyesconfig.The final patch consolidates the config option as its duplicated across mutliple arches. I don't know what tree this series should go through so I tried to send the individual driver patches to the respective maintainers.
Quoted 10 lines
Stephen Boyd (9):
iwlegacy: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
iwlwifi: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning [SCSI] lpfc: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
debugfs: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
kprobes: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
Bluetooth: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
ASoC: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
x86: Implement strict user copy checks forx86_64ConsolidateCONFIG_DEBUG_STRICT_USER_COPY_CHECKS
It looks like 1, 2, 4, 6, and 7 got picked up. Should I resend the left over patches with appropriate acked-bys and tags? Would it be appropriate to push this through your tree?
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Quoted 5 lines · Stephen Boyd
It looks like 1, 2, 4, 6, and 7 got picked up. Should I resend the left over patches with appropriate acked-bys and tags? Would it be appropriate to push this through your tree?
I was first going to think I'd pick up 8 and 9 in tip, but since 9 is cross-architecture, Andrew's tree might be better.
-hpa
Mark Brown
AppliedRe: [PATCH 7/9] ASoC: Silence DEBUG_STRICT_USER_COPY_CHECKS=y warning
In reply to Stephen BoydQuoted 2 lines · Stephen Boyd
Enabling
DEBUG_STRICT_USER_COPY_CHECKScauses the following warning:
Applied, thanks.