linux-stable/arch/x86/boot
Daniel Micay 6974f0c455 include/linux/string.h: add the option of fortified string.h functions
This adds support for compiling with a rough equivalent to the glibc
_FORTIFY_SOURCE=1 feature, providing compile-time and runtime buffer
overflow checks for string.h functions when the compiler determines the
size of the source or destination buffer at compile-time.  Unlike glibc,
it covers buffer reads in addition to writes.

GNU C __builtin_*_chk intrinsics are avoided because they would force a
much more complex implementation.  They aren't designed to detect read
overflows and offer no real benefit when using an implementation based
on inline checks.  Inline checks don't add up to much code size and
allow full use of the regular string intrinsics while avoiding the need
for a bunch of _chk functions and per-arch assembly to avoid wrapper
overhead.

This detects various overflows at compile-time in various drivers and
some non-x86 core kernel code.  There will likely be issues caught in
regular use at runtime too.

Future improvements left out of initial implementation for simplicity,
as it's all quite optional and can be done incrementally:

* Some of the fortified string functions (strncpy, strcat), don't yet
  place a limit on reads from the source based on __builtin_object_size of
  the source buffer.

* Extending coverage to more string functions like strlcat.

* It should be possible to optionally use __builtin_object_size(x, 1) for
  some functions (C strings) to detect intra-object overflows (like
  glibc's _FORTIFY_SOURCE=2), but for now this takes the conservative
  approach to avoid likely compatibility issues.

* The compile-time checks should be made available via a separate config
  option which can be enabled by default (or always enabled) once enough
  time has passed to get the issues it catches fixed.

Kees said:
 "This is great to have. While it was out-of-tree code, it would have
  blocked at least CVE-2016-3858 from being exploitable (improper size
  argument to strlcpy()). I've sent a number of fixes for
  out-of-bounds-reads that this detected upstream already"

[arnd@arndb.de: x86: fix fortified memcpy]
  Link: http://lkml.kernel.org/r/20170627150047.660360-1-arnd@arndb.de
[keescook@chromium.org: avoid panic() in favor of BUG()]
  Link: http://lkml.kernel.org/r/20170626235122.GA25261@beast
[keescook@chromium.org: move from -mm, add ARCH_HAS_FORTIFY_SOURCE, tweak Kconfig help]
Link: http://lkml.kernel.org/r/20170526095404.20439-1-danielmicay@gmail.com
Link: http://lkml.kernel.org/r/1497903987-21002-8-git-send-email-keescook@chromium.org
Signed-off-by: Daniel Micay <danielmicay@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Kees Cook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Daniel Axtens <dja@axtens.net>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Chris Metcalf <cmetcalf@ezchip.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-07-12 16:26:03 -07:00
..
compressed include/linux/string.h: add the option of fortified string.h functions 2017-07-12 16:26:03 -07:00
tools x86/boot: Remove unused 'is_big_kernel' variable 2016-02-16 09:16:58 +01:00
.gitignore x86: remove offsets.h from .gitignore and dontdiff 2012-11-19 14:10:53 +01:00
a20.c
apm.c
bioscall.S x86, boot: Move intcall() to the .inittext section 2014-01-04 14:29:08 -08:00
bitops.h x86, asm: use bool for bitops and other assembly outputs 2016-06-08 12:41:20 -07:00
boot.h x86/boot: Fix BSS corruption/overwrite bug in early x86 kernel startup 2017-04-20 10:05:23 +02:00
cmdline.c x86, boot: Pass cmd_line_ptr with unsigned long instead 2013-01-29 15:26:09 -08:00
code16gcc.h x86, build: Change code16gcc.h from a C header to an assembly header 2014-06-04 13:16:48 -07:00
copy.S x86/boot: Remove unused copy_*_gs() functions 2017-06-05 09:35:16 +02:00
cpu.c Revert "x86/boot: Fail the boot if !M486 and CPUID is missing" 2016-12-19 11:54:20 +01:00
cpucheck.c x86/boot: Detect 5-level paging support 2017-04-04 08:22:33 +02:00
cpuflags.c x86/boot: Detect 5-level paging support 2017-04-04 08:22:33 +02:00
cpuflags.h x86/mm: Disallow running with 32-bit PTEs to work around erratum 2016-07-13 09:43:25 +02:00
ctype.h x86, setup: Rename BOOT_ISDIGIT_H to BOOT_CTYPE_H 2015-01-13 11:59:04 +01:00
early_serial_console.c x86/boot: Add missing file header comments 2016-05-10 10:12:03 +02:00
edd.c x86, boot: Create a separate string.h file to provide standard string functions 2014-03-19 15:43:45 -07:00
header.S x86/boot/e820: Remove assembly guard from asm/e820/types.h 2017-01-28 09:31:15 +01:00
install.sh kbuild: use INSTALLKERNEL to select customized installkernel script 2009-09-20 12:18:14 +02:00
main.c x86/boot: Obsolete the MCA sys_desc_table 2015-07-21 10:55:11 +02:00
Makefile x86/boot/build: Remove always empty $(USERINCLUDE) 2016-11-07 07:30:01 +01:00
memory.c x86/boot/e820: Separate the E820 ABI structures from the in-kernel structures 2017-01-29 13:39:32 +01:00
mkcpustr.c x86/cpufeature: Carve out X86_FEATURE_* 2016-01-30 11:22:17 +01:00
mtools.conf.in
pm.c
pmjump.S
printf.c x86/boot: Fix a sanity check in printf.c 2013-08-14 11:48:41 +02:00
regs.c x86, boot: Create a separate string.h file to provide standard string functions 2014-03-19 15:43:45 -07:00
setup.ld x86, boot: Define the 2.12 bzImage boot protocol 2013-01-27 15:56:37 -08:00
string.c x86/KASLR: Parse all 'memmap=' boot option entries 2017-05-24 09:50:27 +02:00
string.h x86/boot: Add missing strchr() declaration 2017-06-24 08:53:33 +02:00
tty.c x86, setup: reorganize the early console setup 2010-08-02 15:51:56 -07:00
version.c kbuild: move utsrelease.h to include/generated 2009-12-12 13:08:15 +01:00
vesa.h
video-bios.c
video-mode.c x86/mm: Fix regression with huge pages on PAE 2015-12-04 09:14:27 +01:00
video-vesa.c x86, boot: Create a separate string.h file to provide standard string functions 2014-03-19 15:43:45 -07:00
video-vga.c x86, setup: Set ax register in boot vga query 2010-06-10 15:24:29 -07:00
video.c x86/mm: Fix regression with huge pages on PAE 2015-12-04 09:14:27 +01:00
video.h x86/boot/video: Move the 'video_segment' variable to video.c 2015-02-19 00:25:05 +01:00