public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/108510] New: ASAN missed a stack-use-after-scope at -O1
@ 2023-01-24 8:30 shaohua.li at inf dot ethz.ch
2023-01-24 13:32 ` [Bug sanitizer/108510] " marxin at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2023-01-24 8:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108510
Bug ID: 108510
Summary: ASAN missed a stack-use-after-scope at -O1
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, GCC's ASAN at -O1 missed the stack-use-after-scope,
while other opt levels detected it.
I checked the assembly code, -O1 didn't optimize away the buggy code.
Compiler explorer: https://godbolt.org/z/jWPG8hMWY
% cat a.c
short a;
char b;
short *c = &a, *d;
long e;
int main() {
long *f = &e;
{
int g=0;
d = &g;
}
*d << (b = ((*f)--, c || *d));
}
%
% gcc-tk -fsanitize=address -g -O1 a.c && ./a.out
%
% gcc-tk -fsanitize=address -g -O2 a.c && ./a.out
=================================================================
==1==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7f0150b00020
at pc 0x0000004011a4 bp 0x7ffff43bc150 sp 0x7ffff43bc148
READ of size 2 at 0x7f0150b00020 thread T0
#0 0x4011a3 in main /a.c:11
#1 0x7f01534e6082 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId:
1878e6b475720c7c51969e69ab2d276fae6d1dee)
#2 0x40123d in _start (/app/output.s+0x40123d) (BuildId:
2f09fd97ce9e5ec29ed33980daf91dfdd4bb3ebc)
Address 0x7f0150b00020 is located in stack of thread T0 at offset 32 in frame
#0 0x4010bf in main /a.c:5
...
%
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug sanitizer/108510] ASAN missed a stack-use-after-scope at -O1
2023-01-24 8:30 [Bug sanitizer/108510] New: ASAN missed a stack-use-after-scope at -O1 shaohua.li at inf dot ethz.ch
@ 2023-01-24 13:32 ` marxin at gcc dot gnu.org
2023-01-24 13:39 ` shaohua.li at inf dot ethz.ch
2023-01-24 13:52 ` marxin at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: marxin at gcc dot gnu.org @ 2023-01-24 13:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108510
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |WAITING
Last reconfirmed| |2023-01-24
Ever confirmed|0 |1
--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Can you please report a test-case that does not contain the following
violation:
pr108510.c:9:7: warning: assignment to ‘short int *’ from incompatible pointer
type ‘int *’ [-Wincompatible-pointer-types]
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug sanitizer/108510] ASAN missed a stack-use-after-scope at -O1
2023-01-24 8:30 [Bug sanitizer/108510] New: ASAN missed a stack-use-after-scope at -O1 shaohua.li at inf dot ethz.ch
2023-01-24 13:32 ` [Bug sanitizer/108510] " marxin at gcc dot gnu.org
@ 2023-01-24 13:39 ` shaohua.li at inf dot ethz.ch
2023-01-24 13:52 ` marxin at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2023-01-24 13:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108510
--- Comment #2 from Li Shaohua <shaohua.li at inf dot ethz.ch> ---
Sure: (compiler explorer: https://godbolt.org/z/3qEavnan5)
% cat a.c
int a;
char b;
int *c = &a, *d;
long e;
int main() {
long *f = &e;
{
int g=0;
d = &g;
}
*d << (b = ((*f)--, c || *d));
}
%
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug sanitizer/108510] ASAN missed a stack-use-after-scope at -O1
2023-01-24 8:30 [Bug sanitizer/108510] New: ASAN missed a stack-use-after-scope at -O1 shaohua.li at inf dot ethz.ch
2023-01-24 13:32 ` [Bug sanitizer/108510] " marxin at gcc dot gnu.org
2023-01-24 13:39 ` shaohua.li at inf dot ethz.ch
@ 2023-01-24 13:52 ` marxin at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: marxin at gcc dot gnu.org @ 2023-01-24 13:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108510
Martin Liška <marxin at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|WAITING |RESOLVED
Resolution|--- |INVALID
--- Comment #3 from Martin Liška <marxin at gcc dot gnu.org> ---
(In reply to Li Shaohua from comment #2)
> Sure: (compiler explorer: https://godbolt.org/z/3qEavnan5)
>
> % cat a.c
> int a;
> char b;
> int *c = &a, *d;
> long e;
> int main() {
> long *f = &e;
> {
> int g=0;
> d = &g;
> }
So if c is non-zero, then we don't need to load *d here. Plus, the result of
the expression is unused, so the leftmost *d does not play any role.
> *d << (b = ((*f)--, c || *d));
> }
> %
If you change it to:
*d <<= (b = ((*f)--, c || *d));
you will hit the ASAN error.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-01-24 13:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-24 8:30 [Bug sanitizer/108510] New: ASAN missed a stack-use-after-scope at -O1 shaohua.li at inf dot ethz.ch
2023-01-24 13:32 ` [Bug sanitizer/108510] " marxin at gcc dot gnu.org
2023-01-24 13:39 ` shaohua.li at inf dot ethz.ch
2023-01-24 13:52 ` 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).