public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/108085] New: gcc trunk's ASAN at -O3 missed a stack-use-after-scope
@ 2022-12-13 16:08 shaohua.li at inf dot ethz.ch
2022-12-14 8:26 ` [Bug sanitizer/108085] " marxin at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2022-12-13 16:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108085
Bug ID: 108085
Summary: gcc trunk's ASAN at -O3 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 -O3 failed to report the stack-use-after-scope,
other opt levels detected it successfully.
GCC-8 works fine.
Clang at all optimization levels reported it.
Compiler explorer: https://godbolt.org/z/jbsThYWa6
% cat a.c
int a;
void b() {
int c[1];
c;
}
int main() {
int d[1]={1};
int *e = d;
a = 0;
for (; a <= 5; ++a) {
int f[1]={};
e = f;
a || (b(), 1);
}
return *e;
}
%
% gcc-tk -O2 -fsanitize=address -g a.c && ./a.out
=================================================================
==780198==ERROR: AddressSanitizer: stack-use-after-scope on address
0x7f2307600030 at pc 0x0000004011c5 bp 0x7ffdd19ecd80 sp 0x7ffdd19ecd78
READ of size 4 at 0x7f2307600030 thread T0
#0 0x4011c4 in main /a.c:15
#1 0x7f2309f41082 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId:
1878e6b475720c7c51969e69ab2d276fae6d1dee)
#2 0x40126d in _start (/a.out+0x40126d)
Address 0x7f2307600030 is located in stack of thread T0 at offset 48 in frame
#0 0x4010bf in main /a.c:6
This frame has 3 object(s):
[32, 36) 'd' (line 7)
[48, 52) 'f' (line 11) <== Memory access at offset 48 is inside this
variable
[64, 68) 'c' (line 3)
...
%
% gcc-tk -O3 -fsanitize=address -g a.c && ./a.out
%
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug sanitizer/108085] gcc trunk's ASAN at -O3 missed a stack-use-after-scope
2022-12-13 16:08 [Bug sanitizer/108085] New: gcc trunk's ASAN at -O3 missed a stack-use-after-scope shaohua.li at inf dot ethz.ch
@ 2022-12-14 8:26 ` marxin at gcc dot gnu.org
2022-12-14 8:27 ` rguenth at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-12-14 8:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108085
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |marxin at gcc dot gnu.org
Last reconfirmed| |2022-12-14
Status|UNCONFIRMED |ASSIGNED
Ever confirmed|0 |1
--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
I can take a look.
Note I can't reproduce it with Clang with any of -O1+ options:
$ clang pr108085.c -fsanitize=address -w && ./a.out
=================================================================
==20150==ERROR: AddressSanitizer: stack-use-after-scope on address
0x7ffff5e00030 at pc 0x55555566a2aa bp 0x7fffffffd510 sp 0x7fffffffd508
READ of size 4 at 0x7ffff5e00030 thread T0
#0 0x55555566a2a9 in main pr108085.c
#1 0x7ffff7ca35af in __libc_start_call_main (/lib64/libc.so.6+0x275af)
(BuildId: 3f7f40d4302fa8a9568a057065c023bf137fceb7)
#2 0x7ffff7ca3678 in __libc_start_main@GLIBC_2.2.5
(/lib64/libc.so.6+0x27678) (BuildId: 3f7f40d4302fa8a9568a057065c023bf137fceb7)
#3 0x5555555a9d64 in _start
/home/abuild/rpmbuild/BUILD/glibc-2.36/csu/../sysdeps/x86_64/start.S:115
Address 0x7ffff5e00030 is located in stack of thread T0 at offset 48 in frame
#0 0x55555566a11f in main pr108085.c
This frame has 2 object(s):
[32, 36) 'd'
[48, 52) 'f' <== Memory access at offset 48 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 pr108085.c in main
Shadow bytes around the buggy address:
0x10007ebb7fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10007ebb7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10007ebb7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10007ebb7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10007ebb7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x10007ebb8000: f1 f1 f1 f1 04 f2[f8]f3 00 00 00 00 00 00 00 00
0x10007ebb8010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10007ebb8020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10007ebb8030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10007ebb8040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x10007ebb8050: 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
==20150==ABORTING
$ clang pr108085.c -fsanitize=address -w -O1 && ./a.out
(no output)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug sanitizer/108085] gcc trunk's ASAN at -O3 missed a stack-use-after-scope
2022-12-13 16:08 [Bug sanitizer/108085] New: gcc trunk's ASAN at -O3 missed a stack-use-after-scope shaohua.li at inf dot ethz.ch
2022-12-14 8:26 ` [Bug sanitizer/108085] " marxin at gcc dot gnu.org
@ 2022-12-14 8:27 ` rguenth at gcc dot gnu.org
2022-12-23 15:25 ` marxin at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-12-14 8:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108085
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
I bet we unroll the loop and then elide f[] at -O3.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug sanitizer/108085] gcc trunk's ASAN at -O3 missed a stack-use-after-scope
2022-12-13 16:08 [Bug sanitizer/108085] New: gcc trunk's ASAN at -O3 missed a stack-use-after-scope shaohua.li at inf dot ethz.ch
2022-12-14 8:26 ` [Bug sanitizer/108085] " marxin at gcc dot gnu.org
2022-12-14 8:27 ` rguenth at gcc dot gnu.org
@ 2022-12-23 15:25 ` marxin at gcc dot gnu.org
2022-12-23 15:25 ` marxin at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-12-23 15:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108085
--- Comment #3 from Martin Liška <marxin at gcc dot gnu.org> ---
Created attachment 54153
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54153&action=edit
pr108085.c.216t.uncprop1.dot.svg
So no, it's a real issue where we optimize out .ASAN_CHECK (6, &f, 4, 8); in
the exit block. As seen in the dump file, we have the very ASAN_CHECK in bb_3:
.ASAN_CHECK (7, &f, 4, 8), however, there are 2 ASAN_MARK (POISON, &f, 4) calls
that are on the path from bb_3 to the exit block.
@Jakub: Can you please take a look at the optimization algorithm why the check
is not preserved?
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug sanitizer/108085] gcc trunk's ASAN at -O3 missed a stack-use-after-scope
2022-12-13 16:08 [Bug sanitizer/108085] New: gcc trunk's ASAN at -O3 missed a stack-use-after-scope shaohua.li at inf dot ethz.ch
` (2 preceding siblings ...)
2022-12-23 15:25 ` marxin at gcc dot gnu.org
@ 2022-12-23 15:25 ` marxin at gcc dot gnu.org
2023-02-02 19:39 ` pinskia at gcc dot gnu.org
2023-02-02 19:45 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-12-23 15:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108085
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|marxin at gcc dot gnu.org |unassigned at gcc dot gnu.org
Status|ASSIGNED |NEW
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug sanitizer/108085] gcc trunk's ASAN at -O3 missed a stack-use-after-scope
2022-12-13 16:08 [Bug sanitizer/108085] New: gcc trunk's ASAN at -O3 missed a stack-use-after-scope shaohua.li at inf dot ethz.ch
` (3 preceding siblings ...)
2022-12-23 15:25 ` marxin at gcc dot gnu.org
@ 2023-02-02 19:39 ` pinskia at gcc dot gnu.org
2023-02-02 19:45 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-02 19:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108085
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Hmm, using the C++ front-end, the use-after-scope still happens at -O3 but not
with the C front-end.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug sanitizer/108085] gcc trunk's ASAN at -O3 missed a stack-use-after-scope
2022-12-13 16:08 [Bug sanitizer/108085] New: gcc trunk's ASAN at -O3 missed a stack-use-after-scope shaohua.li at inf dot ethz.ch
` (4 preceding siblings ...)
2023-02-02 19:39 ` pinskia at gcc dot gnu.org
@ 2023-02-02 19:45 ` pinskia at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-02 19:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108085
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The difference between the two front-ends is at the original.
The C++ front-end adds a BLOCK around the loop while the C front-end does not.
This difference changes where the ASAN_MARK is placed with respect to the
return statement.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-02-02 19:45 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-13 16:08 [Bug sanitizer/108085] New: gcc trunk's ASAN at -O3 missed a stack-use-after-scope shaohua.li at inf dot ethz.ch
2022-12-14 8:26 ` [Bug sanitizer/108085] " marxin at gcc dot gnu.org
2022-12-14 8:27 ` rguenth at gcc dot gnu.org
2022-12-23 15:25 ` marxin at gcc dot gnu.org
2022-12-23 15:25 ` marxin at gcc dot gnu.org
2023-02-02 19:39 ` pinskia at gcc dot gnu.org
2023-02-02 19:45 ` pinskia 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).