public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/110527] New: [10/11/12/13/14 Regression] ASan is missing array out-of-bounds check
@ 2023-07-03  5:05 jwzeng at nuaa dot edu.cn
  2023-07-03  5:12 ` [Bug sanitizer/110527] " pinskia at gcc dot gnu.org
  2023-07-03  7:35 ` jakub at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: jwzeng at nuaa dot edu.cn @ 2023-07-03  5:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110527
           Summary: [10/11/12/13/14 Regression] ASan is missing array
                    out-of-bounds check
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jwzeng at nuaa dot edu.cn
                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: ---

Link to the Compiler Explorer: https://godbolt.org/z/YKaT3YdTx

The following snippet:

#include <stdio.h>
unsigned int aa = 204;
unsigned char bb = 126;
unsigned short cc[19][24][22][11][21];
unsigned int dd[19][24][22][11][21];
int main() {
    for (int i = 0; i < 19; ++i)
        cc[i][0][0][0][0] = 6294;
    unsigned char i = aa - 172;
    bb = cc[i][0][0][0][0];
    printf("%d\n", bb);
}

> $ gcc -O0 -fsanitize=address bug.c; ./a.out
> $ 0

Look at the statement `bb = cc[i][0][0][0][0];` in the above code snippet. The
array is out of bounds, but the program did not output any error after
compilation with "-O0 -fsanitize=address".

When I deleted the statement `unsigned int dd[19][24][22][11][21];` in the
above code snippet. Then compiled with "-O0 -fsanitize=address" again, and it
outputs the following error in this time:

> ddressSanitizer:DEADLYSIGNAL
> =================================================================
> ==1==ERROR: AddressSanitizer: SEGV on unknown address 0x000000b75e40 (pc 0x000000401251 bp 0x7ffc6e878c80 sp 0x7ffc6e878c70 T0)
> ==1==The signal is caused by a READ memory access.
>     #0 0x401251 in main /app/example.cpp:10
>     #1 0x7fd690372082 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24082) (BuildId: 1878e6b475720c7c51969e69ab2d276fae6d1dee)
>     #2 0x4010cd in _start (/app/output.s+0x4010cd) (BuildId: 18aa19a5491b44e6b2908ed7ba8b0a483242b3a5)
> 
> AddressSanitizer can not provide additional info.
> SUMMARY: AddressSanitizer: SEGV /app/example.cpp:10 in main
> ==1==ABORTING

I found that the above bug appeared in gcc 10/11/12/13/14. Earlier GCCs do not
have this bug.

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

* [Bug sanitizer/110527] [10/11/12/13/14 Regression] ASan is missing array out-of-bounds check
  2023-07-03  5:05 [Bug sanitizer/110527] New: [10/11/12/13/14 Regression] ASan is missing array out-of-bounds check jwzeng at nuaa dot edu.cn
@ 2023-07-03  5:12 ` pinskia at gcc dot gnu.org
  2023-07-03  7:35 ` jakub at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-03  5:12 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
There is a redzone for the variables but there is no way it going to be this
large. 

In this case, it just happens that

cc[204-172][0][0][0][0] points into the variable dd and therefore is a valid
address.

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

* [Bug sanitizer/110527] [10/11/12/13/14 Regression] ASan is missing array out-of-bounds check
  2023-07-03  5:05 [Bug sanitizer/110527] New: [10/11/12/13/14 Regression] ASan is missing array out-of-bounds check jwzeng at nuaa dot edu.cn
  2023-07-03  5:12 ` [Bug sanitizer/110527] " pinskia at gcc dot gnu.org
@ 2023-07-03  7:35 ` jakub at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-07-03  7:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
As mentioned, ASan can reliably detect out of bounds accesses into the fairly
small redzone around variables, for out of bounds accesses with larger distance
it is a lottery whether one hits some other variable or whatever other valid
memory or something marked as inaccessible (another redzone etc.).
-fsanitize=undefined detects this out of bounds access and you can use both at
the same time, -fsanitize=address,undefined or just -fsanitize=address,bounds

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

end of thread, other threads:[~2023-07-03  7:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-03  5:05 [Bug sanitizer/110527] New: [10/11/12/13/14 Regression] ASan is missing array out-of-bounds check jwzeng at nuaa dot edu.cn
2023-07-03  5:12 ` [Bug sanitizer/110527] " pinskia at gcc dot gnu.org
2023-07-03  7:35 ` jakub 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).