https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107258
Bug ID: 107258
Summary: ASAN at -O1 failed to detect a stack-under-flow
Product: gcc
Version: 13.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: ---
ASAN with -O1/-Os failed to detect the stack-buffer-underflow, while
-O0/-O2/-O3 can.
% gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-99da523359e9333555585484eb3b8f854a98f1b4/libexec/gcc/x86_64-pc-linux-gnu/13.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
--prefix=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-99da523359e9333555585484eb3b8f854a98f1b4
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.0.0 20221013 (experimental) (GCC)
%
% cat a.c
int a = -5, c, d;
static int f() {
int b[10];
printf("%d", b[a]);
}
int h() {
for (; c;) {
int *e[3];
e;
}
}
int main() {
int g[4];
g[d] = f();
h();
}
%
% gcc-tk -w -O1 -fsanitize=address a.c && ./a.out
0
% gcc-tk -w -O3 -fsanitize=address a.c && ./a.out
=================================================================
==929009==ERROR: AddressSanitizer: stack-buffer-overflow on address
0x7fabc520007c at pc 0x00000040125d bp 0x7ffe232d2c00 sp 0x7ffe232d2bf8
READ of size 4 at 0x7fabc520007c thread T0
#0 0x40125c in f /zdata/shaoli/ubfuzz/synthesizer/debug/a.c:4
#1 0x40125c in main /zdata/shaoli/ubfuzz/synthesizer/debug/a.c:14
#2 0x7fabc79a8082 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId:
1878e6b475720c7c51969e69ab2d276fae6d1dee)
#3 0x4012fd in _start
(/zdata/shaoli/ubfuzz/synthesizer/debug/a.out+0x4012fd)
Address 0x7fabc520007c is located in stack of thread T0 at offset 124 in frame
#0 0x4010df in main /zdata/shaoli/ubfuzz/synthesizer/debug/a.c:12
This frame has 3 object(s):
[48, 64) 'g' (line 13)
[80, 104) 'e' (line 8)
[144, 184) 'b' (line 3) <== Memory access at offset 124 underflows this
variable
HINT: this may be a false positive if your program uses some custom stack
unwind mechanism, swapcontext or vfork
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow
/zdata/shaoli/ubfuzz/synthesizer/debug/a.c:4 in f
Shadow bytes around the buggy address:
0x0ff5f8a37fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff5f8a37fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff5f8a37fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff5f8a37fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff5f8a37ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0ff5f8a38000: f1 f1 f1 f1 f1 f1 00 00 f2 f2 00 00 00 f2 f2[f2]
0x0ff5f8a38010: f2 f2 00 00 00 00 00 f3 f3 f3 f3 f3 00 00 00 00
0x0ff5f8a38020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff5f8a38030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff5f8a38040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff5f8a38050: 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
==929009==ABORTING
%
Compiler explorer: https://godbolt.org/z/Gea6cr9E1