public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "shaohua.li at inf dot ethz.ch" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug sanitizer/107086] New: gcc trunkc at -O1 failed to detect a stack-use-after-return Date: Thu, 29 Sep 2022 12:14:43 +0000 [thread overview] Message-ID: <bug-107086-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107086 Bug ID: 107086 Summary: gcc trunkc at -O1 failed to detect a stack-use-after-return 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: --- %gcc-tk -v Using built-in specs. COLLECT_GCC=gcc-tk COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-519196a27cf534e94f158733b25a4f9d10737031/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-519196a27cf534e94f158733b25a4f9d10737031 Thread model: posix Supported LTO compression algorithms: zlib gcc version 13.0.0 20220921 (experimental) (GCC) % %cat a.c int a, b; int *c; int d() { return 0; } static int e(int f) { int h[144]; for (; b;) h; for (; a >= 0; a = -2) c = &f; return f; } int main() { e(0); *c = 0; if (d()) { int g[28]; g; } } % % %gcc-tk -O1 -w -fsanitize=address a.c && ./a.out % %gcc-tk -O2 -w -fsanitize=address a.c && ./a.out ================================================================= ==491884==ERROR: AddressSanitizer: stack-use-after-return on address 0x7f9cd1000020 at pc 0x0000004010e1 bp 0x7ffe4ecb6150 sp 0x7ffe4ecb6148 WRITE of size 4 at 0x7f9cd1000020 thread T0 #0 0x4010e0 in main /zdata/shaoli/SanitizerFuzz/csmith-only/asan/dangling-ptr-deref-prob-10/bugs/gcc_work102_8/a.c:14 #1 0x7f9cd3a71082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee) #2 0x40114d in _start (/zdata/shaoli/SanitizerFuzz/csmith-only/asan/dangling-ptr-deref-prob-10/bugs/gcc_work102_8/a.out+0x40114d) Address 0x7f9cd1000020 is located in stack of thread T0 at offset 32 in frame #0 0x40121f in e /zdata/shaoli/SanitizerFuzz/csmith-only/asan/dangling-ptr-deref-prob-10/bugs/gcc_work102_8/a.c:4 This frame has 1 object(s): [32, 36) 'f' (line 4) <== 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-return /zdata/shaoli/SanitizerFuzz/csmith-only/asan/dangling-ptr-deref-prob-10/bugs/gcc_work102_8/a.c:14 in main Shadow bytes around the buggy address: 0x0ff41a1f7fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0ff41a1f7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0ff41a1f7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0ff41a1f7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0ff41a1f7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =>0x0ff41a1f8000: f5 f5 f5 f5[f5]f5 f5 f5 00 00 00 00 00 00 00 00 0x0ff41a1f8010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0ff41a1f8020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0ff41a1f8030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0ff41a1f8040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0ff41a1f8050: 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 ==491884==ABORTING % Compiler explorer: https://godbolt.org/z/rn9qjrb5K From the assembly code, we can see that the reason probably is the function `e()` got inlined so that the stack variable didn't get instrumented.
next reply other threads:[~2022-09-29 12:14 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-09-29 12:14 shaohua.li at inf dot ethz.ch [this message] 2022-09-29 12:34 ` [Bug sanitizer/107086] " marxin at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-107086-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).