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

UBSAN: runtime error: member access within null pointer of type 'struct SPIDER_FIELD_CHAIN' and SIGSEGV in spider_db_open_item_ident on SELECT

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Duplicate
    • 10.4(EOL), 10.5, 10.6, 10.9(EOL), 10.10(EOL), 10.11, 11.0(EOL), 11.1(EOL)
    • N/A

    Description

      INSTALL PLUGIN Spider SONAME 'ha_spider.so';
      CREATE SERVER s FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET '../socket.sock',DATABASE'',USER'',PASSWORD'');
      CREATE TABLE t (c BLOB) ENGINE=InnoDB;
      CREATE TABLE ts (c BLOB) ENGINE=Spider COMMENT='WRAPPER "mysql",srv "s",TABLE "t"';
      SELECT TRIM(BOTH ' ' FROM c) FROM ts ORDER BY c;
      

      Leads to:

      11.0.2 368dd22a816f3b437bccd0b9ff28b9de9b1abf0a (Debug)

      /test/11.0_dbg_san/storage/spider/spd_db_conn.cc:7624:32: runtime error: member access within null pointer of type 'struct SPIDER_FIELD_CHAIN'
      

      11.0.2 368dd22a816f3b437bccd0b9ff28b9de9b1abf0a (Debug)

          #0 0x150d1b92ad7d in spider_db_open_item_ident(Item_ident*, ha_spider*, spider_string*, char const*, unsigned int, unsigned int, bool, spider_fields*) /test/11.0_dbg_san/storage/spider/spd_db_conn.cc:7624
          #1 0x150d1b92d7cd in spider_db_open_item_field(Item_field*, ha_spider*, spider_string*, char const*, unsigned int, unsigned int, bool, spider_fields*) /test/11.0_dbg_san/storage/spider/spd_db_conn.cc:7759
          #2 0x150d1b932a4c in spider_db_print_item_type(Item*, Field*, ha_spider*, spider_string*, char const*, unsigned int, unsigned int, bool, spider_fields*) /test/11.0_dbg_san/storage/spider/spd_db_conn.cc:7387
          #3 0x150d1bc59e48 in spider_mbase_handler::append_order_by(st_order*, spider_string*, char const*, unsigned int, bool, spider_fields*) /test/11.0_dbg_san/storage/spider/spd_db_mysql.cc:15213
          #4 0x150d1bc5a095 in spider_mbase_handler::append_order_by_part(st_order*, char const*, unsigned int, bool, spider_fields*, unsigned long) /test/11.0_dbg_san/storage/spider/spd_db_mysql.cc:15190
          #5 0x150d1bc768d2 in spider_group_by_handler::init_scan() /test/11.0_dbg_san/storage/spider/spd_group_by_handler.cc:1347
          #6 0x55f4e0f82c9a in Pushdown_query::execute(JOIN*) /test/11.0_dbg_san/sql/group_by_handler.cc:49
          #7 0x55f4e0e0c68f in do_select /test/11.0_dbg_san/sql/sql_select.cc:22665
          #8 0x55f4e0e0c68f in JOIN::exec_inner() /test/11.0_dbg_san/sql/sql_select.cc:4900
          #9 0x55f4e0e0f916 in JOIN::exec() /test/11.0_dbg_san/sql/sql_select.cc:4677
          #10 0x55f4e0dfe0c1 in mysql_select(THD*, TABLE_LIST*, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) /test/11.0_dbg_san/sql/sql_select.cc:5158
          #11 0x55f4e0e0251c in handle_select(THD*, LEX*, select_result*, unsigned long long) /test/11.0_dbg_san/sql/sql_select.cc:616
          #12 0x55f4e0974a01 in execute_sqlcom_select /test/11.0_dbg_san/sql/sql_parse.cc:6279
          #13 0x55f4e09d5ef5 in mysql_execute_command(THD*, bool) /test/11.0_dbg_san/sql/sql_parse.cc:3949
          #14 0x55f4e0a05973 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.0_dbg_san/sql/sql_parse.cc:8014
          #15 0x55f4e0a15707 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.0_dbg_san/sql/sql_parse.cc:1894
          #16 0x55f4e0a23542 in do_command(THD*, bool) /test/11.0_dbg_san/sql/sql_parse.cc:1407
          #17 0x55f4e13f88b5 in do_handle_one_connection(CONNECT*, bool) /test/11.0_dbg_san/sql/sql_connect.cc:1416
          #18 0x55f4e13f9dd0 in handle_one_connection /test/11.0_dbg_san/sql/sql_connect.cc:1318
          #19 0x150d3ea94b42 in start_thread nptl/pthread_create.c:442
          #20 0x150d3eb269ff  (/lib/x86_64-linux-gnu/libc.so.6+0x1269ff)
      

      Setup:

      Compiled with GCC >=7.5.0 (I use GCC 11.3.0) and:
          -DWITH_ASAN=ON -DWITH_ASAN_SCOPE=ON -DWITH_UBSAN=ON -DWITH_RAPID=OFF -DWSREP_LIB_WITH_ASAN=ON
      Set before execution:
          export UBSAN_OPTIONS=print_stacktrace=1
      

      Bug confirmed present in:
      MariaDB: 10.4.30 (dbg), 10.4.30 (opt), 10.5.21 (dbg), 10.5.21 (opt), 10.6.14 (dbg), 10.6.14 (opt), 10.9.7 (dbg), 10.9.7 (opt), 10.10.5 (dbg), 10.10.5 (opt), 10.11.4 (dbg), 10.11.4 (opt), 11.0.2 (dbg), 11.0.2 (opt), 11.1.0 (dbg), 11.1.0 (opt)

      Attachments

        Issue Links

          Activity

            Roel Roel Van de Paar added a comment - - edited

            MTR testcase:

            IF (`SELECT NOT(COUNT(*)) FROM information_schema.system_variables WHERE variable_name='have_sanitizer' AND global_value LIKE "%UBSAN%"`)
            {
            --skip Test needs to be run with an UBSAN build
            }
            --source include/have_innodb.inc
            --let $SOCKET= `SELECT @@global.socket`
            INSTALL PLUGIN Spider SONAME 'ha_spider.so';
            CREATE USER spider@localhost IDENTIFIED BY 'pwd';
            GRANT ALL ON test.* TO spider@localhost;
            eval CREATE SERVER s FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$SOCKET",DATABASE 'test',USER 'spider',PASSWORD 'pwd');
            CREATE TABLE t (c BLOB) ENGINE=InnoDB;
            CREATE TABLE ts (c BLOB) ENGINE=Spider COMMENT='WRAPPER "mysql",srv "s",TABLE "t"';
            SELECT TRIM(BOTH ' ' FROM c) FROM ts ORDER BY c;
            

            Roel Roel Van de Paar added a comment - - edited MTR testcase: IF (` SELECT NOT ( COUNT (*)) FROM information_schema.system_variables WHERE variable_name= 'have_sanitizer' AND global_value LIKE "%UBSAN%" `) { --skip Test needs to be run with an UBSAN build } --source include/have_innodb.inc --let $SOCKET= `SELECT @@global.socket` INSTALL PLUGIN Spider SONAME 'ha_spider.so' ; CREATE USER spider@localhost IDENTIFIED BY 'pwd' ; GRANT ALL ON test.* TO spider@localhost; eval CREATE SERVER s FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$SOCKET" , DATABASE 'test' , USER 'spider' , PASSWORD 'pwd' ); CREATE TABLE t (c BLOB) ENGINE=InnoDB; CREATE TABLE ts (c BLOB) ENGINE=Spider COMMENT= 'WRAPPER "mysql",srv "s",TABLE "t"' ; SELECT TRIM(BOTH ' ' FROM c) FROM ts ORDER BY c;
            ycp Yuchen Pei added a comment - - edited

            I can get a sigsegv without a ubsan/asan build at 11.0 368dd22a816f3b437bccd0b9ff28b9de9b1abf0a. Judging from the query that caused it and the backtrace, I suspect it is related to MDEV-29447, if not caused by the same problem / duplicate.

            ycp Yuchen Pei added a comment - - edited I can get a sigsegv without a ubsan/asan build at 11.0 368dd22a816f3b437bccd0b9ff28b9de9b1abf0a. Judging from the query that caused it and the backtrace, I suspect it is related to MDEV-29447 , if not caused by the same problem / duplicate.
            Roel Roel Van de Paar added a comment - - edited

            It indeed looks related to MDEV-29447. Here is the UniqueID/stack summary from this bug (without UBSAN):

            SIGSEGV|spider_db_open_item_ident|spider_db_open_item_field|spider_db_print_item_type|spider_mbase_handler::append_order_by
            

            And here is the one from MDEV-29447:

            SIGSEGV|spider_db_open_item_field|spider_db_print_item_type|spider_db_mbase_util::open_item_func|spider_db_open_item_func
            

            Similar, though not identical (also note _ident vs _field in first frame).
            Sidenote: the crash/UniqueID produced by this SQL was not known yet (the bug was registered as an UBSAN issue only thus far).

            Roel Roel Van de Paar added a comment - - edited It indeed looks related to MDEV-29447 . Here is the UniqueID/stack summary from this bug (without UBSAN): SIGSEGV|spider_db_open_item_ident|spider_db_open_item_field|spider_db_print_item_type|spider_mbase_handler::append_order_by And here is the one from MDEV-29447 : SIGSEGV|spider_db_open_item_field|spider_db_print_item_type|spider_db_mbase_util::open_item_func|spider_db_open_item_func Similar, though not identical (also note _ident vs _field in first frame). Sidenote: the crash/UniqueID produced by this SQL was not known yet (the bug was registered as an UBSAN issue only thus far).
            Roel Roel Van de Paar added a comment - - edited

            Across versions and build types the SQL in this bug produces the following UniqueID's/stacks:

            SIGSEGV|spider_db_open_item_ident|spider_db_open_item_field|spider_db_print_item_type|spider_mbase_handler::append_order_by
            SIGSEGV|spider_db_open_item_ident|spider_mbase_handler::append_order_by|spider_mbase_handler::append_order_by|spider_group_by_handler::init_scan
            UBSAN|member access within null pointer of type 'struct SPIDER_FIELD_CHAIN'|storage/spider/spd_db_conn.cc
            UBSAN|member access within null pointer of type 'struct SPIDER_FIELD_CHAIN'|storage/spider/spd_db_conn.cc|spider_db_open_item_ident|spider_db_open_item_field|spider_db_print_item_type|spider_mbase_handler::append_order_by
            UBSAN|member access within null pointer of type 'struct SPIDER_FIELD_CHAIN'|storage/spider/spd_db_conn.cc|spider_db_open_item_ident|spider_db_open_item_field|spider_mbase_handler::append_order_by|spider_mbase_handler::append_order_by
            

            Roel Roel Van de Paar added a comment - - edited Across versions and build types the SQL in this bug produces the following UniqueID's/stacks: SIGSEGV|spider_db_open_item_ident|spider_db_open_item_field|spider_db_print_item_type|spider_mbase_handler::append_order_by SIGSEGV|spider_db_open_item_ident|spider_mbase_handler::append_order_by|spider_mbase_handler::append_order_by|spider_group_by_handler::init_scan UBSAN|member access within null pointer of type 'struct SPIDER_FIELD_CHAIN'|storage/spider/spd_db_conn.cc UBSAN|member access within null pointer of type 'struct SPIDER_FIELD_CHAIN'|storage/spider/spd_db_conn.cc|spider_db_open_item_ident|spider_db_open_item_field|spider_db_print_item_type|spider_mbase_handler::append_order_by UBSAN|member access within null pointer of type 'struct SPIDER_FIELD_CHAIN'|storage/spider/spd_db_conn.cc|spider_db_open_item_ident|spider_db_open_item_field|spider_mbase_handler::append_order_by|spider_mbase_handler::append_order_by
            ycp Yuchen Pei added a comment - - edited

            As I suspected, the patch for MDEV-29447 fixes this bug too. Here's a
            MDEV-29447 patch with an added test for this bug:
            https://github.com/MariaDB/server/commit/2c8f45a2d5e.

            So let's mark this as a duplicate to that ticket. I will add the
            testcase in the patches for that ticket for all versions so it is
            covered.

            mtr case:

            --echo #
            --echo # MDEV-31338 UBSAN: runtime error: member access within null pointer of type 'struct SPIDER_FIELD_CHAIN' and SIGSEGV in spider_db_open_item_ident on SELECT
            --echo #
            --source include/have_innodb.inc
             
            --disable_query_log
            --disable_result_log
            --source ../../t/test_init.inc
            --enable_result_log
            --enable_query_log
             
            eval CREATE SERVER srv FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
            CREATE TABLE t (c BLOB) ENGINE=InnoDB;
            CREATE TABLE ts (c BLOB) ENGINE=Spider COMMENT='WRAPPER "mysql",srv "srv",TABLE "t"';
            SELECT TRIM(BOTH ' ' FROM c) FROM ts ORDER BY c;
            drop table t, ts;
             
            --disable_query_log
            --disable_result_log
            --source ../../t/test_deinit.inc
            --enable_result_log
            --enable_query_log

            ycp Yuchen Pei added a comment - - edited As I suspected, the patch for MDEV-29447 fixes this bug too. Here's a MDEV-29447 patch with an added test for this bug: https://github.com/MariaDB/server/commit/2c8f45a2d5e . So let's mark this as a duplicate to that ticket. I will add the testcase in the patches for that ticket for all versions so it is covered. mtr case: --echo # --echo # MDEV-31338 UBSAN: runtime error: member access within null pointer of type 'struct SPIDER_FIELD_CHAIN' and SIGSEGV in spider_db_open_item_ident on SELECT --echo # --source include/have_innodb.inc   --disable_query_log --disable_result_log --source ../../t/test_init.inc --enable_result_log --enable_query_log   eval CREATE SERVER srv FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK" , DATABASE 'test' , user 'root' ); CREATE TABLE t (c BLOB) ENGINE=InnoDB; CREATE TABLE ts (c BLOB) ENGINE=Spider COMMENT= 'WRAPPER "mysql",srv "srv",TABLE "t"' ; SELECT TRIM(BOTH ' ' FROM c) FROM ts ORDER BY c; drop table t, ts;   --disable_query_log --disable_result_log --source ../../t/test_deinit.inc --enable_result_log --enable_query_log

            People

              ycp Yuchen Pei
              Roel Roel Van de Paar
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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