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/108085] New: gcc trunk's ASAN at -O3 missed a stack-use-after-scope
Date: Tue, 13 Dec 2022 16:08:37 +0000	[thread overview]
Message-ID: <bug-108085-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 108085
           Summary: gcc trunk's ASAN at -O3 missed 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, marxin at gcc dot gnu.org
  Target Milestone: ---

For the following code, ASAN at -O3 failed to report the stack-use-after-scope,
other opt levels detected it successfully.

GCC-8 works fine. 
Clang at all optimization levels reported it.

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

% cat a.c
int a;
void b() {
  int c[1];
  c;
}
int main() {
  int d[1]={1};
  int *e = d;
  a = 0;
  for (; a <= 5; ++a) {
    int f[1]={};
    e = f;
    a || (b(), 1);
  }
  return *e;
}
%
% gcc-tk -O2 -fsanitize=address -g a.c && ./a.out
=================================================================
==780198==ERROR: AddressSanitizer: stack-use-after-scope on address
0x7f2307600030 at pc 0x0000004011c5 bp 0x7ffdd19ecd80 sp 0x7ffdd19ecd78
READ of size 4 at 0x7f2307600030 thread T0
    #0 0x4011c4 in main /a.c:15
    #1 0x7f2309f41082 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId:
1878e6b475720c7c51969e69ab2d276fae6d1dee)
    #2 0x40126d in _start (/a.out+0x40126d)

Address 0x7f2307600030 is located in stack of thread T0 at offset 48 in frame
    #0 0x4010bf in main /a.c:6

  This frame has 3 object(s):
    [32, 36) 'd' (line 7)
    [48, 52) 'f' (line 11) <== Memory access at offset 48 is inside this
variable
    [64, 68) 'c' (line 3)
...
%
% gcc-tk -O3 -fsanitize=address -g a.c && ./a.out
%

             reply	other threads:[~2022-12-13 16:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-13 16:08 shaohua.li at inf dot ethz.ch [this message]
2022-12-14  8:26 ` [Bug sanitizer/108085] " marxin at gcc dot gnu.org
2022-12-14  8:27 ` rguenth at gcc dot gnu.org
2022-12-23 15:25 ` marxin at gcc dot gnu.org
2022-12-23 15:25 ` marxin at gcc dot gnu.org
2023-02-02 19:39 ` pinskia at gcc dot gnu.org
2023-02-02 19:45 ` pinskia 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-108085-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).