From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5C2443858C74; Thu, 2 Feb 2023 12:10:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C2443858C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675339819; bh=OzgmGeDInBwatO1BAsc7eIq6fPkrsR7L6IRQYE0S5xE=; h=From:To:Subject:Date:From; b=f68M3XPbrvtHg2e7gxEYBNRNnl39FLd7PJZEb/4/hszhQqY5ga9cw040XGDitrEds LuPtiSDcmXUGls6QAOh1F5XD2FnmJcQfq7kFXrJIAuWTVoJkcOr9RpeNGUHmseqx4Q pAUkGZmLZO5TiXKKRh/+r+K2C+FTCtXNFIZ0xr0o= From: "shaohua.li at inf dot ethz.ch" To: gcc-bugs@gcc.gnu.org Subject: [Bug sanitizer/108637] New: ASAN at -O2 misses a stack-use-after-scope Date: Thu, 02 Feb 2023 12:10:18 +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=3D108637 Bug ID: 108637 Summary: ASAN at -O2 misses 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, marxi= n at gcc dot gnu.org Target Milestone: --- For the following code, ASAN at -O2 cannot detect the stack-use-after-scope. This happens since GCC-11. GCC-10 and below work fine. I understand that there is a type-incompatible warning. But I believe it sh= ould not affect the ASAN anyway. Compiler explorer: https://godbolt.org/z/WcbadP961 % cat a.c char a, b, c; short d; int main() { { long e =3D a; for (; b <=3D 0; b++) { char *f; d =3D 2; for (; d; d--) { int g =3D 111; f =3D &g; if (e) c =3D 0; } *f +=3D 1; a =3D *f; } } } % % gcc-tk -fsanitize=3Daddress -O2 a.c && ./a.out % % gcc-tk -fsanitize=3Daddress -O1 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=3D1=3D=3DERROR: AddressSanitizer: stack-use-after-scope on address 0x7f= b285e00020 at pc 0x000000401272 bp 0x7ffda17739c0 sp 0x7ffda17739b8 READ of size 1 at 0x7fb285e00020 thread T0 #0 0x401271 in main /a.c:15 #1 0x7fb28883d082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee) #2 0x4010bd in _start (/output.s+0x4010bd) (BuildId: cb6e8e9c15b7d8e5515d7e6b8591d2b77b5f3e21) Address 0x7fb285e00020 is located in stack of thread T0 at offset 32 in fra= me #0 0x401185 in main /a.c:3 This frame has 1 object(s): [32, 36) 'g' (line 10) <=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-scope /a.c:15 in main Shadow bytes around the buggy address: ... %=