[Bug sanitizer/55739] asan doesn't work on common symbols
hjl.tools at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon Jan 14 22:12:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55739
--- Comment #6 from H.J. Lu <hjl.tools at gmail dot com> 2013-01-14 22:11:16 UTC ---
Created attachment 29165
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29165
A prototype
If as, ld and ld.so provide size info via "symbol@size", we can do
.LASAN0:
# __beg:
.quad common_data
# __size:
.quad common_data@size
# __size_with_redzone:
.quad common_data@size + 40
# __name:
.quad .LC0
# __has_dynamic_init:
.quad 0
[hjl@gnu-6 pr55739]$ make
/export/build/gnu/gcc/build-x86_64-linux/gcc/../../release/usr/gcc-4.8.0/bin/gcc
-fsanitize=address -O -static-libasan -c -o m.o m.c
/export/build/gnu/gcc/build-x86_64-linux/gcc/../../release/usr/gcc-4.8.0/bin/gcc
-fsanitize=address -O -static-libasan -c -o c.o c.c
/export/build/gnu/gcc/build-x86_64-linux/gcc/../../release/usr/gcc-4.8.0/bin/gcc
-fsanitize=address -O -static-libasan -c size.S
/export/build/gnu/gcc/build-x86_64-linux/gcc/../../release/usr/gcc-4.8.0/bin/gcc
-fsanitize=address -O -static-libasan -o x m.o c.o size.o
./x
10: 0
29: 1
=================================================================
==1454== ERROR: AddressSanitizer: global-buffer-overflow on address
0x000002e70a18 at pc 0x401dc5 bp 0x7fffffffde90 sp 0x7fffffffde70
WRITE of size 4 at 0x000002e70a18 thread T0
#0 0x401dc4 (/export/home/hjl/bugs/gcc/pr55739/x+0x401dc4)
0x000002e70a18 is located 0 bytes to the right of global variable 'c (d.c)'
(0x2e709a0) of size 120
'c (d.c)' is ascii string ''
Shadow bytes around the buggy address:
0x1000005ce0f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000005ce100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000005ce110: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000005ce120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000005ce130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x1000005ce140: 00 00 00[f9]f9 f9 f9 f9 00 00 00 00 00 00 00 00
0x1000005ce150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000005ce160: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000005ce170: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000005ce180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1000005ce190: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
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 righ 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
ASan internal: fe
Stats: 0M malloced (0M for red zones) by 0 calls
Stats: 0M realloced by 0 calls
Stats: 0M freed by 0 calls
Stats: 0M really freed by 0 calls
Stats: 0M (0M-0M) mmaped; 0 maps, 0 unmaps
mmaps by size class:
mallocs by size class:
frees by size class:
rfrees by size class:
Stats: malloc large: 0 small slow: 0
Stats: StackDepot: 0 ids; 0M mapped
==1454== ABORTING
make: *** [all] Error 1
[hjl@gnu-6 pr55739]$ readelf -s c.o | grep common_data
17: 0000000000000020 120 OBJECT GLOBAL DEFAULT COM common_data
[hjl@gnu-6 pr55739]$
More information about the Gcc-bugs
mailing list