[MDEV-31802] GCC 13: sql/sys_vars.inl: runtime error: store to address ... with insufficient space for an object of type ... Created: 2023-07-31  Updated: 2023-11-28

Status: Open
Project: MariaDB Server
Component/s: Server
Affects Version/s: 10.4, 10.5, 10.6, 10.9, 10.10, 10.11, 11.0, 11.1, 11.2
Fix Version/s: 10.4, 10.5, 10.6, 10.11, 11.0, 11.1, 11.2

Type: Bug Priority: Critical
Reporter: Marko Mäkelä Assignee: Sergei Golubchik
Resolution: Unresolved Votes: 0
Labels: UBSAN

Issue Links:
Relates
relates to MDEV-26272 The macro MASTER_INFO_VAR invokes und... Closed

 Description   

When I compile the server with GCC 13.1.0, tests fail massively due to UBSAN errors on static initialization like the following:

static Sys_var_mybool Sys_automatic_sp_privileges(
       "automatic_sp_privileges",
       "Creating and dropping stored procedures alters ACLs",
       GLOBAL_VAR(sp_automatic_privileges),
       CMD_LINE(OPT_ARG), DEFAULT(TRUE));

If I compile with GCC 12.3.0, no error is reported.

The minimal steps to reproduce this should be as follows:

cmake -DWITH_UBSAN=ON -DMYSQL_MAINTAINER_MODE=WARN /mariadb/10.5
cmake --build .
sql/mariadbd --no-defaults --wrong-option

The output that I am seeing is as follows:

10.5 055f2e308bf1dd4026df65093a1166526ac35d9b

/mariadb/10.5/sql/sys_vars.inl:193:18: runtime error: store to address 0x55bf69c88ec8 with insufficient space for an object of type 'uchar'
0x55bf69c88ec8: note: pointer points here
 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
              ^ 
/mariadb/10.5/sql/sys_vars.inl:193:18: runtime error: store to address 0x55bf69c88e48 with insufficient space for an object of type 'uchar'
0x55bf69c88e48: note: pointer points here
 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
              ^ 
/mariadb/10.5/sql/sys_vars.inl:520:28: runtime error: store to address 0x55bf69409930 with insufficient space for an object of type 'uchar'
0x55bf69409930: note: pointer points here
 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
              ^ 
/mariadb/10.5/sql/sys_vars.inl:193:18: runtime error: store to address 0x55bf6940c758 with insufficient space for an object of type 'uchar'
0x55bf6940c758: note: pointer points here
 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
              ^ 
/mariadb/10.5/sql/sys_vars.inl:1839:8: runtime error: load of address 0x55bf6940c728 with insufficient space for an object of type 'uchar'
0x55bf6940c728: note: pointer points here
 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 80 00 00 00 00 00 00  00 00 00 00
              ^ 
/mariadb/10.5/sql/sys_vars.inl:1839:26: runtime error: store to address 0x55bf6940c728 with insufficient space for an object of type 'uchar'
0x55bf6940c728: note: pointer points here
 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 80 00 00 00 00 00 00  00 00 00 00
              ^ 
/mariadb/10.5/sql/sys_vars.inl:389:22: runtime error: store to address 0x55bf690c57b0 with insufficient space for an object of type 'uchar'
0x55bf690c57b0: note: pointer points here
 ff ff ff 7f  02 00 00 00 00 00 00 00  00 04 00 00 00 00 00 00  09 00 00 00 ff ff ff ff  fe fe 08 02
              ^ 
/mariadb/10.5/sql/sys_vars.inl:827:35: runtime error: store to address 0x55bf6940c8e8 with insufficient space for an object of type 'size_t'
0x55bf6940c8e8: note: pointer points here
 bf 55 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
              ^ 
/mariadb/10.5/sql/sys_vars.inl:827:35: runtime error: store to address 0x55bf6940c8d8 with insufficient space for an object of type 'size_t'
0x55bf6940c8d8: note: pointer points here
 bf 55 00 00  00 00 00 00 00 00 00 00  13 16 22 67 bf 55 00 00  00 00 00 00 00 00 00 00  00 00 00 00
              ^ 
/mariadb/10.5/sql/sys_vars.inl:193:18: runtime error: store to address 0x55bf6940c844 with insufficient space for an object of type 'uchar'
0x55bf6940c844: note: pointer points here
  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
              ^ 
/mariadb/10.5/sql/sys_vars.inl:1413:26: runtime error: store to address 0x55bf6940c768 with insufficient space for an object of type 'uchar'
0x55bf6940c768: note: pointer points here
 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00
              ^ 
/mariadb/10.5/sql/sys_vars.inl:193:18: runtime error: store to address 0x55bf69420c64 with insufficient space for an object of type 'uchar'
0x55bf69420c64: note: pointer points here
  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  13 16 22 67 bf 55 00 00  00 00 00 00 00 00 00 00
              ^ 
2023-07-31 13:00:44 0 [Warning] Can't create test file /usr/local/mysql/data/jyty.lower-test
/dev/shm/10.5u/sql/mariadbd: Can't change dir to '/usr/local/mysql/data/' (Errcode: 2 "No such file or directory")
2023-07-31 13:00:44 0 [ERROR] Aborting
/mariadb/10.5/sql/sys_vars.inl:526:14: runtime error: load of address 0x55bf6940c850 with insufficient space for an object of type 'uchar'
0x55bf6940c850: note: pointer points here
 00 00 00 00  00 00 00 00 00 00 00 00  00 01 00 01 00 01 00 00  00 00 00 00 00 00 00 00  00 00 00 00
              ^ 
/mariadb/10.5/sql/sys_vars.inl:527:25: runtime error: store to address 0x55bf6940c850 with insufficient space for an object of type 'uchar'
0x55bf6940c850: note: pointer points here
 00 00 00 00  00 00 00 00 00 00 00 00  00 01 00 01 00 01 00 00  00 00 00 00 00 00 00 00  00 00 00 00
              ^ 

It could be worthwhile to test this on clang as well, once MDEV-26272 has been fixed.



 Comments   
Comment by Marko Mäkelä [ 2023-07-31 ]

To debug this, you may want to set a breakpoint inside UBSAN. For my GCC 13.1.0, the call stack corresponding to the first runtime error looks like this. When using a different compiler version, the function names could be different:

10.5 055f2e308bf1dd4026df65093a1166526ac35d9b

#0  __ubsan::__ubsan_on_report () at ../../../../src/libsanitizer/ubsan/ubsan_monitor.cpp:39
#1  0x00007f2b9960f6d8 in __ubsan::UndefinedBehaviorReport::UndefinedBehaviorReport (this=this@entry=0x7ffe185ab360, IssueKind=<optimized out>, 
    Loc=@0x7ffe185ab470: {Kind = __ubsan::Location::LK_Source, SourceLoc = {Filename = 0x559491b6e020 "/mariadb/10.5/sql/sys_vars.inl", Line = 458, Column = 24}, MemoryLoc = 0, SymbolizedLoc = 0x7ffe185ab7a0}, 
    Msg=@0x7ffe185ab320: {buffer_ = {<__sanitizer::InternalMmapVectorNoCtor<char>> = {data_ = 0x7f2b95c60000 "store to address 0x55949676f560 with insufficient space for an object of type 'uchar'", capacity_bytes_ = 4096, size_ = 86}, <No data fields>}}) at ../../../../src/libsanitizer/ubsan/ubsan_monitor.cpp:29
#2  0x00007f2b996081ed in __ubsan::Diag::~Diag (this=this@entry=0x7ffe185ab470, __in_chrg=<optimized out>) at ../../../../src/libsanitizer/ubsan/ubsan_diag.cpp:352
#3  0x00007f2b9960c458 in handleTypeMismatchImpl (Data=Data@entry=0x55949a7bb000, Pointer=Pointer@entry=94096667899232, Opts=<optimized out>) at ../../../../src/libsanitizer/ubsan/ubsan_handlers.cpp:127
#4  0x00007f2b9960d71f in __ubsan::__ubsan_handle_type_mismatch_v1 (Data=Data@entry=0x55949a7bb000, Pointer=Pointer@entry=94096667899232) at ../../../../src/libsanitizer/ubsan/ubsan_handlers.cpp:142
#5  0x000055949449766a in Sys_var_mybool::Sys_var_mybool (this=0x55949e301460 <Sys_automatic_sp_privileges>, name_arg=<optimized out>, comment=<optimized out>, flag_args=<optimized out>, off=<optimized out>, 
    size=<optimized out>, getopt=<optimized out>, def_val=<optimized out>, lock=<optimized out>, binlog_status_arg=<optimized out>, on_check_func=<optimized out>, on_update_func=<optimized out>, 
    substitute=<optimized out>) at /mariadb/10.5/sql/sys_vars.inl:458
#6  0x000055949449ad27 in __static_initialization_and_destruction_0 () at /mariadb/10.5/sql/sys_vars.cc:498
#7  0x00005594944aed85 in _GLOBAL__sub_I_sys_vars.cc(void) () at /mariadb/10.5/sql/sys_vars.cc:6757
#8  0x00007f2b99c457f6 in call_init (env=<optimized out>, argv=0x7ffe185aef68, argc=8) at ../csu/libc-start.c:145
#9  __libc_start_main_impl (main=0x55949236a870 <main(int, char**)>, argc=8, argv=0x7ffe185aef68, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffe185aef58)
    at ../csu/libc-start.c:347
#10 0x000055949236a7a1 in _start ()

Generated at Thu Feb 08 10:26:34 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.