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

ASAN heap-use-after-free in String::c_ptr / partition_info::prune_partition_bitmaps

    XMLWordPrintable

Details

    Description

      --source include/have_partition.inc
      --source include/have_innodb.inc
       
      CREATE TABLE t1 (a INT DEFAULT 0) ENGINE=InnoDB WITH SYSTEM VERSIONING PARTITION BY system_time INTERVAL 1 WEEK (PARTITION p1 HISTORY, PARTITION pn CURRENT);
      CREATE PROCEDURE pr() SELECT * FROM t1;
      CALL pr();
      ALTER TABLE t1 ALTER COLUMN a DROP DEFAULT, ALGORITHM=INSTANT;
      CALL pr();
       
      # Cleanup
      DROP PROCEDURE pr;
      DROP TABLE t1;
      

      10.3 98b24da0

      ==29729==ERROR: AddressSanitizer: heap-use-after-free on address 0x61d00020e05a at pc 0x55f11fad040e bp 0x7f3b1f8ab550 sp 0x7f3b1f8ab548
      READ of size 1 at 0x61d00020e05a thread T27
          #0 0x55f11fad040d in String::c_ptr() /data/src/10.3/sql/sql_string.h:206
          #1 0x55f11ffd644a in partition_info::prune_partition_bitmaps(List<String>*) /data/src/10.3/sql/partition_info.cc:275
          #2 0x55f11ffd68d8 in partition_info::set_partition_bitmaps(List<String>*) /data/src/10.3/sql/partition_info.cc:312
          #3 0x55f121426e9f in ha_partition::change_partitions_to_open(List<String>*) /data/src/10.3/sql/ha_partition.cc:8466
          #4 0x55f11fb7b2d9 in set_partitions_as_used /data/src/10.3/sql/sql_base.cc:1505
          #5 0x55f11fb7d143 in open_table(THD*, TABLE_LIST*, Open_table_context*) /data/src/10.3/sql/sql_base.cc:1968
          #6 0x55f11fb84b56 in open_and_process_table /data/src/10.3/sql/sql_base.cc:3667
          #7 0x55f11fb87324 in open_tables(THD*, DDL_options_st const&, TABLE_LIST**, unsigned int*, unsigned int, Prelocking_strategy*) /data/src/10.3/sql/sql_base.cc:4162
          #8 0x55f11fb8bb5b in open_and_lock_tables(THD*, DDL_options_st const&, TABLE_LIST*, bool, unsigned int, Prelocking_strategy*) /data/src/10.3/sql/sql_base.cc:5041
          #9 0x55f11fb007f5 in open_and_lock_tables(THD*, TABLE_LIST*, bool, unsigned int) /data/src/10.3/sql/sql_base.h:505
          #10 0x55f11fcde774 in execute_sqlcom_select /data/src/10.3/sql/sql_parse.cc:6207
          #11 0x55f11fccf127 in mysql_execute_command(THD*) /data/src/10.3/sql/sql_parse.cc:3816
          #12 0x55f11faeae31 in sp_instr_stmt::exec_core(THD*, unsigned int*) /data/src/10.3/sql/sp_head.cc:3596
          #13 0x55f11fae9770 in sp_lex_keeper::reset_lex_and_exec_core(THD*, unsigned int*, bool, sp_instr*) /data/src/10.3/sql/sp_head.cc:3324
          #14 0x55f11faea619 in sp_instr_stmt::execute(THD*, unsigned int*) /data/src/10.3/sql/sp_head.cc:3502
          #15 0x55f11fadd9f4 in sp_head::execute(THD*, bool) /data/src/10.3/sql/sp_head.cc:1356
          #16 0x55f11fae2bed in sp_head::execute_procedure(THD*, List<Item>*) /data/src/10.3/sql/sp_head.cc:2296
          #17 0x55f11fcc9d65 in do_execute_sp /data/src/10.3/sql/sql_parse.cc:2992
          #18 0x55f11fccb626 in Sql_cmd_call::execute(THD*) /data/src/10.3/sql/sql_parse.cc:3232
          #19 0x55f11fcdcfaa in mysql_execute_command(THD*) /data/src/10.3/sql/sql_parse.cc:6023
          #20 0x55f11fce7ccf in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.3/sql/sql_parse.cc:7829
          #21 0x55f11fcc3d25 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.3/sql/sql_parse.cc:1856
          #22 0x55f11fcc0cdf in do_command(THD*) /data/src/10.3/sql/sql_parse.cc:1401
          #23 0x55f12002739e in do_handle_one_connection(CONNECT*) /data/src/10.3/sql/sql_connect.cc:1403
          #24 0x55f120026d65 in handle_one_connection /data/src/10.3/sql/sql_connect.cc:1308
          #25 0x55f1213b698f in pfs_spawn_thread /data/src/10.3/storage/perfschema/pfs.cc:1862
          #26 0x7f3b36fe74a3 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x74a3)
          #27 0x7f3b3552fd0e in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xe8d0e)
       
      0x61d00020e05a is located 1498 bytes inside of 2084-byte region [0x61d00020da80,0x61d00020e2a4)
      freed by thread T27 here:
          #0 0x7f3b372bea10 in free (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1a10)
          #1 0x55f1214df9ea in free_memory /data/src/10.3/mysys/safemalloc.c:279
          #2 0x55f1214df08c in sf_free /data/src/10.3/mysys/safemalloc.c:197
          #3 0x55f1214b1640 in my_free /data/src/10.3/mysys/my_malloc.c:223
          #4 0x55f121492928 in free_root /data/src/10.3/mysys/my_alloc.c:429
          #5 0x55f11ff71ad9 in closefrm(TABLE*) /data/src/10.3/sql/table.cc:3629
          #6 0x55f1201cf7ef in intern_close_table /data/src/10.3/sql/table_cache.cc:222
          #7 0x55f1201cfa56 in tc_remove_table /data/src/10.3/sql/table_cache.cc:260
          #8 0x55f1201d0d1b in tc_release_table(TABLE*) /data/src/10.3/sql/table_cache.cc:474
          #9 0x55f11fb78d68 in close_thread_table(THD*, TABLE**) /data/src/10.3/sql/sql_base.cc:920
          #10 0x55f11fb77879 in close_all_tables_for_name(THD*, TABLE_SHARE*, ha_extra_function, TABLE*) /data/src/10.3/sql/sql_base.cc:688
          #11 0x55f11fee2834 in mysql_inplace_alter_table /data/src/10.3/sql/sql_table.cc:7623
          #12 0x55f11feeffd9 in mysql_alter_table(THD*, st_mysql_const_lex_string const*, st_mysql_const_lex_string const*, HA_CREATE_INFO*, TABLE_LIST*, Alter_info*, unsigned int, st_order*, bool) /data/src/10.3/sql/sql_table.cc:9827
          #13 0x55f120036281 in Sql_cmd_alter_table::execute(THD*) /data/src/10.3/sql/sql_alter.cc:500
          #14 0x55f11fcdcfaa in mysql_execute_command(THD*) /data/src/10.3/sql/sql_parse.cc:6023
          #15 0x55f11fce7ccf in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.3/sql/sql_parse.cc:7829
          #16 0x55f11fcc3d25 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.3/sql/sql_parse.cc:1856
          #17 0x55f11fcc0cdf in do_command(THD*) /data/src/10.3/sql/sql_parse.cc:1401
          #18 0x55f12002739e in do_handle_one_connection(CONNECT*) /data/src/10.3/sql/sql_connect.cc:1403
          #19 0x55f120026d65 in handle_one_connection /data/src/10.3/sql/sql_connect.cc:1308
          #20 0x55f1213b698f in pfs_spawn_thread /data/src/10.3/storage/perfschema/pfs.cc:1862
          #21 0x7f3b36fe74a3 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x74a3)
       
      previously allocated by thread T27 here:
          #0 0x7f3b372bed28 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d28)
          #1 0x55f1214dea8c in sf_malloc /data/src/10.3/mysys/safemalloc.c:118
          #2 0x55f1214b0d87 in my_malloc /data/src/10.3/mysys/my_malloc.c:101
          #3 0x55f121491978 in alloc_root /data/src/10.3/mysys/my_alloc.c:250
          #4 0x55f11fa60435 in Query_arena::alloc(unsigned long) /data/src/10.3/sql/sql_class.h:1018
          #5 0x55f11fbd9ea8 in thd_alloc /data/src/10.3/sql/sql_class.cc:1083
          #6 0x55f11facfe8d in Sql_alloc::operator new(unsigned long) /data/src/10.3/sql/sql_alloc.h:30
          #7 0x55f1207cfeb8 in mysql_unpack_partition(THD*, char*, unsigned int, TABLE*, bool, handlerton*, bool*) /data/src/10.3/sql/sql_partition.cc:4481
          #8 0x55f11ff6fd02 in open_table_from_share(THD*, TABLE_SHARE*, st_mysql_const_lex_string const*, unsigned int, unsigned int, unsigned int, TABLE*, bool, List<String>*) /data/src/10.3/sql/table.cc:3400
          #9 0x55f11fb7d239 in open_table(THD*, TABLE_LIST*, Open_table_context*) /data/src/10.3/sql/sql_base.cc:1979
          #10 0x55f11fb84b56 in open_and_process_table /data/src/10.3/sql/sql_base.cc:3667
          #11 0x55f11fb87324 in open_tables(THD*, DDL_options_st const&, TABLE_LIST**, unsigned int*, unsigned int, Prelocking_strategy*) /data/src/10.3/sql/sql_base.cc:4162
          #12 0x55f11fb8bb5b in open_and_lock_tables(THD*, DDL_options_st const&, TABLE_LIST*, bool, unsigned int, Prelocking_strategy*) /data/src/10.3/sql/sql_base.cc:5041
          #13 0x55f11fb007f5 in open_and_lock_tables(THD*, TABLE_LIST*, bool, unsigned int) /data/src/10.3/sql/sql_base.h:505
          #14 0x55f11fcde774 in execute_sqlcom_select /data/src/10.3/sql/sql_parse.cc:6207
          #15 0x55f11fccf127 in mysql_execute_command(THD*) /data/src/10.3/sql/sql_parse.cc:3816
          #16 0x55f11faeae31 in sp_instr_stmt::exec_core(THD*, unsigned int*) /data/src/10.3/sql/sp_head.cc:3596
          #17 0x55f11fae9770 in sp_lex_keeper::reset_lex_and_exec_core(THD*, unsigned int*, bool, sp_instr*) /data/src/10.3/sql/sp_head.cc:3324
          #18 0x55f11faea619 in sp_instr_stmt::execute(THD*, unsigned int*) /data/src/10.3/sql/sp_head.cc:3502
          #19 0x55f11fadd9f4 in sp_head::execute(THD*, bool) /data/src/10.3/sql/sp_head.cc:1356
          #20 0x55f11fae2bed in sp_head::execute_procedure(THD*, List<Item>*) /data/src/10.3/sql/sp_head.cc:2296
          #21 0x55f11fcc9d65 in do_execute_sp /data/src/10.3/sql/sql_parse.cc:2992
          #22 0x55f11fccb626 in Sql_cmd_call::execute(THD*) /data/src/10.3/sql/sql_parse.cc:3232
          #23 0x55f11fcdcfaa in mysql_execute_command(THD*) /data/src/10.3/sql/sql_parse.cc:6023
          #24 0x55f11fce7ccf in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.3/sql/sql_parse.cc:7829
          #25 0x55f11fcc3d25 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.3/sql/sql_parse.cc:1856
          #26 0x55f11fcc0cdf in do_command(THD*) /data/src/10.3/sql/sql_parse.cc:1401
          #27 0x55f12002739e in do_handle_one_connection(CONNECT*) /data/src/10.3/sql/sql_connect.cc:1403
          #28 0x55f120026d65 in handle_one_connection /data/src/10.3/sql/sql_connect.cc:1308
          #29 0x55f1213b698f in pfs_spawn_thread /data/src/10.3/storage/perfschema/pfs.cc:1862
       
      Thread T27 created by T0 here:
          #0 0x7f3b3722df59 in __interceptor_pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x30f59)
          #1 0x55f1213b6dcb in spawn_thread_v1 /data/src/10.3/storage/perfschema/pfs.cc:1912
          #2 0x55f11fa3c930 in inline_mysql_thread_create /data/src/10.3/include/mysql/psi/mysql_thread.h:1268
          #3 0x55f11fa51849 in create_thread_to_handle_connection(CONNECT*) /data/src/10.3/sql/mysqld.cc:6608
          #4 0x55f11fa51f2c in create_new_thread /data/src/10.3/sql/mysqld.cc:6678
          #5 0x55f11fa52f44 in handle_connections_sockets() /data/src/10.3/sql/mysqld.cc:6953
          #6 0x55f11fa50d19 in mysqld_main(int, char**) /data/src/10.3/sql/mysqld.cc:6230
          #7 0x55f11fa3b04f in main /data/src/10.3/sql/main.cc:25
          #8 0x7f3b354672e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
       
      SUMMARY: AddressSanitizer: heap-use-after-free /data/src/10.3/sql/sql_string.h:206 in String::c_ptr()
      Shadow bytes around the buggy address:
        0x0c3a80039bb0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c3a80039bc0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c3a80039bd0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c3a80039be0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c3a80039bf0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      =>0x0c3a80039c00: fd fd fd fd fd fd fd fd fd fd fd[fd]fd fd fd fd
        0x0c3a80039c10: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c3a80039c20: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c3a80039c30: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c3a80039c40: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c3a80039c50: fd fd fd fd fd fa fa fa fa fa fa fa fa fa fa fa
      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
        Heap right redzone:      fb
        Freed heap region:       fd
        Stack left redzone:      f1
        Stack mid redzone:       f2
        Stack right redzone:     f3
        Stack partial redzone:   f4
        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
      ==29729==ABORTING
      

      The problem was apparently introduced by this commit:

      commit cdbac54df0bd857a053decd66b6067abf15a6801 43882e764d6867c6855b1ff057758a3f08b25c55
      Commit:     Aleksey Midenkov
      CommitDate: Sun Aug 11 12:32:08 2019 +0300
       
          MDEV-17613 MIN/MAX Optimization (Select tables optimized away) does not work
          
          Prune to now-partition when there is no FOR SYSTEM_TIME clause.
      

      Happens on both debug- and non-debug builds with ASAN. Non-ASAN builds don't crash, but produce a weird error:

      CURRENT_TEST: bug.3554
      mysqltest: At line 8: query 'CALL pr()' failed: 1735: Unknown partition '' in table 't1'
      

      Attachments

        Issue Links

          Activity

            People

              midenok Aleksey Midenkov
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              3 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.