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

Server crash or ASAN heap-use-after-free in my_strtod_int / Value_source::Converter_strntod::Converter_strntod

    XMLWordPrintable

    Details

      Description

      10.2 ASAN b8aef8722

      ==11131==ERROR: AddressSanitizer: heap-use-after-free on address 0x60c000027a70 at pc 0x558f1bd8c6de bp 0x7f054225f0e0 sp 0x7f054225f0d8
      READ of size 1 at 0x60c000027a70 thread T5
          #0 0x558f1bd8c6dd in my_strtod_int /data/src/10.2/strings/dtoa.c:1378
          #1 0x558f1bd8904f in my_strtod /data/src/10.2/strings/dtoa.c:469
          #2 0x558f1bd34220 in my_strntod_8bit /data/src/10.2/strings/ctype-simple.c:788
          #3 0x558f1a4ac53e in Value_source::Converter_strntod::Converter_strntod(charset_info_st const*, char const*, unsigned long) /data/src/10.2/sql/field.h:159
          #4 0x558f1a4ac889 in Value_source::Converter_strntod_with_warn::Converter_strntod_with_warn(THD*, Value_source::Warn_filter, charset_info_st const*, char const*, unsigned long) /data/src/10.2/sql/field.h:229
          #5 0x558f1ac0c1e0 in Field_blob::val_real() /data/src/10.2/sql/field.cc:8101
          #6 0x558f1ac93fc6 in Item_field::val_real() /data/src/10.2/sql/item.cc:2800
          #7 0x558f1acef131 in Arg_comparator::compare_real() /data/src/10.2/sql/item_cmpfunc.cc:849
          #8 0x558f1ad29dba in Arg_comparator::compare() /data/src/10.2/sql/item_cmpfunc.h:87
          #9 0x558f1acfa13f in Item_func_ne::val_int() /data/src/10.2/sql/item_cmpfunc.cc:1805
          #10 0x558f1ac7e932 in Item::val_bool() /data/src/10.2/sql/item.cc:112
          #11 0x558f1ad188cc in Item_cond_and::val_int() /data/src/10.2/sql/item_cmpfunc.cc:5048
          #12 0x558f1a8bef08 in SQL_SELECT::skip_record(THD*) /data/src/10.2/sql/opt_range.h:1632
          #13 0x558f1ac3fc31 in find_all_keys /data/src/10.2/sql/filesort.cc:835
          #14 0x558f1ac3c045 in filesort(THD*, TABLE*, Filesort*, Filesort_tracker*, JOIN*, unsigned long long) /data/src/10.2/sql/filesort.cc:279
          #15 0x558f1a781ba8 in create_sort_index(THD*, JOIN*, st_join_table*, Filesort*) /data/src/10.2/sql/sql_select.cc:21913
          #16 0x558f1a772d78 in st_join_table::sort_table() /data/src/10.2/sql/sql_select.cc:19729
          #17 0x558f1a772396 in join_init_read_record(st_join_table*) /data/src/10.2/sql/sql_select.cc:19670
          #18 0x558f1a76bac7 in sub_select(JOIN*, st_join_table*, bool) /data/src/10.2/sql/sql_select.cc:18761
          #19 0x558f1a769fd2 in do_select /data/src/10.2/sql/sql_select.cc:18308
          #20 0x558f1a70a208 in JOIN::exec_inner() /data/src/10.2/sql/sql_select.cc:3623
          #21 0x558f1a707e9d in JOIN::exec() /data/src/10.2/sql/sql_select.cc:3418
          #22 0x558f1a70b285 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.2/sql/sql_select.cc:3818
          #23 0x558f1a6ea260 in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.2/sql/sql_select.cc:376
          #24 0x558f1a66ced2 in execute_sqlcom_select /data/src/10.2/sql/sql_parse.cc:6481
          #25 0x558f1a659bbb in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:3487
          #26 0x558f1a675bbd in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:8015
          #27 0x558f1a6505aa in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1826
          #28 0x558f1a64d63f in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1379
          #29 0x558f1a994034 in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1335
          #30 0x558f1a993a49 in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #31 0x558f1b3b10db in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1862
          #32 0x7f054e6d6493 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x7493)
          #33 0x7f054cabc93e in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xe893e)
       
      0x60c000027a70 is located 112 bytes inside of 124-byte region [0x60c000027a00,0x60c000027a7c)
      freed by thread T5 here:
          #0 0x7f054e940527 in __interceptor_free (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x54527)
          #1 0x558f1bcd2043 in free_memory /data/src/10.2/mysys/safemalloc.c:279
          #2 0x558f1bcd1649 in sf_free /data/src/10.2/mysys/safemalloc.c:197
          #3 0x558f1bca08d8 in my_free /data/src/10.2/mysys/my_malloc.c:217
          #4 0x558f1a46c7f7 in String::free() /data/src/10.2/sql/sql_string.h:351
          #5 0x558f1a4abebe in String::set(char const*, unsigned int, charset_info_st const*) /data/src/10.2/sql/sql_string.h:274
          #6 0x558f1ac0ccdb in Field_blob::val_str(String*, String*) /data/src/10.2/sql/field.cc:8128
          #7 0x558f1a48fc1f in Field::val_str(String*) /data/src/10.2/sql/field.h:866
          #8 0x558f1ac2ba7c in Field_blob::store_field(Field*) (/data/bld/10.2-asan/bin/mysqld+0x1254a7c)
          #9 0x558f1ac39b2d in field_conv_incompatible /data/src/10.2/sql/field_conv.cc:831
          #10 0x558f1ac39bca in field_conv(Field*, Field*) /data/src/10.2/sql/field_conv.cc:844
          #11 0x558f1acad0c8 in save_field_in_field /data/src/10.2/sql/item.cc:6257
          #12 0x558f1acad5c4 in Item_field::save_in_field(Field*, bool) /data/src/10.2/sql/item.cc:6303
          #13 0x558f1a907bac in TABLE::update_virtual_fields(handler*, enum_vcol_update_mode) /data/src/10.2/sql/table.cc:7640
          #14 0x558f1ac5c73c in handler::ha_index_read_map(unsigned char*, unsigned char const*, unsigned long, ha_rkey_function) /data/src/10.2/sql/handler.cc:2684
          #15 0x558f1ac6d868 in handler::read_range_first(st_key_range const*, st_key_range const*, bool, bool) /data/src/10.2/sql/handler.cc:5378
          #16 0x558f1bc20291 in ha_partition::handle_ordered_index_scan(unsigned char*, bool) /data/src/10.2/sql/ha_partition.cc:6181
          #17 0x558f1bc1c24c in ha_partition::common_index_read(unsigned char*, bool) /data/src/10.2/sql/ha_partition.cc:5527
          #18 0x558f1bc1da6d in ha_partition::read_range_first(st_key_range const*, st_key_range const*, bool, bool) /data/src/10.2/sql/ha_partition.cc:5810
          #19 0x558f1aa30dd8 in handler::multi_range_read_next(void**) /data/src/10.2/sql/multi_range_read.cc:303
          #20 0x558f1afab616 in QUICK_RANGE_SELECT::get_next() /data/src/10.2/sql/opt_range.cc:11445
          #21 0x558f1ac3f6e6 in find_all_keys /data/src/10.2/sql/filesort.cc:781
          #22 0x558f1ac3c045 in filesort(THD*, TABLE*, Filesort*, Filesort_tracker*, JOIN*, unsigned long long) /data/src/10.2/sql/filesort.cc:279
          #23 0x558f1a781ba8 in create_sort_index(THD*, JOIN*, st_join_table*, Filesort*) /data/src/10.2/sql/sql_select.cc:21913
          #24 0x558f1a772d78 in st_join_table::sort_table() /data/src/10.2/sql/sql_select.cc:19729
          #25 0x558f1a772396 in join_init_read_record(st_join_table*) /data/src/10.2/sql/sql_select.cc:19670
          #26 0x558f1a76bac7 in sub_select(JOIN*, st_join_table*, bool) /data/src/10.2/sql/sql_select.cc:18761
          #27 0x558f1a769fd2 in do_select /data/src/10.2/sql/sql_select.cc:18308
          #28 0x558f1a70a208 in JOIN::exec_inner() /data/src/10.2/sql/sql_select.cc:3623
          #29 0x558f1a707e9d in JOIN::exec() /data/src/10.2/sql/sql_select.cc:3418
       
      previously allocated by thread T5 here:
          #0 0x7f054e94073f in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x5473f)
          #1 0x558f1bcd0db9 in sf_malloc /data/src/10.2/mysys/safemalloc.c:118
          #2 0x558f1bca0010 in my_malloc /data/src/10.2/mysys/my_malloc.c:101
          #3 0x558f1a83268b in String::realloc_raw(unsigned long) /data/src/10.2/sql/sql_string.cc:102
          #4 0x558f1a46c91e in String::realloc(unsigned long) /data/src/10.2/sql/sql_string.h:367
          #5 0x558f1a832f6b in String::copy() /data/src/10.2/sql/sql_string.cc:158
          #6 0x558f1ac2bb85 in Field_blob::store_field(Field*) (/data/bld/10.2-asan/bin/mysqld+0x1254b85)
          #7 0x558f1ac39b2d in field_conv_incompatible /data/src/10.2/sql/field_conv.cc:831
          #8 0x558f1ac39bca in field_conv(Field*, Field*) /data/src/10.2/sql/field_conv.cc:844
          #9 0x558f1acad0c8 in save_field_in_field /data/src/10.2/sql/item.cc:6257
          #10 0x558f1acad5c4 in Item_field::save_in_field(Field*, bool) /data/src/10.2/sql/item.cc:6303
          #11 0x558f1a907bac in TABLE::update_virtual_fields(handler*, enum_vcol_update_mode) /data/src/10.2/sql/table.cc:7640
          #12 0x558f1ac5c73c in handler::ha_index_read_map(unsigned char*, unsigned char const*, unsigned long, ha_rkey_function) /data/src/10.2/sql/handler.cc:2684
          #13 0x558f1ac6d868 in handler::read_range_first(st_key_range const*, st_key_range const*, bool, bool) /data/src/10.2/sql/handler.cc:5378
          #14 0x558f1bc20291 in ha_partition::handle_ordered_index_scan(unsigned char*, bool) /data/src/10.2/sql/ha_partition.cc:6181
          #15 0x558f1bc1c24c in ha_partition::common_index_read(unsigned char*, bool) /data/src/10.2/sql/ha_partition.cc:5527
          #16 0x558f1bc1da6d in ha_partition::read_range_first(st_key_range const*, st_key_range const*, bool, bool) /data/src/10.2/sql/ha_partition.cc:5810
          #17 0x558f1aa30dd8 in handler::multi_range_read_next(void**) /data/src/10.2/sql/multi_range_read.cc:303
          #18 0x558f1afab616 in QUICK_RANGE_SELECT::get_next() /data/src/10.2/sql/opt_range.cc:11445
          #19 0x558f1ac3f6e6 in find_all_keys /data/src/10.2/sql/filesort.cc:781
          #20 0x558f1ac3c045 in filesort(THD*, TABLE*, Filesort*, Filesort_tracker*, JOIN*, unsigned long long) /data/src/10.2/sql/filesort.cc:279
          #21 0x558f1a781ba8 in create_sort_index(THD*, JOIN*, st_join_table*, Filesort*) /data/src/10.2/sql/sql_select.cc:21913
          #22 0x558f1a772d78 in st_join_table::sort_table() /data/src/10.2/sql/sql_select.cc:19729
          #23 0x558f1a772396 in join_init_read_record(st_join_table*) /data/src/10.2/sql/sql_select.cc:19670
          #24 0x558f1a76bac7 in sub_select(JOIN*, st_join_table*, bool) /data/src/10.2/sql/sql_select.cc:18761
          #25 0x558f1a769fd2 in do_select /data/src/10.2/sql/sql_select.cc:18308
          #26 0x558f1a70a208 in JOIN::exec_inner() /data/src/10.2/sql/sql_select.cc:3623
          #27 0x558f1a707e9d in JOIN::exec() /data/src/10.2/sql/sql_select.cc:3418
          #28 0x558f1a70b285 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.2/sql/sql_select.cc:3818
          #29 0x558f1a6ea260 in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.2/sql/sql_select.cc:376
       
      Thread T5 created by T0 here:
          #0 0x7f054e90fbba in pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x23bba)
          #1 0x558f1b3b16a3 in spawn_thread_v1 /data/src/10.2/storage/perfschema/pfs.cc:1912
          #2 0x558f1a449e7e in inline_mysql_thread_create /data/src/10.2/include/mysql/psi/mysql_thread.h:1239
          #3 0x558f1a45ee1b in create_thread_to_handle_connection(CONNECT*) /data/src/10.2/sql/mysqld.cc:6466
          #4 0x558f1a45f520 in create_new_thread /data/src/10.2/sql/mysqld.cc:6536
          #5 0x558f1a460537 in handle_connections_sockets() /data/src/10.2/sql/mysqld.cc:6811
          #6 0x558f1a45e370 in mysqld_main(int, char**) /data/src/10.2/sql/mysqld.cc:6085
          #7 0x558f1a44821f in main /data/src/10.2/sql/main.cc:25
          #8 0x7f054c9f42b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)
       
      SUMMARY: AddressSanitizer: heap-use-after-free /data/src/10.2/strings/dtoa.c:1378 my_strtod_int
      Shadow bytes around the buggy address:
        0x0c187fffcef0: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
        0x0c187fffcf00: 00 00 00 00 00 00 00 04 fa fa fa fa fa fa fa fa
        0x0c187fffcf10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04
        0x0c187fffcf20: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
        0x0c187fffcf30: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa
      =>0x0c187fffcf40: fd fd fd fd fd fd fd fd fd fd fd fd fd fd[fd]fd
        0x0c187fffcf50: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
        0x0c187fffcf60: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa
        0x0c187fffcf70: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c187fffcf80: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
        0x0c187fffcf90: 00 00 00 00 00 00 00 04 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
        Contiguous container OOB:fc
        ASan internal:           fe
      ==11131==ABORTING
      

      Test case based on Alice Sherepa 's findings:

      --source include/have_partition.inc
       
      CREATE TABLE t1 (
        pk INT PRIMARY KEY,
        b BLOB,
        vb TEXT AS (b) VIRTUAL,
        d INT,
        vd INT AS (d),
       KEY(d)
      ) PARTITION BY KEY() PARTITIONS 6;
       
      INSERT IGNORE INTO t1 (pk,b,d) VALUES
        (1,'1',0),(2,'2',1),(3,'3',2),(4,'4',3),(5,'5',4),(6,'6',5),
        (7,'7',6),(8,NULL,NULL),(9,'8',7),(10,NULL,8);
       
      SELECT * FROM t1 WHERE vb != d AND d > 0 ORDER BY vd;
       
      # Cleanup
      DROP TABLE t1;
      

      Also crashes on non-ASAN builds have been observed, but the test case doesn't necessarily reproduce them.

      10.2 3fb6d25

      #3  <signal handler called>
      #4  0x000055d2a44c61d4 in my_strtod_int (s00=0x8f8f8f8f8f8f8f8f <error: Cannot access memory at address 0x8f8f8f8f8f8f8f8f>, se=0x7fcdbc1ecc90, error=0x7fcdbc1ecc98, buf=0x7fcdbc1ebd30 "`\275\036\274\315\177", buf_size=3680) at /data/src/10.2/strings/dtoa.c:1378
      #5  0x000055d2a44c4e2d in my_strtod (str=0x8f8f8f8f8f8f8f8f <error: Cannot access memory at address 0x8f8f8f8f8f8f8f8f>, end=0x7fcdbc1ecc90, error=0x7fcdbc1ecc98) at /data/src/10.2/strings/dtoa.c:469
      #6  0x000055d2a44a2c6d in my_strntod_8bit (cs=0x55d2a4e6a580 <my_charset_bin>, str=0x8f8f8f8f8f8f8f8f <error: Cannot access memory at address 0x8f8f8f8f8f8f8f8f>, length=36751, end=0x7fcdbc1ecc90, err=0x7fcdbc1ecc98) at /data/src/10.2/strings/ctype-simple.c:788
      #7  0x000055d2a39e0288 in Value_source::Converter_strntod::Converter_strntod (this=0x7fcdbc1ecc90, cs=0x55d2a4e6a580 <my_charset_bin>, str=0x8f8f8f8f8f8f8f8f <error: Cannot access memory at address 0x8f8f8f8f8f8f8f8f>, length=36751) at /data/src/10.2/sql/field.h:159
      #8  0x000055d2a39e03c0 in Value_source::Converter_strntod_with_warn::Converter_strntod_with_warn (this=0x7fcdbc1ecc90, thd=0x7fcd44000b00, filter=..., cs=0x55d2a4e6a580 <my_charset_bin>, str=0x8f8f8f8f8f8f8f8f <error: Cannot access memory at address 0x8f8f8f8f8f8f8f8f>, length=36751) at /data/src/10.2/sql/field.h:229
      #9  0x000055d2a3cfb054 in Field_blob::val_real (this=0x7fcd44162018) at /data/src/10.2/sql/field.cc:8101
      #10 0x000055d2a3d2f534 in Item_field::val_real (this=0x7fcd44162138) at /data/src/10.2/sql/item.cc:2800
      #11 0x000055d2a3d8f213 in Item_func_plus::real_op (this=0x7fcd440fdf08) at /data/src/10.2/sql/item_func.cc:1300
      #12 0x000055d2a3d8da3f in Item_func_hybrid_field_type::val_real (this=0x7fcd440fdf08) at /data/src/10.2/sql/item_func.cc:911
      #13 0x000055d2a3d3916d in Item::save_in_field (this=0x7fcd440fdf08, field=0x7fcd4405c2d8, no_conversions=false) at /data/src/10.2/sql/item.cc:6377
      #14 0x000055d2a3bab48d in TABLE::update_virtual_fields (this=0x7fcd4411f170, h=0x7fcd440ef018, update_mode=VCOL_UPDATE_FOR_WRITE) at /data/src/10.2/sql/table.cc:7640
      #15 0x000055d2a3a34dc3 in fill_record (thd=0x7fcd44000b00, table_arg=0x7fcd4411f170, fields=..., values=..., ignore_errors=false, update=false) at /data/src/10.2/sql/sql_base.cc:8035
      #16 0x000055d2a3a35233 in fill_record_n_invoke_before_triggers (thd=0x7fcd44000b00, table=0x7fcd4411f170, fields=..., values=..., ignore_errors=false, event=TRG_EVENT_INSERT) at /data/src/10.2/sql/sql_base.cc:8164
      #17 0x000055d2a3a74cea in mysql_insert (thd=0x7fcd44000b00, table_list=0x7fcd440277b0, fields=..., values_list=..., update_fields=..., update_values=..., duplic=DUP_ERROR, ignore=true) at /data/src/10.2/sql/sql_insert.cc:958
      #18 0x000055d2a3a9cbc3 in mysql_execute_command (thd=0x7fcd44000b00) at /data/src/10.2/sql/sql_parse.cc:4438
      #19 0x000055d2a3aa80b3 in mysql_parse (thd=0x7fcd44000b00, rawbuf=0x7fcd44027658 "INSERT IGNORE INTO `oltp3` ( `k` ) VALUES ( 26138 ) /* QNO 6195 CON_ID 17 */", length=76, parser_state=0x7fcdbc1ee250, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:8015
      #20 0x000055d2a3a959ed in dispatch_command (command=COM_QUERY, thd=0x7fcd44000b00, packet=0x7fcd440088a1 "INSERT IGNORE INTO `oltp3` ( `k` ) VALUES ( 26138 ) /* QNO 6195 CON_ID 17 */", packet_length=76, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:1826
      #21 0x000055d2a3a94344 in do_command (thd=0x7fcd44000b00) at /data/src/10.2/sql/sql_parse.cc:1379
      #22 0x000055d2a3be72cf in do_handle_one_connection (connect=0x55d2a81153e0) at /data/src/10.2/sql/sql_connect.cc:1335
      #23 0x000055d2a3be705c in handle_one_connection (arg=0x55d2a81153e0) at /data/src/10.2/sql/sql_connect.cc:1241
      #24 0x00007fcdbf7d3494 in start_thread (arg=0x7fcdbc1ef700) at pthread_create.c:333
      #25 0x00007fcdbdbb993f in clone () from /lib/x86_64-linux-gnu/libc.so.6
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              nikitamalyavin Nikita Malyavin
              Reporter:
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated: