From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 192D73858D37; Thu, 29 Sep 2022 12:14:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 192D73858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664453684; bh=i2PLBOy7arPtIcdxewR4x5+8Vk33CxGs6HdwIetSC3c=; h=From:To:Subject:Date:From; b=IhyJeO9GZMI+hCRMImCENb9gox97fvQsvd1uMwSdTSZc9ZztF5jTYnjekln7RQY/H ynLb+mJdXwQN1ZFVk8nZyIe/LH2NSZjzgztWw062j7Sq9OmJesJGsyqx4WowrOXVqR zAnSDhcSXUv+hQbMz3XVqkvtsWFm8xB795uvlLfI= From: "shaohua.li at inf dot ethz.ch" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: sanitizer X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: shaohua.li at inf dot ethz.ch X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107086 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, marxi= n at gcc dot gnu.org Target Milestone: --- %gcc-tk -v Using built-in specs. COLLECT_GCC=3Dgcc-tk COLLECT_LTO_WRAPPER=3D/zdata/shaoli/compilers/ccbuilder-compilers/gcc-51919= 6a27cf534e94f158733b25a4f9d10737031/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=3Dc,c++ --prefix=3D/zdata/shaoli/compilers/ccbuilder-compilers/gcc-519196a27cf534e9= 4f158733b25a4f9d10737031 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 >=3D 0; a =3D -2) c =3D &f; return f; } int main() { e(0); *c =3D 0; if (d()) { int g[28]; g; } } % % %gcc-tk -O1 -w -fsanitize=3Daddress a.c && ./a.out % %gcc-tk -O2 -w -fsanitize=3Daddress a.c && ./a.out =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D491884=3D=3DERROR: 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/bug= s/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/bu= gs/gcc_work102_8/a.out+0x40114d) Address 0x7f9cd1000020 is located in stack of thread T0 at offset 32 in fra= me #0 0x40121f in e /zdata/shaoli/SanitizerFuzz/csmith-only/asan/dangling-ptr-deref-prob-10/bug= s/gcc_work102_8/a.c:4 This frame has 1 object(s): [32, 36) 'f' (line 4) <=3D=3D 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/bug= s/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 =3D>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=20 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 =3D=3D491884=3D=3DABORTING % 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.=