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/107258] New: ASAN at -O1 failed to detect a stack-under-flow
Date: Fri, 14 Oct 2022 08:44:26 +0000	[thread overview]
Message-ID: <bug-107258-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107258

            Bug ID: 107258
           Summary: ASAN at -O1 failed to detect a stack-under-flow
           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: ---

ASAN with -O1/-Os failed to detect the stack-buffer-underflow, while
-O0/-O2/-O3 can. 

% gcc-tk -v
Using built-in specs.
COLLECT_GCC=gcc-tk
COLLECT_LTO_WRAPPER=/zdata/shaoli/compilers/ccbuilder-compilers/gcc-99da523359e9333555585484eb3b8f854a98f1b4/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-99da523359e9333555585484eb3b8f854a98f1b4
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 13.0.0 20221013 (experimental) (GCC)
% 
% cat a.c
int a = -5, c, d;
static int f() {
  int b[10];
  printf("%d", b[a]);
}
int h() {
  for (; c;) {
    int *e[3];
    e;
  }
}
int main() {
  int g[4];
  g[d] = f();
  h();
}
%
% gcc-tk -w -O1 -fsanitize=address a.c && ./a.out
0
% gcc-tk -w -O3 -fsanitize=address a.c && ./a.out
=================================================================
==929009==ERROR: AddressSanitizer: stack-buffer-overflow on address
0x7fabc520007c at pc 0x00000040125d bp 0x7ffe232d2c00 sp 0x7ffe232d2bf8
READ of size 4 at 0x7fabc520007c thread T0
    #0 0x40125c in f /zdata/shaoli/ubfuzz/synthesizer/debug/a.c:4
    #1 0x40125c in main /zdata/shaoli/ubfuzz/synthesizer/debug/a.c:14
    #2 0x7fabc79a8082 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId:
1878e6b475720c7c51969e69ab2d276fae6d1dee)
    #3 0x4012fd in _start
(/zdata/shaoli/ubfuzz/synthesizer/debug/a.out+0x4012fd)

Address 0x7fabc520007c is located in stack of thread T0 at offset 124 in frame
    #0 0x4010df in main /zdata/shaoli/ubfuzz/synthesizer/debug/a.c:12

  This frame has 3 object(s):
    [48, 64) 'g' (line 13)
    [80, 104) 'e' (line 8)
    [144, 184) 'b' (line 3) <== Memory access at offset 124 underflows 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-buffer-overflow
/zdata/shaoli/ubfuzz/synthesizer/debug/a.c:4 in f
Shadow bytes around the buggy address:
  0x0ff5f8a37fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff5f8a37fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff5f8a37fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff5f8a37fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff5f8a37ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0ff5f8a38000: f1 f1 f1 f1 f1 f1 00 00 f2 f2 00 00 00 f2 f2[f2]
  0x0ff5f8a38010: f2 f2 00 00 00 00 00 f3 f3 f3 f3 f3 00 00 00 00
  0x0ff5f8a38020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff5f8a38030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff5f8a38040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0ff5f8a38050: 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
==929009==ABORTING
%

Compiler explorer: https://godbolt.org/z/Gea6cr9E1

             reply	other threads:[~2022-10-14  8:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-14  8:44 shaohua.li at inf dot ethz.ch [this message]
2022-10-14  9:04 ` [Bug sanitizer/107258] " 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-107258-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: link
Be 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).