https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105084
Bug ID: 105084 Summary: ASAN false positive on global-buffer-overflow Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: shaohua.li at inf dot ethz.ch CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org, jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at gcc dot gnu.org Target Milestone: --- Hi, ASAN seems to falsely report global-buffer-overflow with "-O1" and above. I tested with gcc trunk, 11.0, 10.0, and 9.0. They all reported the same issue. I wonder if this behaviour is intended or not. For clang's ASAN, it does not report anything on the program. $ $cat a.c int a[] = {3}; int b = 7; main() { unsigned int *c = &b; *c = a[1]; } $ $gcc -fsanitize=address -w -O0; ./a.out $ $gcc -fsanitize=address -w -O1; ./a.out ==292501==ERROR: AddressSanitizer: global-buffer-overflow on address 0x55aff123e040 at pc 0x55aff123b218 bp 0x7ffd41151fd0 sp 0x7ffd41151fc0 READ of size 4 at 0x55aff123e040 thread T0 #0 0x55aff123b217 in main (/shared/oob/debug_wrong3/a.out+0x2217) #1 0x7f3933a360b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x240b2) #2 0x55aff123b10d in _start (/shared/oob/debug_wrong3/a.out+0x210d) 0x55aff123e040 is located 32 bytes to the left of global variable 'ak' defined in 'simple.c:26:16' (0x55aff123e060) of size 4 0x55aff123e040 is located 28 bytes to the right of global variable 'al' defined in 'simple.c:27:16' (0x55aff123e020) of size 4 SUMMARY: AddressSanitizer: global-buffer-overflow (/shared/oob/debug_wrong3/a.out+0x2217) in main Shadow bytes around the buggy address: 0x0ab67e23fbb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0ab67e23fbc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0ab67e23fbd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0ab67e23fbe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0ab67e23fbf0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =>0x0ab67e23fc00: 00 00 00 00 04 f9 f9 f9[f9]f9 f9 f9 04 f9 f9 f9 0x0ab67e23fc10: f9 f9 f9 f9 00 00 00 00 00 00 00 00 00 00 00 00 0x0ab67e23fc20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0ab67e23fc30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0ab67e23fc40: 00 00 00 00 00 00 00 00 00 00 00 f9 f9 f9 f9 f9 0x0ab67e23fc50: 04 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 00 00 00 00 Shadow byte legend (one shadow byte represents 8 application bytes):