[coreboot-gerrit] New patch to review for coreboot: util/cbmem: Fix out of bounds access

Paul Menzel (paulepanter@users.sourceforge.net) gerrit at coreboot.org
Thu Jun 18 08:13:18 CEST 2015


Paul Menzel (paulepanter at users.sourceforge.net) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/10572

-gerrit

commit 15c955db8a6b7d87156d317e8841b652bdc47fb5
Author: Aaron Durbin <adurbin at chromium.org>
Date:   Wed Jun 17 16:22:00 2015 +0200

    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 at chromium.org>
    Signed-off-by: Paul Menzel <paulepanter at users.sourceforge.net>
---
 util/cbmem/cbmem.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c
index f3366f3..1f3531a 100644
--- a/util/cbmem/cbmem.c
+++ b/util/cbmem/cbmem.c
@@ -549,8 +549,6 @@ static void dump_console(void)
 	console_p = map_memory_size((unsigned long)console.cbmem_addr,
 	                            size + sizeof(size) + sizeof(cursor));
 	memcpy(console_c, console_p + 8, size);
-	console_c[size] = 0;
-	console_c[cursor] = 0;
 
 	printf("%s\n", console_c);
 	if (size < cursor)



More information about the coreboot-gerrit mailing list