public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/108514] New: ASAN at -O0 missed a stack-use-after-scope
@ 2023-01-24 10:24 shaohua.li at inf dot ethz.ch
2023-01-25 9:32 ` [Bug sanitizer/108514] " marxin at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2023-01-24 10:24 UTC (permalink / raw)
To: gcc-bugs
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:
...
%
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug sanitizer/108514] ASAN at -O0 missed a stack-use-after-scope
2023-01-24 10:24 [Bug sanitizer/108514] New: ASAN at -O0 missed a stack-use-after-scope shaohua.li at inf dot ethz.ch
@ 2023-01-25 9:32 ` marxin at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: marxin at gcc dot gnu.org @ 2023-01-25 9:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108514
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
> for (; b != 9; b = 9) {
> int g=7;
> f = &g;
> }
> e = (c = d, a) || *f;
Here again, a is non-zero and thus *f does not need to be evaluated. That's
what you see with -O0. With -O1 it's evaluated as a result of optimization.
Note clang does not report the use-after-score at all in this case.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-01-25 9:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-24 10:24 [Bug sanitizer/108514] New: ASAN at -O0 missed a stack-use-after-scope shaohua.li at inf dot ethz.ch
2023-01-25 9:32 ` [Bug sanitizer/108514] " marxin at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).