[Bug sanitizer/108514] New: ASAN at -O0 missed a stack-use-after-scope
shaohua.li at inf dot ethz.ch
gcc-bugzilla@gcc.gnu.org
Tue Jan 24 10:24:27 GMT 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108514
Bug ID: 108514
Summary: ASAN at -O0 missed a stack-use-after-scope
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: ---
For the following code, ASAN at -O0 and -Os missed the stack-use-after-scope,
while other opt levels caught it. This issue is really concerning as it appears
at -O0.
Compiler explorer: https://godbolt.org/z/bWGbq6Er9
% cat a.c
int a = 5;
char b, d;
short c, e;
int main() {
int *f = &a;
b = 0;
for (; b != 9; b = 9) {
int g=7;
f = &g;
}
e = (c = d, a) || *f;
return e;
}
%
% gcc-tk -fsanitize=address -g -O0 a.c && ./a.out
%
% gcc-tk -fsanitize=address -g -O1 a.c && ./a.out
=================================================================
==1==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7f5faf900020
at pc 0x0000004011e6 bp 0x7ffc50f70450 sp 0x7ffc50f70448
READ of size 4 at 0x7f5faf900020 thread T0
#0 0x4011e5 in main /a.c:11
#1 0x7f5fb22da082 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId:
1878e6b475720c7c51969e69ab2d276fae6d1dee)
#2 0x4010bd in _start (/app/output.s+0x4010bd) (BuildId:
99c4c90f86135af6a6c35d4ef1af9a5d7e48c1ed)
Address 0x7f5faf900020 is located in stack of thread T0 at offset 32 in frame
#0 0x401185 in main /a.c:4
This frame has 1 object(s):
[32, 36) 'g' (line 8) <== Memory access at offset 32 is inside 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-use-after-scope /a.c:11 in main
Shadow bytes around the buggy address:
...
%
More information about the Gcc-bugs
mailing list