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/108541] New: ASAN since GCC 9 missed a stack-buffer-overflow
Date: Wed, 25 Jan 2023 16:41:33 +0000	[thread overview]
Message-ID: <bug-108541-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 108541
           Summary: ASAN since GCC 9 missed a stack-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, marxin at gcc dot gnu.org
  Target Milestone: ---

For the following code, ASAN at -O0 missed the stack-buffer-overflow while
other opt levels caught it. This issue happens since GCC-9. GCC-8 and before
worked fine.

I also noticed that there is an incompatible pointer assignment `i = &m`, but
anyway the bufferoverflow should be reported.

Clang can detect it at all opt levels.

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

% cat a.c
struct a {
  long b;
  int c;
  long d;
  short e;
  long f;
  long g;
};
struct {
  struct a b;
  unsigned : 6;
} h, *i;
int j;
int main() {
  struct a *k;
  &k;
  long l[3];
  l[j] = 4;
  int m = 1;
  i = &m;
  *i = h;
  return m;
}
% 
% gcc-tk -fsanitize=address -w -O0 a.c && ./a.out
% 
% gcc-tk -fsanitize=address -w -O1 a.c && ./a.out
=================================================================
==1==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7f8605800030
at pc 0x0000004012e0 bp 0x7ffdfd9e9b10 sp 0x7ffdfd9e9b08
WRITE of size 56 at 0x7f8605800030 thread T0
    #0 0x4012df in main /a.c:21
    #1 0x7f860810f082 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId:
1878e6b475720c7c51969e69ab2d276fae6d1dee)
    #2 0x4010cd in _start (/a.s+0x4010cd) (BuildId:
62f9205a5d8cda9f9cd98eb2592c0ba25a6a0a20)

Address 0x7f8605800030 is located in stack of thread T0 at offset 48 in frame
    #0 0x401195 in main /app/example.c:14

  This frame has 2 object(s):
    [48, 52) 'm' (line 19) <== Memory access at offset 48 partially overflows
this variable
    [64, 88) 'l' (line 17) <== Memory access at offset 48 partially 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 /a.c:21 in main
Shadow bytes around the buggy address:
...
%

             reply	other threads:[~2023-01-25 16:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-25 16:41 shaohua.li at inf dot ethz.ch [this message]
2023-01-26  9:24 ` [Bug sanitizer/108541] ASAN since GCC 9 missed a stack-buffer-overflow since r9-4503-g6e644a50045f8032 marxin at gcc dot gnu.org
2023-03-16 14:30 ` 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-108541-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).