https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128842
Bug ID: 128842
Summary: AddressSanitizer: global-buffer-overflow in
parse_optimize_options(tree_node*, bool) before ICE
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: haoxintu at gmail dot com
Target Milestone: ---
Hi,
$cat reduced.c
__attribute__((optimize("x"))) void f(void);
$$ ASAN_OPTIONS=detect_leaks=0:abort_on_error=1 gcc -c repro.c
=================================================================
==4063201==ERROR: AddressSanitizer: global-buffer-overflow on address
0x00000f5fbd7c at pc 0x000000f26829 bp 0x7ffdd6d63950 sp 0x7ffdd6d63940
READ of size 4 at 0x00000f5fbd7c thread T0
#0 0xf26828 in parse_optimize_options(tree_node*, bool)
/home/haoxin/research/cottontail/gcc/gcc/c-family/c-common.cc:6303
#1 0x113bda0 in handle_optimize_attribute
/home/haoxin/research/cottontail/gcc/gcc/c-family/c-attribs.cc:5866
#2 0x8712d1 in decl_attributes(tree_node**, tree_node*, int, tree_node*)
/home/haoxin/research/cottontail/gcc/gcc/attribs.cc:905
#3 0x8dc04a in c_decl_attributes
/home/haoxin/research/cottontail/gcc/gcc/c/c-decl.cc:5747
#4 0x96f03d in start_decl(c_declarator*, c_declspecs*, bool, tree_node*,
bool, unsigned long*) /home/haoxin/research/cottontail/gcc/gcc/c/c-decl.cc:5902
#5 0xce9a19 in c_parser_declaration_or_fndef
/home/haoxin/research/cottontail/gcc/gcc/c/c-parser.cc:3083
#6 0xd5c2f3 in c_parser_external_declaration
/home/haoxin/research/cottontail/gcc/gcc/c/c-parser.cc:2276
#7 0xd5f4e0 in c_parser_translation_unit
/home/haoxin/research/cottontail/gcc/gcc/c/c-parser.cc:2115
#8 0xd5f4e0 in c_parse_file()
/home/haoxin/research/cottontail/gcc/gcc/c/c-parser.cc:31603
#9 0x107abf7 in c_common_parse_file()
/home/haoxin/research/cottontail/gcc/gcc/c-family/c-opts.cc:1442
#10 0x42a79ad in compile_file
/home/haoxin/research/cottontail/gcc/gcc/toplev.cc:455
#11 0x42b79c0 in do_compile
/home/haoxin/research/cottontail/gcc/gcc/toplev.cc:2228
#12 0x42b79c0 in toplev::main(int, char**)
/home/haoxin/research/cottontail/gcc/gcc/toplev.cc:2396
#13 0xd2991e3 in main /home/haoxin/research/cottontail/gcc/gcc/main.cc:39
#14 0x7f23d5e29d8f in __libc_start_call_main
../sysdeps/nptl/libc_start_call_main.h:58
#15 0x7f23d5e29e3f in __libc_start_main_impl ../csu/libc-start.c:392
#16 0x84a904 in _start
(/home/haoxin/research/cottontail/gcc/build-asan/install/libexec/gcc/x86_64-pc-linux-gnu/17.0.0/cc1+0x84a904)
0x00000f5fbd7c is located 4 bytes to the left of global variable '*.LC4876'
defined in 'options.cc' (0xf5fbd80) of size 4
'*.LC4876' is ascii string 'Ada'
0x00000f5fbd7c is located 56 bytes to the right of global variable
'cl_options_count' defined in 'options.cc:4221:20' (0xf5fbd40) of size 4
SUMMARY: AddressSanitizer: global-buffer-overflow
/home/haoxin/research/cottontail/gcc/gcc/c-family/c-common.cc:6303 in
parse_optimize_options(tree_node*, bool)
Shadow bytes around the buggy address:
0x000081eb7750: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x000081eb7760: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x000081eb7770: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x000081eb7780: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x000081eb7790: 00 00 00 00 00 00 00 00 00 00 00 00 f9 f9 f9 f9
=>0x000081eb77a0: 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9[f9]
0x000081eb77b0: 04 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9
0x000081eb77c0: 07 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9
0x000081eb77d0: 02 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9
0x000081eb77e0: 06 f9 f9 f9 f9 f9 f9 f9 02 f9 f9 f9 f9 f9 f9 f9
0x000081eb77f0: 00 f9 f9 f9 f9 f9 f9 f9 03 f9 f9 f9 f9 f9 f9 f9
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
Shadow gap: cc
==4063201==ABORTING
reduced.c:1:1: internal compiler error: Aborted
1 | __attribute__((optimize("x"))) void f(void);
| ^~~~~~~~~~~~~
0xd35d918 internal_error(char const*, ...)
/home/haoxin/research/cottontail/gcc/gcc/diagnostic-global-context.cc:787
0x42a5253 crash_signal
/home/haoxin/research/cottontail/gcc/gcc/toplev.cc:325
0x7f23d5e4251f ???
./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0x7f23d5e969fc __pthread_kill_implementation
./nptl/pthread_kill.c:44
0x7f23d5e969fc __pthread_kill_internal
./nptl/pthread_kill.c:78
0x7f23d5e969fc __GI___pthread_kill
./nptl/pthread_kill.c:89
0x7f23d5e42475 __GI_raise
../sysdeps/posix/raise.c:26
0x7f23d5e287f2 __GI_abort
./stdlib/abort.c:79
0x7f23d6ad2711 __sanitizer::Abort()
../../../../src/libsanitizer/sanitizer_common/sanitizer_posix_libcdep.cpp:151
0x7f23d6ade2cb __sanitizer::Die()
../../../../src/libsanitizer/sanitizer_common/sanitizer_termination.cpp:58
0x7f23d6abd77b __asan::ScopedInErrorReport::~ScopedInErrorReport()
../../../../src/libsanitizer/asan/asan_report.cpp:190
0x7f23d6abd014 __asan::ReportGenericError(unsigned long, unsigned long,
unsigned long, unsigned long, bool, unsigned long, unsigned int, bool)
../../../../src/libsanitizer/asan/asan_report.cpp:478
0x7f23d6abdd3a __asan_report_load4
../../../../src/libsanitizer/asan/asan_rtl.cpp:120
0xf26828 parse_optimize_options(tree_node*, bool)
/home/haoxin/research/cottontail/gcc/gcc/c-family/c-common.cc:6303
0x113bda0 handle_optimize_attribute
/home/haoxin/research/cottontail/gcc/gcc/c-family/c-attribs.cc:5866
0x8712d1 decl_attributes(tree_node**, tree_node*, int, tree_node*)
/home/haoxin/research/cottontail/gcc/gcc/attribs.cc:905
0x8dc04a c_decl_attributes
/home/haoxin/research/cottontail/gcc/gcc/c/c-decl.cc:5747
0x96f03d start_decl(c_declarator*, c_declspecs*, bool, tree_node*, bool,
unsigned long*)
/home/haoxin/research/cottontail/gcc/gcc/c/c-decl.cc:5902
0xce9a19 c_parser_declaration_or_fndef
/home/haoxin/research/cottontail/gcc/gcc/c/c-parser.cc:3083
0xd5c2f3 c_parser_external_declaration
/home/haoxin/research/cottontail/gcc/gcc/c/c-parser.cc:2276
/home/haoxin/research/cottontail/gcc/build-asan/install/libexec/gcc/x86_64-pc-linux-gnu/17.0.0/cc1
-quiet -imultiarch x86_64-linux-gnu reduced.c -quiet -dumpbase reduced.c
-dumpbase-ext .c -mtune=generic -march=x86-64 -o /tmp/cchcgoFz.s
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
$gcc -v
Using built-in specs.
COLLECT_GCC=/gcc/build-asan/install/bin/gcc
COLLECT_LTO_WRAPPER=/gcc/build-asan/install/libexec/gcc/x86_64-pc-linux-gnu/17.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /gcc/configure --prefix=/gcc/build-asan/install
--disable-multilib --disable-bootstrap --disable-werror --disable-libsanitizer
--disable-nls --enable-languages=c,lto CC=gcc CXX=g++ CFLAGS='-O1 -g1
-fsanitize=address,undefined -fno-omit-frame-pointer' CXXFLAGS='-O1 -g1
-fsanitize=address,undefined -fno-omit-frame-pointer'
LDFLAGS='-fsanitize=address,undefined -fno-omit-frame-pointer'
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 17.0.0 20261017 (experimental) (GCC)
Note that the failure can only be reproduced when
"-fsanitize=address,undefined" is linked for building.
Thanks.