coreboot-kgpe-d16/util
Aaron Durbin e740f4845d util/cbmem: Fix out of bounds access
Building cbmem with ASan

	$ CC=gcc-5 CFLAGS="-O1 -g -fsanitize=address -fno-omit-frame-pointer" LDFLAGS="-fsanitize=address" make

it sometimes finds a heap-buffer-overflow, while dumping the CBMEM
console.

$ sudo ./cbmem -c
=================================================================
==11208==ERROR: AddressSanitizer: heap-buffer-overflow on address 0xb5d5782b at pc 0x0804a4d7 bp 0xbfe23bc8 sp 0xbfe23bbc
WRITE of size 1 at 0xb5d5782b thread T0
    #0 0x804a4d6 in dump_console /home/joey/src/coreboot/util/cbmem/cbmem.c:553
    #1 0x804a4d6 in main /home/joey/src/coreboot/util/cbmem/cbmem.c:1134
    #2 0xb70a3a62 in __libc_start_main (/lib/i386-linux-gnu/i686/cmov/libc.so.6+0x19a62)
    #3 0x8048cf0  (/home/joey/src/coreboot/util/cbmem/cbmem+0x8048cf0)

0xb5d5782b is located 50 bytes to the right of 131065-byte region [0xb5d37800,0xb5d577f9)
allocated by thread T0 here:
    #0 0xb72c64ce in __interceptor_malloc (/usr/lib/i386-linux-gnu/libasan.so.2+0x924ce)
    #1 0x804a407 in dump_console /home/joey/src/coreboot/util/cbmem/cbmem.c:542
    #2 0x804a407 in main /home/joey/src/coreboot/util/cbmem/cbmem.c:1134
    #3 0xb70a3a62 in __libc_start_main (/lib/i386-linux-gnu/i686/cmov/libc.so.6+0x19a62)

SUMMARY: AddressSanitizer: heap-buffer-overflow /home/joey/src/coreboot/util/cbmem/cbmem.c:553 dump_console
Shadow bytes around the buggy address:
  0x36baaeb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x36baaec0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x36baaed0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x36baaee0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x36baaef0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01
=>0x36baaf00: fa fa fa fa fa[fa]fa fa fa fa fa fa fa fa fa fa
  0x36baaf10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x36baaf20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x36baaf30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x36baaf40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x36baaf50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Heap right redzone:      fb
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack partial redzone:   f4
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
==11208==ABORTING

Fix up commit 06b13a37 (cbmem: Terminate the cbmem console at the cursor
position.) by reverting setting the cursor to 0.

Change-Id: Id614a8e0f1a202671dd091f825d826a17176bfcc
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Signed-off-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-on: http://review.coreboot.org/10572
Tested-by: build bot (Jenkins)
Reviewed-by: Martin Roth <martinroth@google.com>
2015-11-20 16:36:59 +01:00
..
abuild abuild: allow specifying multiple targets by mainboard descriptor 2015-11-01 14:27:02 +01:00
acpi tree: drop last paragraph of GPL copyright header 2015-10-31 21:37:39 +01:00
amdfwtool amdfwtool: Add amdfwtool to combine AMD firmwares 2015-11-19 04:11:59 +01:00
amdtools Remove empty lines at end of file 2015-06-08 00:55:07 +02:00
arm_boot_tools/mksunxiboot arm_boot_tools: Add 'b' to fopen flags for Windows compatibility 2014-12-19 18:55:34 +01:00
autoport tree: drop last paragraph of GPL copyright header 2015-10-31 21:37:39 +01:00
bimgtool tree: drop last paragraph of GPL copyright header 2015-10-31 21:37:39 +01:00
board_status board-status: Reorder the table categories 2015-11-03 21:29:16 +01:00
broadcom secimage: Use libz's crc32 function 2015-08-09 12:34:24 +02:00
cbfstool cbfstool: Fix build error with clang when comparing enum 2015-11-20 05:36:48 +01:00
cbmem util/cbmem: Fix out of bounds access 2015-11-20 16:36:59 +01:00
crossgcc crossgcc: Update makefile builds 2015-11-19 16:50:00 +01:00
dtd_parser tree: drop last paragraph of GPL copyright header 2015-10-31 21:37:39 +01:00
ectool tree: drop last paragraph of GPL copyright header 2015-10-31 21:37:39 +01:00
exynos exynos: Install the BL1 and set the checksum in the Makefile. 2014-09-09 20:01:18 +02:00
fuzz-tests tree: drop last paragraph of GPL copyright header 2015-10-31 21:37:39 +01:00
genbuild_h tree: drop last paragraph of GPL copyright header 2015-10-31 21:37:39 +01:00
genprof util/genprof: improve handling of command line arguments 2014-08-12 09:02:44 +02:00
gitconfig gitconfig/rebase.sh: adapt default branch name 2015-08-28 18:41:21 +00:00
ifdfake tree: drop last paragraph of GPL copyright header 2015-10-31 21:37:39 +01:00
ifdtool ifdtool: Makefile: fix install target 2015-11-17 05:18:28 +01:00
inteltool tree: drop last paragraph of GPL copyright header 2015-10-31 21:37:39 +01:00
intelvbttool tree: drop last paragraph of GPL copyright header 2015-10-31 21:37:39 +01:00
ipqheader Remove empty lines at end of file 2015-06-08 00:55:07 +02:00
k8resdump tree: drop last paragraph of GPL copyright header 2015-10-31 21:37:39 +01:00
kconfig util/kconfig: Set parameter of mkdir to only one for mingw. 2015-11-20 05:37:20 +01:00
lint lint: properly terminate junit report on error 2015-11-19 16:13:50 +01:00
msrtool tree: drop last paragraph of GPL copyright header 2015-10-31 21:37:39 +01:00
nvidia nvidia/cbootimage: update to 1.5 2015-04-25 12:16:58 +02:00
nvramtool tree: drop last paragraph of GPL copyright header 2015-10-31 21:37:39 +01:00
optionlist tree: drop last paragraph of GPL copyright header 2015-10-31 21:37:39 +01:00
release util/release: Add release notes generator script 2015-11-11 20:42:00 +01:00
rockchip add make_idb.py & update bootblock 2015-03-24 15:24:52 +01:00
romcc romcc: Allow adding non-existent paths to include path 2015-11-19 21:20:29 +01:00
sconfig sconfig: remove warning about root_complex 2015-11-14 18:43:06 +01:00
scripts utils/scripts: Add microcode conversion tool 2015-11-10 18:46:04 +01:00
showdevicetree tree: drop last paragraph of GPL copyright header 2015-10-31 21:37:39 +01:00
spkmodem_recv tree: drop last paragraph of GPL copyright header 2015-10-31 21:37:39 +01:00
superiotool tree: drop last paragraph of GPL copyright header 2015-10-31 21:37:39 +01:00
uio_usbdebug tree: drop last paragraph of GPL copyright header 2015-10-31 21:37:39 +01:00
vgabios vgabios: fix compilation after x86emu changes 2015-10-25 21:33:32 +01:00
viatool tree: drop last paragraph of GPL copyright header 2015-10-31 21:37:39 +01:00
xcompile build system: tighten down .xcompile handling some more 2015-11-20 10:33:07 +01:00