Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-38277

SIGSEGVs in parse_view_definition, st_select_lex::master_unit and SIGSEGV and UBSAN member call on null pointer in mysql_make_view

    XMLWordPrintable

Details

    • Can result in hang or crash

    Description

      Some similarities to MDEV-35476, however no sequence is used here and the stacks (inc UBSAN) differ.

      RENAME TABLE mysql.help_topic TO mysql.help_topic1;
      CREATE VIEW mysql.help_topic AS SELECT * FROM mysql.help_topic1;
      HELP '';
      

      Leads to:

      CS 12.2.0 fd15fd2765b53d0c070dd01d86fb231024b8f284 (Debug, Clang 21.1.3-20250923) Build 10/11/2025

      Core was generated by `/test/MD101125-mariadb-12.2.0-linux-x86_64-dbg/bin/mariadbd --no-defaults --max'.
      Program terminated with signal SIGSEGV, Segmentation fault.
      #0  st_select_lex::master_unit (this=0x0) at /test/12.2_dbg/sql/sql_lex.h:1315
       
      [Current thread is 1 (LWP 1484012)]
      (gdb) bt
      #0  st_select_lex::master_unit (this=0x0) at /test/12.2_dbg/sql/sql_lex.h:1315
      #1  0x000055933e4bf04d in mysql_make_view (thd=0x7f1384000d58, share=0x7f13840806d0, view_table_alias=0x7f14900cd090, open_view_no_parse=false) at /test/12.2_dbg/sql/sql_view.cc:1819
      #2  0x000055933e1ea6ee in open_table (thd=0x7f1384000d58, table_list=0x7f14900cd090, ot_ctx=0x7f14900ccae8)at /test/12.2_dbg/sql/sql_base.cc:2230
      #3  0x000055933e1efba1 in open_and_process_table (thd=0x7f1384000d58, tables=0x7f14900cd090, counter=0x7f14900ccb9c, flags=133122, prelocking_strategy=0x7f14900ccc00, has_prelocking_list=false, ot_ctx=0x7f14900ccae8) at /test/12.2_dbg/sql/sql_base.cc:4273
      #4  0x000055933e1ee9eb in open_tables (thd=0x7f1384000d58, options=@0x7f1384006764: {m_options = DDL_options_st::OPT_NONE}, start=0x7f14900ccbb0, counter=0x7f14900ccb9c, flags=133122, prelocking_strategy=0x7f14900ccc00) at /test/12.2_dbg/sql/sql_base.cc:4756
      #5  0x000055933e1f191a in open_and_lock_tables (thd=0x7f1384000d58, options=@0x7f1384006764: {m_options = DDL_options_st::OPT_NONE}, tables=0x7f14900cd090, derived=false, flags=133122, prelocking_strategy=0x7f14900ccc00) at /test/12.2_dbg/sql/sql_base.cc:5797
      #6  0x000055933e05706e in open_and_lock_tables (thd=0x7f1384000d58, tables=0x7f14900cd090, derived=false, flags=133122)at /test/12.2_dbg/sql/sql_base.h:537
      #7  0x000055933e1f9d46 in open_system_tables_for_read (thd=0x7f1384000d58, table_list=0x7f14900cd090) at /test/12.2_dbg/sql/sql_base.cc:9829
      #8  0x000055933e3617e2 in mysqld_help_internal (thd=0x7f1384000d58, mask=0x7f1384019f50 "") at /test/12.2_dbg/sql/sql_help.cc:973
      #9  0x000055933e36165f in mysqld_help (thd=0x7f1384000d58, mask=0x7f1384019f50 "") at /test/12.2_dbg/sql/sql_help.cc:1114
      #10 0x000055933e34aef7 in mysql_execute_command (thd=0x7f1384000d58, is_called_from_prepared_stmt=false) at /test/12.2_dbg/sql/sql_parse.cc:3988
      #11 0x000055933e343cf8 in mysql_parse (thd=0x7f1384000d58, rawbuf=0x7f1384019ee0 "HELP ''", length=7, parser_state=0x7f14900d1a00)at /test/12.2_dbg/sql/sql_parse.cc:7888
      #12 0x000055933e3414d9 in dispatch_command (command=COM_QUERY, thd=0x7f1384000d58, packet=0x7f138400b239 "HELP ''", packet_length=7, blocking=true) at /test/12.2_dbg/sql/sql_parse.cc:1878
      #13 0x000055933e34477a in do_command (thd=0x7f1384000d58, blocking=true)at /test/12.2_dbg/sql/sql_parse.cc:1417
      #14 0x000055933e537afe in do_handle_one_connection (connect=0x559341dc4218, put_in_cache=true) at /test/12.2_dbg/sql/sql_connect.cc:1503
      #15 0x000055933e5378e1 in handle_one_connection (arg=0x559341d039f8)at /test/12.2_dbg/sql/sql_connect.cc:1415
      #16 0x00007f149289ca94 in start_thread (arg=<optimized out>)at ./nptl/pthread_create.c:447
      #17 0x00007f1492929c3c in clone3 ()at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
      

      Bug Detection Matrix

          Rel    o/d  Build   Commit                                    UniqueID observed             
      CS  10.6   dbg  101125  759e3523e3d832b174cf0a612704da38b2557b40  SIGSEGV|st_select_lex::master_unit|mysql_make_view|open_table|open_and_process_table
      CS  10.6   opt  101125  759e3523e3d832b174cf0a612704da38b2557b40  SIGSEGV|mysql_make_view|open_table|open_and_process_table|open_tables
      CS  10.11  dbg  101125  536cd151f0370216d9ba4c15f40c7037060972a5  SIGSEGV|st_select_lex::master_unit|mysql_make_view|open_table|open_and_process_table
      CS  10.11  opt  101125  536cd151f0370216d9ba4c15f40c7037060972a5  SIGSEGV|mysql_make_view|open_table|open_and_process_table|open_tables
      CS  11.4   dbg  101125  a1bb5c94fda453baa99e57e3927eaa7cd3c8bafe  SIGSEGV|st_select_lex::master_unit|mysql_make_view|open_table|open_and_process_table
      CS  11.4   opt  101125  a1bb5c94fda453baa99e57e3927eaa7cd3c8bafe  SIGSEGV|mysql_make_view|open_table|open_and_process_table|open_tables
      CS  11.8   dbg  101125  e0428264d0095472c015eb58c46be68ca1a320ee  SIGSEGV|st_select_lex::master_unit|mysql_make_view|open_table|open_and_process_table
      CS  11.8   opt  101125  e0428264d0095472c015eb58c46be68ca1a320ee  SIGSEGV|mysql_make_view|open_table|open_and_process_table|open_tables
      CS  12.1   dbg  101125  ba00960fdaee67a4efff6866e31f446bf486a1c2  SIGSEGV|st_select_lex::master_unit|mysql_make_view|open_table|open_and_process_table
      CS  12.1   opt  101125  ba00960fdaee67a4efff6866e31f446bf486a1c2  SIGSEGV|mysql_make_view|open_table|open_and_process_table|open_tables
      CS  12.2   dbg  101125  fd15fd2765b53d0c070dd01d86fb231024b8f284  SIGSEGV|st_select_lex::master_unit|mysql_make_view|open_table|open_and_process_table
      CS  12.2   opt  101125  fd15fd2765b53d0c070dd01d86fb231024b8f284  SIGSEGV|mysql_make_view|open_table|open_and_process_table|open_tables
      ES  10.6   dbg  101125  f0d4d34fb0314b03fddb71fb9dbde372744a8c13  SIGSEGV|st_select_lex::master_unit|mysql_make_view|open_table|open_and_process_table
      ES  10.6   opt  101125  f0d4d34fb0314b03fddb71fb9dbde372744a8c13  SIGSEGV|mysql_make_view|open_table|open_and_process_table|open_tables
      ES  11.4   dbg  101125  b81ec4b57a5ddce88b8e2b2d16b64625ffdaa0e6  SIGSEGV|st_select_lex::master_unit|mysql_make_view|open_table|open_and_process_table
      ES  11.4   opt  101125  b81ec4b57a5ddce88b8e2b2d16b64625ffdaa0e6  SIGSEGV|mysql_make_view|open_table|open_and_process_table|open_tables
      ES  11.8   dbg  101125  db36e8fb3bcdae26dd0acdcb2b52f7f4eb014df6  SIGSEGV|st_select_lex::master_unit|mysql_make_view|open_table|open_and_process_table
      ES  11.8   opt  101125  db36e8fb3bcdae26dd0acdcb2b52f7f4eb014df6  SIGSEGV|mysql_make_view|open_table|open_and_process_table|open_tables
      MS  5.5    dbg  070123  bac287c315b1792e7ae33f91add6a60292f9bae8  SIGSEGV|mysql_make_view|open_new_frm|open_table|open_and_process_table
      MS  5.5    opt  070123  bac287c315b1792e7ae33f91add6a60292f9bae8  SIGSEGV|mysql_make_view|open_new_frm|open_table|open_and_process_table
      MS  5.6    dbg  070123  dab95781a1244104d6b87020ac2fc4d190ba2946  SIGSEGV|mysql_make_view|open_table|open_and_process_table|open_tables
      MS  5.6    opt  070123  dab95781a1244104d6b87020ac2fc4d190ba2946  SIGSEGV|mysql_make_view|open_table|open_and_process_table|open_tables
      MS  5.7    dbg  070525  f7680e98b6bbe3500399fbad465d08a6b75d7a5c  SIGSEGV|parse_view_definition|open_table|open_and_process_table|open_tables
      MS  5.7    opt  070525  f7680e98b6bbe3500399fbad465d08a6b75d7a5c  SIGSEGV|parse_view_definition|open_table|open_and_process_table|open_tables
      MS  8.0    dbg  060224  49ef33f7edadef3ae04665e73d1babd40179a4f1  SIGSEGV|parse_view_definition|open_table|open_and_process_table|open_tables
      MS  8.0    opt  060224  49ef33f7edadef3ae04665e73d1babd40179a4f1  SIGSEGV|parse_view_definition|open_table|open_and_process_table|open_tables
      MS  9.1    dbg  211024  61a3a1d8ef15512396b4c2af46e922a19bf2b174  SIGSEGV|parse_view_definition|open_table|open_and_process_table|open_tables
      MS  9.1    opt  211024  61a3a1d8ef15512396b4c2af46e922a19bf2b174  SIGSEGV|parse_view_definition|open_table|open_and_process_table|open_tables
      

      UBSAN sees a member call on null pointer in mysql_make_view:

      CS 12.2.0 fd15fd2765b53d0c070dd01d86fb231024b8f284 (Debug, UBASAN, Clang 21.1.3-20250923) Build 10/11/2025

      /test/12.2_dbg_san/sql/sql_view.cc:1819:40: runtime error: member call on null pointer of type 'st_select_lex'
          #0 0x64d1606146d2 in mysql_make_view(THD*, TABLE_SHARE*, TABLE_LIST*, bool) /test/12.2_dbg_san/sql/sql_view.cc:1819:40
          #1 0x64d15faf0973 in open_table(THD*, TABLE_LIST*, Open_table_context*) /test/12.2_dbg_san/sql/sql_base.cc:2230:9
          #2 0x64d15fb04d35 in open_and_process_table(THD*, TABLE_LIST*, unsigned int*, unsigned int, Prelocking_strategy*, bool, Open_table_context*) /test/12.2_dbg_san/sql/sql_base.cc:4273:14
          #3 0x64d15fb04d35 in open_tables(THD*, DDL_options_st const&, TABLE_LIST**, unsigned int*, unsigned int, Prelocking_strategy*) /test/12.2_dbg_san/sql/sql_base.cc:4756:14
          #4 0x64d15fb15ff1 in open_and_lock_tables(THD*, DDL_options_st const&, TABLE_LIST*, bool, unsigned int, Prelocking_strategy*) /test/12.2_dbg_san/sql/sql_base.cc:5797:7
          #5 0x64d15f58e534 in open_and_lock_tables(THD*, TABLE_LIST*, bool, unsigned int) /test/12.2_dbg_san/sql/sql_base.h:537:10
          #6 0x64d15fb39d99 in open_system_tables_for_read(THD*, TABLE_LIST*) /test/12.2_dbg_san/sql/sql_base.cc:9829:7
          #7 0x64d16004ccb1 in mysqld_help_internal(THD*, char const*) /test/12.2_dbg_san/sql/sql_help.cc:973:7
          #8 0x64d16004ccb1 in mysqld_help(THD*, char const*) /test/12.2_dbg_san/sql/sql_help.cc:1114:12
          #9 0x64d15ffff379 in mysql_execute_command(THD*, bool) /test/12.2_dbg_san/sql/sql_parse.cc:3988:10
          #10 0x64d15ffde1e8 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/12.2_dbg_san/sql/sql_parse.cc:7888:18
          #11 0x64d15ffd79a3 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/12.2_dbg_san/sql/sql_parse.cc:1878:7
          #12 0x64d15ffe062a in do_command(THD*, bool) /test/12.2_dbg_san/sql/sql_parse.cc:1417:17
          #13 0x64d1607edb3c in do_handle_one_connection(CONNECT*, bool) /test/12.2_dbg_san/sql/sql_connect.cc:1503:11
          #14 0x64d1607ed645 in handle_one_connection /test/12.2_dbg_san/sql/sql_connect.cc:1415:5
          #15 0x64d15ef3cb4a in asan_thread_start(void*) crtstuff.c
          #16 0x71d915e9ca93 in start_thread nptl/pthread_create.c:447:8
          #17 0x71d915f29c3b in clone3 misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
       
      SUMMARY: UndefinedBehaviorSanitizer: null-pointer-use /test/12.2_dbg_san/sql/sql_view.cc:1819:40 
      

      Setup:

      Compiled with a recent version of Clang and LLVM. Ubuntu instructions for Clang/LLVM 18:
        # Note: It is strongly recommended to uninstall all old Clang & LLVM packages (ref  dpkg --list | grep -iE 'clang|llvm'  and use  apt purge  and  dpkg --purge  to remove the packages), before installing Clang/LLVM 18
           sudo apt install clang llvm-18 llvm-18-linker-tools llvm-18-runtime llvm-18-tools llvm-18-dev libstdc++-14-dev llvm-dev lld-18
      Compiled with: "-DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_C{,XX}_FLAGS='-march=native -mtune=native'" and:
          -DWITH_ASAN=ON -DWITH_ASAN_SCOPE=ON -DWITH_UBSAN=ON -DWSREP_LIB_WITH_ASAN=ON
      Set before execution:
          export UBSAN_OPTIONS=print_stacktrace=1:report_error_type=1   # And you may also want to supress UBSAN startup issues using 'suppressions=UBSAN.filter' in UBSAN_OPTIONS. For an example of UBSAN.filter, which includes current startup issues see: https://github.com/mariadb-corporation/mariadb-qa/blob/master/UBSAN.filter
          export ASAN_OPTIONS=quarantine_size_mb=512:atexit=0:detect_invalid_pointer_pairs=3:dump_instruction_bytes=1:abort_on_error=1:allocator_may_return_null=1
      

      SAN Bug Detection Matrix

          Rel    o/d  Build   Commit                                    UniqueID observed             
      CS  10.6   dbg  101125  759e3523e3d832b174cf0a612704da38b2557b40  UBSAN|member call on null pointer of type 'st_select_lex'|sql/sql_view.cc|mysql_make_view|open_table|open_and_process_table|open_tables
      CS  10.6   opt  101125  759e3523e3d832b174cf0a612704da38b2557b40  UBSAN|member call on null pointer of type 'st_select_lex'|sql/sql_view.cc|mysql_make_view|open_table|open_and_process_table|open_tables
      CS  10.11  dbg  101125  536cd151f0370216d9ba4c15f40c7037060972a5  UBSAN|member call on null pointer of type 'st_select_lex'|sql/sql_view.cc|mysql_make_view|open_table|open_and_process_table|open_tables
      CS  10.11  opt  101125  536cd151f0370216d9ba4c15f40c7037060972a5  UBSAN|member call on null pointer of type 'st_select_lex'|sql/sql_view.cc|mysql_make_view|open_table|open_and_process_table|open_tables
      CS  11.4   dbg  101125  a1bb5c94fda453baa99e57e3927eaa7cd3c8bafe  UBSAN|member call on null pointer of type 'st_select_lex'|sql/sql_view.cc|mysql_make_view|open_table|open_and_process_table|open_tables
      CS  11.4   opt  101125  a1bb5c94fda453baa99e57e3927eaa7cd3c8bafe  UBSAN|member call on null pointer of type 'st_select_lex'|sql/sql_view.cc|mysql_make_view|open_table|open_and_process_table|open_tables
      CS  11.8   dbg  101125  e0428264d0095472c015eb58c46be68ca1a320ee  UBSAN|member call on null pointer of type 'st_select_lex'|sql/sql_view.cc|mysql_make_view|open_table|open_and_process_table|open_tables
      CS  11.8   opt  101125  e0428264d0095472c015eb58c46be68ca1a320ee  UBSAN|member call on null pointer of type 'st_select_lex'|sql/sql_view.cc|mysql_make_view|open_table|open_and_process_table|open_tables
      CS  12.1   dbg  101125  ba00960fdaee67a4efff6866e31f446bf486a1c2  UBSAN|member call on null pointer of type 'st_select_lex'|sql/sql_view.cc|mysql_make_view|open_table|open_and_process_table|open_tables
      CS  12.1   opt  101125  ba00960fdaee67a4efff6866e31f446bf486a1c2  UBSAN|member call on null pointer of type 'st_select_lex'|sql/sql_view.cc|mysql_make_view|open_table|open_and_process_table|open_tables
      CS  12.2   dbg  101125  fd15fd2765b53d0c070dd01d86fb231024b8f284  UBSAN|member call on null pointer of type 'st_select_lex'|sql/sql_view.cc|mysql_make_view|open_table|open_and_process_table|open_tables
      CS  12.2   opt  101125  fd15fd2765b53d0c070dd01d86fb231024b8f284  UBSAN|member call on null pointer of type 'st_select_lex'|sql/sql_view.cc|mysql_make_view|open_table|open_and_process_table|open_tables
      ES  10.6   dbg  101125  f0d4d34fb0314b03fddb71fb9dbde372744a8c13  UBSAN|member call on null pointer of type 'st_select_lex'|sql/sql_view.cc|mysql_make_view|open_table|open_and_process_table|open_tables
      ES  10.6   opt  101125  f0d4d34fb0314b03fddb71fb9dbde372744a8c13  UBSAN|member call on null pointer of type 'st_select_lex'|sql/sql_view.cc|mysql_make_view|open_table|open_and_process_table|open_tables
      ES  11.4   dbg  101125  b81ec4b57a5ddce88b8e2b2d16b64625ffdaa0e6  UBSAN|member call on null pointer of type 'st_select_lex'|sql/sql_view.cc|mysql_make_view|open_table|open_and_process_table|open_tables
      ES  11.4   opt  101125  b81ec4b57a5ddce88b8e2b2d16b64625ffdaa0e6  UBSAN|member call on null pointer of type 'st_select_lex'|sql/sql_view.cc|mysql_make_view|open_table|open_and_process_table|open_tables
      ES  11.8   dbg  101125  db36e8fb3bcdae26dd0acdcb2b52f7f4eb014df6  UBSAN|member call on null pointer of type 'st_select_lex'|sql/sql_view.cc|mysql_make_view|open_table|open_and_process_table|open_tables
      ES  11.8   opt  101125  db36e8fb3bcdae26dd0acdcb2b52f7f4eb014df6  UBSAN|member call on null pointer of type 'st_select_lex'|sql/sql_view.cc|mysql_make_view|open_table|open_and_process_table|open_tables
      

      Testcase is CLI and MTR compatible.

      Attachments

        Issue Links

          Activity

            People

              sanja Oleksandr Byelkin
              Roel Roel Van de Paar
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.