From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 57EE1385D0CC; Wed, 26 Oct 2022 09:07:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 57EE1385D0CC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666775257; bh=0/ePUudmXWSuVj/VtAsF4BjZ0nFcNiS8RYiX8bTp6k0=; h=From:To:Subject:Date:From; b=xymfKFwMIByA06oLW8HA5t2FXJIKAg7XrEzmJQ2UVCFMvl/a182Vs+NlV1BKdThA4 2VMwQ7fel1kSQ1pt3mDYWys+Xtp522UrOQLER0WV8rYeok47WsuEx3J++i1igq0rSa WX1PvbS2gIpB9jRkwpTc0pv2iXFAMe3wjyVaazEw= From: "shaohua.li at inf dot ethz.ch" To: gcc-bugs@gcc.gnu.org Subject: [Bug sanitizer/107410] New: ASan failed to detect a heap-buffer-overflow Date: Wed, 26 Oct 2022 09:07:36 +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=3D107410 Bug ID: 107410 Summary: ASan failed to detect a heap-buffer-overflow 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, `gcc-fsanitize=3Daddress -O0` reported nothing, whi= le `gcc -fsanitize=3Daddress -Ox` (x=3D1, 2, 3, or s) reported the heap-buffer-overflow. There is a stack-buffer-overflow in `c[i] =3D 2`, whi= ch has crossed the red-zone but I believe it should not affect the heap-buffer-overflow detection. % gcc-tk -tv Using built-in specs. COLLECT_GCC=3Dgcc-tk COLLECT_LTO_WRAPPER=3D/zdata/shaoli/compilers/ccbuilder-compilers/gcc-99da5= 23359e9333555585484eb3b8f854a98f1b4/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-99da523359e93335= 55585484eb3b8f854a98f1b4 Thread model: posix Supported LTO compression algorithms: zlib gcc version 13.0.0 20221013 (experimental) (GCC)=20 % % gcc-tk -fsanitize=3Daddress -w -g -O0 a.c && ./a.out % % gcc-tk -fsanitize=3Daddress -w -g -O3 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=3D1764559=3D=3DERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000038 at pc 0x000000401210 bp 0x7fff57c272c0 sp 0x7fff57c272b8 WRITE of size 4 at 0x602000000038 thread T0 #0 0x40120f in main /zdata/shaoli/ubfuzz/synthesizer/bugs/gcc_work114/a.c:17 #1 0x7f5e7a12a082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee) #2 0x4012bd in _start (/zdata/shaoli/ubfuzz/synthesizer/bugs/gcc_work114/a.out+0x4012bd) 0x602000000038 is located 32 bytes to the right of 8-byte region [0x602000000010,0x602000000018) allocated by thread T0 here: #0 0x7f5e7a3c78bf in __interceptor_malloc ../../../../gcc/libsanitizer/asan/asan_malloc_linux.cpp:69 #1 0x40115f in main /zdata/shaoli/ubfuzz/synthesizer/bugs/gcc_work114/a.c:12 SUMMARY: AddressSanitizer: heap-buffer-overflow /zdata/shaoli/ubfuzz/synthesizer/bugs/gcc_work114/a.c:17 in main Shadow bytes around the buggy address: 0x0c047fff7fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c047fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c047fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c047fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c047fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =3D>0x0c047fff8000: fa fa 00 fa fa fa fa[fa]fa fa fa fa fa fa fa fa 0x0c047fff8010: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c047fff8020: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c047fff8030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c047fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c047fff8050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 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=3D1764559=3D=3DABORTING % % cat a.c typedef struct { int a } b; int d; int main() { for (; d !=3D 3; ++d) { char c[2]; char e[5]; char *h =3D e; int *g =3D malloc(2*sizeof(int)); int i=3D19; b k; c[i] =3D 2; k.a =3D 0; g[c[i]] =3D 1; } } %=