public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/108817] New: ASAN at -O3 failed to detect a global-buffer-overflow
@ 2023-02-16  8:16 shaohua.li at inf dot ethz.ch
  2023-02-17 14:31 ` [Bug sanitizer/108817] " marxin at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2023-02-16  8:16 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108817
           Summary: ASAN at -O3 failed to detect a global-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 -O3 (GCC>=12) missed the global
buffer-overflow, while other opt levels detected it. GCC-11 can detect it at
all opt levels. Although I was using -O3, I indeed observed the overflow read
and the ASAN check in the assembly code.

Compiler explorer: https://godbolt.org/z/9Yenz8roT


% cat a.c
long a;
int b[3];
char c;
int main() {
  int d;
  a = 2;
  for (; a >= 0; a--) {
    d = 0;
    for (; d <= 3; d++)
      c = b[a+1];
  }
  return c;
}
%
% gcc-tk -O3 -fsanitize=address a.c && ./a.out
% 
% gcc-tk -O2 -fsanitize=address a.c && ./a.out
=================================================================
==1==ERROR: AddressSanitizer: global-buffer-overflow on address 0x0000004041cc
at pc 0x00000040112b bp 0x7ffd88ccd090 sp 0x7ffd88ccd088
READ of size 4 at 0x0000004041cc thread T0
    #0 0x40112a in main /a.c:10
    #1 0x7f8b3fad2082 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId:
1878e6b475720c7c51969e69ab2d276fae6d1dee)
    #2 0x40119d in _start (/a.s+0x40119d) (BuildId:
8f8919b865053b4da8e28daf8de45ed9390d0057)

0x0000004041cc is located 52 bytes before global variable 'a' defined in '/a.c'
(0x404200) of size 8
0x0000004041cc is located 0 bytes after global variable 'b' defined in '/a.c'
(0x4041c0) of size 12
SUMMARY: AddressSanitizer: global-buffer-overflow /a.c:10 in main
Shadow bytes around the buggy address:
  0x000000403f00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x000000403f80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x000000404000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x000000404080: 00 00 00 00 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
  0x000000404100: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 00 00 00 00
=>0x000000404180: 01 f9 f9 f9 f9 f9 f9 f9 00[04]f9 f9 f9 f9 f9 f9
  0x000000404200: 00 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 00 00 00 00
  0x000000404280: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x000000404300: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x000000404380: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x000000404400: 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 
...
%

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-02-17 14:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-16  8:16 [Bug sanitizer/108817] New: ASAN at -O3 failed to detect a global-buffer-overflow shaohua.li at inf dot ethz.ch
2023-02-17 14:31 ` [Bug sanitizer/108817] " marxin at gcc dot gnu.org

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).