Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[S390] uaccess: implement strict user copy checks

Same as on x86 and sparc, besides the fact that enabling the option
will just emit compile time warnings instead of errors.
Keeps allyesconfig kernels compiling.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>

authored by

Heiko Carstens and committed by
Martin Schwidefsky
1dcec254 68c6b859

+34 -1
+13
arch/s390/Kconfig.debug
··· 6 6 7 7 source "lib/Kconfig.debug" 8 8 9 + config DEBUG_STRICT_USER_COPY_CHECKS 10 + bool "Strict user copy size checks" 11 + ---help--- 12 + Enabling this option turns a certain set of sanity checks for user 13 + copy operations into compile time warnings. 14 + 15 + The copy_from_user() etc checks are there to help test if there 16 + are sufficient security checks on the length argument of 17 + the copy operation, by having gcc prove that the argument is 18 + within bounds. 19 + 20 + If unsure, or if you run an older (pre 4.4) gcc, say N. 21 + 9 22 endmenu
+12
arch/s390/include/asm/uaccess.h
··· 265 265 return uaccess.copy_from_user(n, from, to); 266 266 } 267 267 268 + extern void copy_from_user_overflow(void) 269 + #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS 270 + __compiletime_warning("copy_from_user() buffer size is not provably correct") 271 + #endif 272 + ; 273 + 268 274 /** 269 275 * copy_from_user: - Copy a block of data from user space. 270 276 * @to: Destination address, in kernel space. ··· 290 284 static inline unsigned long __must_check 291 285 copy_from_user(void *to, const void __user *from, unsigned long n) 292 286 { 287 + unsigned int sz = __compiletime_object_size(to); 288 + 293 289 might_fault(); 290 + if (unlikely(sz != -1 && sz < n)) { 291 + copy_from_user_overflow(); 292 + return n; 293 + } 294 294 if (access_ok(VERIFY_READ, from, n)) 295 295 n = __copy_from_user(to, from, n); 296 296 else
+1 -1
arch/s390/lib/Makefile
··· 2 2 # Makefile for s390-specific library files.. 3 3 # 4 4 5 - lib-y += delay.o string.o uaccess_std.o uaccess_pt.o 5 + lib-y += delay.o string.o uaccess_std.o uaccess_pt.o usercopy.o 6 6 obj-$(CONFIG_32BIT) += div64.o qrnnd.o ucmpdi2.o 7 7 lib-$(CONFIG_64BIT) += uaccess_mvcos.o 8 8 lib-$(CONFIG_SMP) += spinlock.o
+8
arch/s390/lib/usercopy.c
··· 1 + #include <linux/module.h> 2 + #include <linux/bug.h> 3 + 4 + void copy_from_user_overflow(void) 5 + { 6 + WARN(1, "Buffer overflow detected!\n"); 7 + } 8 + EXPORT_SYMBOL(copy_from_user_overflow);