Bug 107806 - gcc trunk at -O3 misses a global-buffer-overflow
Summary: gcc trunk at -O3 misses a global-buffer-overflow
Status: RESOLVED DUPLICATE of bug 106558
Alias: None
Product: gcc
Classification: Unclassified
Component: sanitizer (show other bugs)
Version: 13.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-11-22 10:21 UTC by Shaohua Li
Modified: 2022-11-22 12:21 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Shaohua Li 2022-11-22 10:21:00 UTC
For the following code, `gcc-trunk -O3 -fsanitize=address` misses the global-buffer-overflow, while `gcc-trunk -Ox -fsanitize=address` (x=0,1, 2, s) can detect it.

gcc-12/11/10/9 have the same issue at -O3.

clang-tk can also detect it at all optimization levels.

Compiler explorer: https://godbolt.org/z/foeGGovdK

% cat a.c
int a;
long b;
int *c;
int e[9];
int **d = &c;
int main() {
    b = 0;
    for (; b < 3; b++) {
        a = a + 3;
        *d = &e[a];
        *c = 3;
    }
}
%
% gcc-tk -O3 -g -fsanitize=address a.c && ./a.out
%
% gcc-tk -O2 -g -fsanitize=address a.c && ./a.out
=================================================================
==139599==ERROR: AddressSanitizer: global-buffer-overflow on address 0x0000004042a4 at pc 0x00000040113f bp 0x7ffedad1aeb0 sp 0x7ffedad1aea8
WRITE of size 4 at 0x0000004042a4 thread T0
    #0 0x40113e in main /zdata/shaoli/sanitizertesting/mutate/synthesizer/bugs/gcc/a.c:11
    #1 0x7fad0bd57082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee)
    #2 0x40119d in _start (/zdata/shaoli/sanitizertesting/mutate/synthesizer/bugs/gcc/a.out+0x40119d)

0x0000004042a4 is located 60 bytes to the left of global variable 'c' defined in 'a.c:3:6' (0x4042e0) of size 8
0x0000004042a4 is located 0 bytes to the right of global variable 'e' defined in 'a.c:4:5' (0x404280) of size 36
SUMMARY: AddressSanitizer: global-buffer-overflow /zdata/shaoli/sanitizertesting/mutate/synthesizer/bugs/gcc/a.c:11 in main
Shadow bytes around the buggy address:
  0x000080078800: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x000080078810: 00 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 00 00 00 00
  0x000080078820: 00 00 00 00 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
  0x000080078830: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
  0x000080078840: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 00 00 00 00
=>0x000080078850: 00 00 00 00[04]f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9
  0x000080078860: f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9
  0x000080078870: f9 f9 f9 f9 00 00 00 00 00 00 00 00 00 00 00 00
  0x000080078880: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x000080078890: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0000800788a0: 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
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  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
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==139599==ABORTING
%
Comment 1 Martin Liška 2022-11-22 12:21:45 UTC
Dup.

*** This bug has been marked as a duplicate of bug 106558 ***