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

ASAN heap-use-after-free in my_hash_sort_bin or ER_KEY_NOT_FOUND upon INSERT into table with long unique blob

    XMLWordPrintable

Details

    Description

      with InnoDB

      --source include/have_innodb.inc
       
      CREATE TABLE t1 (a INT, b BLOB) ENGINE=InnoDB;
      INSERT INTO t1 VALUES (1,'foo'),(2,'bar');
      CREATE TABLE t2 (c BIT, d BLOB, UNIQUE(d)) ENGINE=InnoDB;
       
      INSERT INTO t2 SELECT * FROM t1;
       
      # Cleanup
      DROP TABLE t1, t2;
      

      10.4 ASAN 98316320

      ==21080==ERROR: AddressSanitizer: heap-use-after-free on address 0x62900029e290 at pc 0x5648df7ae2b0 bp 0x7f96e3ed2c30 sp 0x7f96e3ed2c28
      READ of size 1 at 0x62900029e290 thread T27
          #0 0x5648df7ae2af in my_hash_sort_bin /data/src/10.4/strings/ctype-bin.c:274
          #1 0x5648de7028f9 in calc_hash_for_unique /data/src/10.4/sql/item_func.cc:1746
          #2 0x5648de702c4e in Item_func_hash::val_int() /data/src/10.4/sql/item_func.cc:1763
          #3 0x5648de6338f8 in Item::save_int_in_field(Field*, bool) /data/src/10.4/sql/item.cc:6540
          #4 0x5648de315c9b in Type_handler_int_result::Item_save_in_field(Item*, Field*, bool) const /data/src/10.4/sql/sql_type.cc:3672
          #5 0x5648de633ad4 in Item::save_in_field(Field*, bool) /data/src/10.4/sql/item.cc:6550
          #6 0x5648de13a96e in TABLE::update_virtual_fields(handler*, enum_vcol_update_mode) /data/src/10.4/sql/table.cc:8285
          #7 0x5648ddd120d0 in fill_record(THD*, TABLE*, Field**, List<Item>&, bool, bool) /data/src/10.4/sql/sql_base.cc:8770
          #8 0x5648ddd12331 in fill_record_n_invoke_before_triggers(THD*, TABLE*, Field**, List<Item>&, bool, trg_event_type) /data/src/10.4/sql/sql_base.cc:8811
          #9 0x5648dddca955 in select_insert::store_values(List<Item>&) /data/src/10.4/sql/sql_insert.cc:4014
          #10 0x5648dddc9c92 in select_insert::send_data(List<Item>&) /data/src/10.4/sql/sql_insert.cc:3945
          #11 0x5648ddf8728b in end_send /data/src/10.4/sql/sql_select.cc:21444
          #12 0x5648ddf7fc26 in evaluate_join_record /data/src/10.4/sql/sql_select.cc:20475
          #13 0x5648ddf7eea6 in sub_select(JOIN*, st_join_table*, bool) /data/src/10.4/sql/sql_select.cc:20294
          #14 0x5648ddf7cc2c in do_select /data/src/10.4/sql/sql_select.cc:19793
          #15 0x5648ddf16033 in JOIN::exec_inner() /data/src/10.4/sql/sql_select.cc:4452
          #16 0x5648ddf1393f in JOIN::exec() /data/src/10.4/sql/sql_select.cc:4234
          #17 0x5648ddf173f1 in mysql_select(THD*, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) /data/src/10.4/sql/sql_select.cc:4666
          #18 0x5648ddeecc38 in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.4/sql/sql_select.cc:420
          #19 0x5648dde618c3 in mysql_execute_command(THD*) /data/src/10.4/sql/sql_parse.cc:4643
          #20 0x5648dde777dd in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.4/sql/sql_parse.cc:7901
          #21 0x5648dde50a90 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.4/sql/sql_parse.cc:1842
          #22 0x5648dde4d990 in do_command(THD*) /data/src/10.4/sql/sql_parse.cc:1360
          #23 0x5648de1d46a0 in do_handle_one_connection(CONNECT*) /data/src/10.4/sql/sql_connect.cc:1412
          #24 0x5648de1d4054 in handle_one_connection /data/src/10.4/sql/sql_connect.cc:1316
          #25 0x5648df63a84d in pfs_spawn_thread /data/src/10.4/storage/perfschema/pfs.cc:1862
          #26 0x7f96fbb304a3 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x74a3)
          #27 0x7f96f9c64d0e in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xe8d0e)
       
      0x62900029e290 is located 144 bytes inside of 16520-byte region [0x62900029e200,0x6290002a2288)
      freed by thread T27 here:
          #0 0x7f96fbe07a10 in free (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1a10)
          #1 0x5648decad27d in mem_heap_block_free(mem_block_info_t*, mem_block_info_t*) /data/src/10.4/storage/innobase/mem/mem0mem.cc:426
          #2 0x5648dedda873 in mem_heap_free /data/src/10.4/storage/innobase/include/mem0mem.ic:437
          #3 0x5648dede2018 in row_mysql_prebuilt_free_blob_heap(row_prebuilt_t*) /data/src/10.4/storage/innobase/row/row0mysql.cc:162
          #4 0x5648dee63f73 in row_sel_store_mysql_rec /data/src/10.4/storage/innobase/row/row0sel.cc:3053
          #5 0x5648dee7079c in row_search_mvcc(unsigned char*, page_cur_mode_t, row_prebuilt_t*, unsigned long, unsigned long) /data/src/10.4/storage/innobase/row/row0sel.cc:5488
          #6 0x5648deb13bff in ha_innobase::general_fetch(unsigned char*, unsigned int, unsigned int) /data/src/10.4/storage/innobase/handler/ha_innodb.cc:9561
          #7 0x5648deb14aa9 in ha_innobase::rnd_next(unsigned char*) /data/src/10.4/storage/innobase/handler/ha_innodb.cc:9770
          #8 0x5648de5cff78 in handler::ha_rnd_next(unsigned char*) /data/src/10.4/sql/handler.cc:2827
          #9 0x5648de99b233 in rr_sequential(READ_RECORD*) /data/src/10.4/sql/records.cc:477
          #10 0x5648ddcd3875 in READ_RECORD::read_record() /data/src/10.4/sql/records.h:69
          #11 0x5648ddf7eac6 in sub_select(JOIN*, st_join_table*, bool) /data/src/10.4/sql/sql_select.cc:20274
          #12 0x5648ddf7cc2c in do_select /data/src/10.4/sql/sql_select.cc:19793
          #13 0x5648ddf16033 in JOIN::exec_inner() /data/src/10.4/sql/sql_select.cc:4452
          #14 0x5648ddf1393f in JOIN::exec() /data/src/10.4/sql/sql_select.cc:4234
          #15 0x5648ddf173f1 in mysql_select(THD*, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) /data/src/10.4/sql/sql_select.cc:4666
          #16 0x5648ddeecc38 in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.4/sql/sql_select.cc:420
          #17 0x5648dde618c3 in mysql_execute_command(THD*) /data/src/10.4/sql/sql_parse.cc:4643
          #18 0x5648dde777dd in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.4/sql/sql_parse.cc:7901
          #19 0x5648dde50a90 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.4/sql/sql_parse.cc:1842
          #20 0x5648dde4d990 in do_command(THD*) /data/src/10.4/sql/sql_parse.cc:1360
          #21 0x5648de1d46a0 in do_handle_one_connection(CONNECT*) /data/src/10.4/sql/sql_connect.cc:1412
          #22 0x5648de1d4054 in handle_one_connection /data/src/10.4/sql/sql_connect.cc:1316
          #23 0x5648df63a84d in pfs_spawn_thread /data/src/10.4/storage/perfschema/pfs.cc:1862
          #24 0x7f96fbb304a3 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x74a3)
       
      previously allocated by thread T27 here:
          #0 0x7f96fbe07d28 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d28)
          #1 0x5648decac7cd in mem_heap_create_block_func(mem_block_info_t*, unsigned long, char const*, unsigned int, unsigned long) /data/src/10.4/storage/innobase/mem/mem0mem.cc:280
          #2 0x5648dee4e9ce in mem_heap_create_func /data/src/10.4/storage/innobase/include/mem0mem.ic:393
          #3 0x5648dee6391f in row_sel_store_mysql_field /data/src/10.4/storage/innobase/row/row0sel.cc:2994
          #4 0x5648dee64bfb in row_sel_store_mysql_rec /data/src/10.4/storage/innobase/row/row0sel.cc:3141
          #5 0x5648dee7079c in row_search_mvcc(unsigned char*, page_cur_mode_t, row_prebuilt_t*, unsigned long, unsigned long) /data/src/10.4/storage/innobase/row/row0sel.cc:5488
          #6 0x5648deb11629 in ha_innobase::index_read(unsigned char*, unsigned char const*, unsigned int, ha_rkey_function) /data/src/10.4/storage/innobase/handler/ha_innodb.cc:9296
          #7 0x5648deb14583 in ha_innobase::index_first(unsigned char*) /data/src/10.4/storage/innobase/handler/ha_innodb.cc:9669
          #8 0x5648deb14a23 in ha_innobase::rnd_next(unsigned char*) /data/src/10.4/storage/innobase/handler/ha_innodb.cc:9762
          #9 0x5648de5cff78 in handler::ha_rnd_next(unsigned char*) /data/src/10.4/sql/handler.cc:2827
          #10 0x5648de99b233 in rr_sequential(READ_RECORD*) /data/src/10.4/sql/records.cc:477
          #11 0x5648ddcd3875 in READ_RECORD::read_record() /data/src/10.4/sql/records.h:69
          #12 0x5648ddf84e0d in join_init_read_record(st_join_table*) /data/src/10.4/sql/sql_select.cc:21197
          #13 0x5648ddf7e68a in sub_select(JOIN*, st_join_table*, bool) /data/src/10.4/sql/sql_select.cc:20252
          #14 0x5648ddf7cc2c in do_select /data/src/10.4/sql/sql_select.cc:19793
          #15 0x5648ddf16033 in JOIN::exec_inner() /data/src/10.4/sql/sql_select.cc:4452
          #16 0x5648ddf1393f in JOIN::exec() /data/src/10.4/sql/sql_select.cc:4234
          #17 0x5648ddf173f1 in mysql_select(THD*, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*) /data/src/10.4/sql/sql_select.cc:4666
          #18 0x5648ddeecc38 in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.4/sql/sql_select.cc:420
          #19 0x5648dde618c3 in mysql_execute_command(THD*) /data/src/10.4/sql/sql_parse.cc:4643
          #20 0x5648dde777dd in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.4/sql/sql_parse.cc:7901
          #21 0x5648dde50a90 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.4/sql/sql_parse.cc:1842
          #22 0x5648dde4d990 in do_command(THD*) /data/src/10.4/sql/sql_parse.cc:1360
          #23 0x5648de1d46a0 in do_handle_one_connection(CONNECT*) /data/src/10.4/sql/sql_connect.cc:1412
          #24 0x5648de1d4054 in handle_one_connection /data/src/10.4/sql/sql_connect.cc:1316
          #25 0x5648df63a84d in pfs_spawn_thread /data/src/10.4/storage/perfschema/pfs.cc:1862
          #26 0x7f96fbb304a3 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x74a3)
       
      Thread T27 created by T0 here:
          #0 0x7f96fbd76f59 in __interceptor_pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x30f59)
          #1 0x5648df63ac3a in spawn_thread_v1 /data/src/10.4/storage/perfschema/pfs.cc:1912
          #2 0x5648ddba6ae8 in inline_mysql_thread_create /data/src/10.4/include/mysql/psi/mysql_thread.h:1268
          #3 0x5648ddbbb08c in create_thread_to_handle_connection(CONNECT*) /data/src/10.4/sql/mysqld.cc:6234
          #4 0x5648ddbbb76f in create_new_thread(CONNECT*) /data/src/10.4/sql/mysqld.cc:6304
          #5 0x5648ddbbbafa in handle_accepted_socket(st_mysql_socket, st_mysql_socket) /data/src/10.4/sql/mysqld.cc:6402
          #6 0x5648ddbbc74c in handle_connections_sockets() /data/src/10.4/sql/mysqld.cc:6560
          #7 0x5648ddbba90d in mysqld_main(int, char**) /data/src/10.4/sql/mysqld.cc:5892
          #8 0x5648ddba49cf in main /data/src/10.4/sql/main.cc:25
          #9 0x7f96f9b9c2e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
       
      SUMMARY: AddressSanitizer: heap-use-after-free /data/src/10.4/strings/ctype-bin.c:274 in my_hash_sort_bin
      Shadow bytes around the buggy address:
        0x0c528004bc00: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c528004bc10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c528004bc20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c528004bc30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c528004bc40: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      =>0x0c528004bc50: fd fd[fd]fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c528004bc60: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c528004bc70: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c528004bc80: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c528004bc90: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c528004bca0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      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
      ==21080==ABORTING
      

      with MyISAM

      CREATE TABLE t1 (a INT, b BLOB) ENGINE=MyISAM;
      INSERT INTO t1 VALUES (1,'foo'),(2,'bar');
      CREATE TABLE t2 (c BIT, d BLOB, UNIQUE(d)) ENGINE=MyISAM;
       
      INSERT INTO t2 SELECT * FROM t1;
       
      # Cleanup
      DROP TABLE t1, t2;
      

      mysqltest: At line 5: query 'INSERT INTO t2 SELECT * FROM t1' failed: 1032: Can't find record in 't2'
      

      Reproducible with 10.4, 10.5.
      MyISAM variation is reproducible on non-debug non-ASAN builds as well.
      InnoDB variation doesn't crash on a non-ASAN build.

      Attachments

        Activity

          People

            monty Michael Widenius
            elenst Elena Stepanova
            Votes:
            0 Vote for this issue
            Watchers:
            7 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.