public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/107746] New: gcc -O1 misses a stack-buffer-overflow
@ 2022-11-18  9:19 shaohua.li at inf dot ethz.ch
  2022-11-21  9:49 ` [Bug sanitizer/107746] " marxin at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2022-11-18  9:19 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107746
           Summary: gcc -O1 misses 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, `gcc-trunk -O1 -fsanitize=address` misses the
stack-buffer-overflow, while `gcc-trunk -Ox -fsanitize=address` (x=0,2,3, or s)
can detect it.

Maybe fundamentally similar to
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107698 but that was a miss of
global-buffer-overflow.

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

% cat a.c
int a;
short b;
short *c = &b;
int *d = &a;
void main() {
  int e;
  *d = 0;
  d = &e + 3;
  *d = --*c;
}
% gcc-tk -O1 -fsanitize=address a.c && ./a.out
%
% gcc-tk -O3 -fsanitize=address a.c && ./a.out
=================================================================
==1==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7f074300002c
at pc 0x0000004011b1 bp 0x7fffa6d6a4d0 sp 0x7fffa6d6a4c8
WRITE of size 4 at 0x7f074300002c thread T0
    #0 0x4011b0 in main /app/example.c:9
    #1 0x7f0745a17082 in __libc_start_main
(/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId:
1878e6b475720c7c51969e69ab2d276fae6d1dee)
    #2 0x40125d in _start (/app/output.s+0x40125d) (BuildId:
c0151d5ad34e416e89a8cfe01d6f2ea794b64dec)

Address 0x7f074300002c is located in stack of thread T0 at offset 44 in frame
    #0 0x4010bf in main /app/example.c:5

  This frame has 1 object(s):
    [32, 36) 'e' (line 6) <== Memory access at offset 44 overflows 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 /app/example.c:9 in main
Shadow bytes around the buggy address:
  0x7f0742fffd80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7f0742fffe00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7f0742fffe80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7f0742ffff00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7f0742ffff80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x7f0743000000: f1 f1 f1 f1 04[f3]f3 f3 00 00 00 00 00 00 00 00
  0x7f0743000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7f0743000100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7f0743000180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7f0743000200: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7f0743000280: 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
==1==ABORTING
%

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

* [Bug sanitizer/107746] gcc -O1 misses a stack-buffer-overflow
  2022-11-18  9:19 [Bug sanitizer/107746] New: gcc -O1 misses a stack-buffer-overflow shaohua.li at inf dot ethz.ch
@ 2022-11-21  9:49 ` marxin at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-11-21  9:49 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Dup. Fixed with the patch attached to PR106558.

*** This bug has been marked as a duplicate of bug 106558 ***

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

end of thread, other threads:[~2022-11-21  9:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-18  9:19 [Bug sanitizer/107746] New: gcc -O1 misses a stack-buffer-overflow shaohua.li at inf dot ethz.ch
2022-11-21  9:49 ` [Bug sanitizer/107746] " 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).