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

ASAN: heap-use-after-free upon LEAST(..CHARSET(..),..)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 5.5, 10.0, 10.1, 10.2, 10.3, 10.4
    • Fix Version/s: 10.1
    • Component/s: OTHER
    • Labels:
      None

      Description

      This issue was originally reported as a part of MDEV-14041, but then moved into a separate issue.

      CREATE TABLE t1 (a DATE, b TIME);
      INSERT INTO t1 VALUES ('2014-04-07','11:35:28');
      SELECT * FROM t1 GROUP BY GREATEST( TRIM(LEADING '02:18:28' FROM CHARSET(a)), UPPER(b) ) WITH ROLLUP;
      DROP TABLE t1;
      

      10.4 7b33a6a1 ASAN

      ==23264==ERROR: AddressSanitizer: heap-use-after-free on address 0x60d000047cc0 at pc 0x55df6365aa61 bp 0x7fda286d69f0 sp 0x7fda286d69e8
      READ of size 1 at 0x60d000047cc0 thread T5
          #0 0x55df6365aa60 in my_scan_weight_utf8_general_ci /data/src/10.4/strings/strcoll.ic:98
          #1 0x55df6365b2d6 in my_strnncollsp_utf8_general_ci /data/src/10.4/strings/strcoll.ic:254
          #2 0x55df61ead092 in sortcmp(String const*, String const*, charset_info_st const*) /data/src/10.4/sql/sql_string.cc:803
          #3 0x55df6259794a in Item_func_min_max::val_str_native(String*) /data/src/10.4/sql/item_func.cc:2679
          #4 0x55df62181568 in Type_handler_string_result::Item_func_min_max_val_str(Item_func_min_max*, String*) const /data/src/10.4/sql/sql_type.cc:5189
          #5 0x55df62560ec4 in Item_func_min_max::val_str(String*) /data/src/10.4/sql/item_func.h:1798
          #6 0x55df624ee7b6 in Cached_item_str::cmp() /data/src/10.4/sql/item_buff.cc:84
          #7 0x55df61df3a0a in test_if_group_changed(List<Cached_item>&) /data/src/10.4/sql/sql_select.cc:24413
          #8 0x55df61ddf82e in end_send_group(JOIN*, st_join_table*, bool) /data/src/10.4/sql/sql_select.cc:21403
          #9 0x55df61dd2562 in do_select /data/src/10.4/sql/sql_select.cc:19513
          #10 0x55df61d6be3c in JOIN::exec_inner() /data/src/10.4/sql/sql_select.cc:4371
          #11 0x55df61d69737 in JOIN::exec() /data/src/10.4/sql/sql_select.cc:4153
          #12 0x55df61d6d214 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:4585
          #13 0x55df61d437fa in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.4/sql/sql_select.cc:424
          #14 0x55df61cc4537 in execute_sqlcom_select /data/src/10.4/sql/sql_parse.cc:6652
          #15 0x55df61cb10fe in mysql_execute_command(THD*) /data/src/10.4/sql/sql_parse.cc:3889
          #16 0x55df61cccdda in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.4/sql/sql_parse.cc:8205
          #17 0x55df61ca4ce5 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.4/sql/sql_parse.cc:1829
          #18 0x55df61ca1b36 in do_command(THD*) /data/src/10.4/sql/sql_parse.cc:1358
          #19 0x55df620358a5 in do_handle_one_connection(CONNECT*) /data/src/10.4/sql/sql_connect.cc:1399
          #20 0x55df6203529e in handle_one_connection /data/src/10.4/sql/sql_connect.cc:1302
          #21 0x55df62bfcbe2 in pfs_spawn_thread /data/src/10.4/storage/perfschema/pfs.cc:1862
          #22 0x7fda33a86493 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x7493)
          #23 0x7fda31e6c93e in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xe893e)
       
      0x60d000047cc0 is located 112 bytes inside of 140-byte region [0x60d000047c50,0x60d000047cdc)
      freed by thread T5 here:
          #0 0x7fda33cf0527 in __interceptor_free (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x54527)
          #1 0x55df635ae2e1 in free_memory /data/src/10.4/mysys/safemalloc.c:279
          #2 0x55df635ad8e7 in sf_free /data/src/10.4/mysys/safemalloc.c:197
          #3 0x55df6357e330 in my_free /data/src/10.4/mysys/my_malloc.c:222
          #4 0x55df61a0f733 in Binary_string::free() /data/src/10.4/sql/sql_string.h:604
          #5 0x55df61ea7d7a in Binary_string::real_alloc(unsigned long) /data/src/10.4/sql/sql_string.cc:43
          #6 0x55df61a2f575 in Binary_string::alloc(unsigned long) /data/src/10.4/sql/sql_string.h:613
          #7 0x55df624dfd8b in String::copy(charset_info_st const*, charset_info_st const*, char const*, unsigned long, unsigned long, String_copier*) /data/src/10.4/sql/sql_string.h:847
          #8 0x55df624bb433 in String_copier_for_item::copy_with_warn(charset_info_st const*, String*, charset_info_st const*, char const*, unsigned int, unsigned int) /data/src/10.4/sql/item.cc:6214
          #9 0x55df6261816c in Item_func_conv_charset::val_str(String*) /data/src/10.4/sql/item_strfunc.cc:3446
          #10 0x55df625978fb in Item_func_min_max::val_str_native(String*) /data/src/10.4/sql/item_func.cc:2676
          #11 0x55df62181568 in Type_handler_string_result::Item_func_min_max_val_str(Item_func_min_max*, String*) const /data/src/10.4/sql/sql_type.cc:5189
          #12 0x55df62560ec4 in Item_func_min_max::val_str(String*) /data/src/10.4/sql/item_func.h:1798
          #13 0x55df624ee7b6 in Cached_item_str::cmp() /data/src/10.4/sql/item_buff.cc:84
          #14 0x55df61df3a0a in test_if_group_changed(List<Cached_item>&) /data/src/10.4/sql/sql_select.cc:24413
          #15 0x55df61ddf82e in end_send_group(JOIN*, st_join_table*, bool) /data/src/10.4/sql/sql_select.cc:21403
          #16 0x55df61dd2562 in do_select /data/src/10.4/sql/sql_select.cc:19513
          #17 0x55df61d6be3c in JOIN::exec_inner() /data/src/10.4/sql/sql_select.cc:4371
          #18 0x55df61d69737 in JOIN::exec() /data/src/10.4/sql/sql_select.cc:4153
          #19 0x55df61d6d214 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:4585
          #20 0x55df61d437fa in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.4/sql/sql_select.cc:424
          #21 0x55df61cc4537 in execute_sqlcom_select /data/src/10.4/sql/sql_parse.cc:6652
          #22 0x55df61cb10fe in mysql_execute_command(THD*) /data/src/10.4/sql/sql_parse.cc:3889
          #23 0x55df61cccdda in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.4/sql/sql_parse.cc:8205
          #24 0x55df61ca4ce5 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.4/sql/sql_parse.cc:1829
          #25 0x55df61ca1b36 in do_command(THD*) /data/src/10.4/sql/sql_parse.cc:1358
          #26 0x55df620358a5 in do_handle_one_connection(CONNECT*) /data/src/10.4/sql/sql_connect.cc:1399
          #27 0x55df6203529e in handle_one_connection /data/src/10.4/sql/sql_connect.cc:1302
          #28 0x55df62bfcbe2 in pfs_spawn_thread /data/src/10.4/storage/perfschema/pfs.cc:1862
          #29 0x7fda33a86493 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x7493)
       
      previously allocated by thread T5 here:
          #0 0x7fda33cf073f in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x5473f)
          #1 0x55df635ad057 in sf_malloc /data/src/10.4/mysys/safemalloc.c:118
          #2 0x55df6357d952 in my_malloc /data/src/10.4/mysys/my_malloc.c:101
          #3 0x55df61ea7dd9 in Binary_string::real_alloc(unsigned long) /data/src/10.4/sql/sql_string.cc:46
          #4 0x55df61a2f575 in Binary_string::alloc(unsigned long) /data/src/10.4/sql/sql_string.h:613
          #5 0x55df61eaa299 in String::copy(char const*, unsigned long, charset_info_st const*, charset_info_st const*, unsigned int*) /data/src/10.4/sql/sql_string.cc:443
          #6 0x55df626190de in Item_func_charset::val_str(String*) /data/src/10.4/sql/item_strfunc.cc:3513
          #7 0x55df62608d13 in Item_func_ltrim::val_str(String*) /data/src/10.4/sql/item_strfunc.cc:1938
          #8 0x55df62597791 in Item_func_min_max::val_str_native(String*) /data/src/10.4/sql/item_func.cc:2672
          #9 0x55df62181568 in Type_handler_string_result::Item_func_min_max_val_str(Item_func_min_max*, String*) const /data/src/10.4/sql/sql_type.cc:5189
          #10 0x55df62560ec4 in Item_func_min_max::val_str(String*) /data/src/10.4/sql/item_func.h:1798
          #11 0x55df624ee7b6 in Cached_item_str::cmp() /data/src/10.4/sql/item_buff.cc:84
          #12 0x55df61df3a0a in test_if_group_changed(List<Cached_item>&) /data/src/10.4/sql/sql_select.cc:24413
          #13 0x55df61ddf82e in end_send_group(JOIN*, st_join_table*, bool) /data/src/10.4/sql/sql_select.cc:21403
          #14 0x55df61dd2562 in do_select /data/src/10.4/sql/sql_select.cc:19513
          #15 0x55df61d6be3c in JOIN::exec_inner() /data/src/10.4/sql/sql_select.cc:4371
          #16 0x55df61d69737 in JOIN::exec() /data/src/10.4/sql/sql_select.cc:4153
          #17 0x55df61d6d214 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:4585
          #18 0x55df61d437fa in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.4/sql/sql_select.cc:424
          #19 0x55df61cc4537 in execute_sqlcom_select /data/src/10.4/sql/sql_parse.cc:6652
          #20 0x55df61cb10fe in mysql_execute_command(THD*) /data/src/10.4/sql/sql_parse.cc:3889
          #21 0x55df61cccdda in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.4/sql/sql_parse.cc:8205
          #22 0x55df61ca4ce5 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.4/sql/sql_parse.cc:1829
          #23 0x55df61ca1b36 in do_command(THD*) /data/src/10.4/sql/sql_parse.cc:1358
          #24 0x55df620358a5 in do_handle_one_connection(CONNECT*) /data/src/10.4/sql/sql_connect.cc:1399
          #25 0x55df6203529e in handle_one_connection /data/src/10.4/sql/sql_connect.cc:1302
          #26 0x55df62bfcbe2 in pfs_spawn_thread /data/src/10.4/storage/perfschema/pfs.cc:1862
          #27 0x7fda33a86493 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x7493)
       
      Thread T5 created by T0 here:
          #0 0x7fda33cbfbba in pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x23bba)
          #1 0x55df62bfd1aa in spawn_thread_v1 /data/src/10.4/storage/perfschema/pfs.cc:1912
          #2 0x55df619ec846 in inline_mysql_thread_create /data/src/10.4/include/mysql/psi/mysql_thread.h:1268
          #7 0x55df61a01973 in mysqld_main(int, char**) /data/src/10.4/sql/mysqld.cc:5876
          #8 0x55df619ea6cf in main /data/src/10.4/sql/main.cc:25
          #9 0x7fda31da42b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)
       
      SUMMARY: AddressSanitizer: heap-use-after-free /data/src/10.4/strings/strcoll.ic:98 my_scan_weight_utf8_general_ci
      Shadow bytes around the buggy address:
        0x0c1a80000f40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c1a80000f50: fa fa fa fa fa fa 00 00 00 00 00 00 00 00 00 00
        0x0c1a80000f60: 00 00 00 00 00 00 04 fa fa fa fa fa fa fa fa fa
        0x0c1a80000f70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
        0x0c1a80000f80: 04 fa fa fa fa fa fa fa fa fa fd fd fd fd fd fd
      =>0x0c1a80000f90: fd fd fd fd fd fd fd fd[fd]fd fd fd fa fa fa fa
        0x0c1a80000fa0: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 00
        0x0c1a80000fb0: 00 00 00 00 04 fa fa fa fa fa fa fa fa fa 00 00
        0x0c1a80000fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04
        0x0c1a80000fd0: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
        0x0c1a80000fe0: 00 00 00 00 00 00 00 00 00 04 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
      ==23264==ABORTING
      

      5.5 8024f8c6 ASAN

      ==24172==ERROR: AddressSanitizer: heap-use-after-free on address 0x60c000012d60 at pc 0x1697c49 bp 0x7fa810ad8d30 sp 0x7fa810ad8d28
      READ of size 1 at 0x60c000012d60 thread T5
          #0 0x1697c48 in my_utf8_uni /data/src/5.5/strings/ctype-utf8.c:2316
          #1 0x169b915 in my_strnncollsp_utf8 /data/src/5.5/strings/ctype-utf8.c:2761
          #2 0x809302 in sortcmp(String const*, String const*, charset_info_st const*) /data/src/5.5/sql/sql_string.cc:736
          #3 0xbc9d8a in Item_func_min_max::val_str(String*) /data/src/5.5/sql/item_func.cc:3000
          #4 0xb387ac in Cached_item_str::cmp() /data/src/5.5/sql/item_buff.cc:83
          #5 0x70ac75 in test_if_group_changed /data/src/5.5/sql/sql_select.cc:21404
          #6 0x788554 in end_send_group(JOIN*, st_join_table*, bool) /data/src/5.5/sql/sql_select.cc:18401
          #7 0x770d89 in do_select /data/src/5.5/sql/sql_select.cc:16742
          #8 0x7b0f3d in JOIN::exec() /data/src/5.5/sql/sql_select.cc:2912
          #9 0x79d8ac in mysql_select(THD*, Item***, 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/5.5/sql/sql_select.cc:3133
          #10 0x79df58 in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/5.5/sql/sql_select.cc:323
          #11 0x690312 in execute_sqlcom_select /data/src/5.5/sql/sql_parse.cc:4679
          #12 0x6a70bb in mysql_execute_command(THD*) /data/src/5.5/sql/sql_parse.cc:2225
          #13 0x6bac31 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /data/src/5.5/sql/sql_parse.cc:5924
          #14 0x6be7ac in dispatch_command(enum_server_command, THD*, char*, unsigned int) /data/src/5.5/sql/sql_parse.cc:1067
          #15 0x6c29f4 in do_command(THD*) /data/src/5.5/sql/sql_parse.cc:793
          #16 0x91bf7a in do_handle_one_connection(THD*) /data/src/5.5/sql/sql_connect.cc:1268
          #17 0x91c1eb in handle_one_connection /data/src/5.5/sql/sql_connect.cc:1184
          #18 0x10ab47f in pfs_spawn_thread /data/src/5.5/storage/perfschema/pfs.cc:1015
      freed by thread T5 here:
          #0 0x7fa81878e527 in __interceptor_free (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x54527)
          #1 0x1658faa in free_memory /data/src/5.5/mysys/safemalloc.c:205
       
      previously allocated by thread T5 here:
          #0 0x7fa81878e73f in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x5473f)
          #1 0x165908f in sf_malloc /data/src/5.5/mysys/safemalloc.c:105
       
      Thread T5 created by T0 here:
          #0 0x7fa81875dbba in pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x23bba)
          #1 0x10aeff4 in spawn_thread_v1 /data/src/5.5/storage/perfschema/pfs.cc:1038
       
      SUMMARY: AddressSanitizer: heap-use-after-free /data/src/5.5/strings/ctype-utf8.c:2316 my_utf8_uni
      Shadow bytes around the buggy address:
        0x0c187fffa550: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c187fffa560: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c187fffa570: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c187fffa580: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c187fffa590: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      =>0x0c187fffa5a0: fd fd fd fd fd fd fd fd fd fd fd fd[fd]fd fd fd
        0x0c187fffa5b0: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
        0x0c187fffa5c0: 00 00 00 00 00 00 07 fa fa fa fa fa fa fa fa fa
        0x0c187fffa5d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 fa
        0x0c187fffa5e0: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
        0x0c187fffa5f0: fd fd fd fd fd fd fd 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
        Contiguous container OOB:fc
        ASan internal:           fe
      ==24172==ABORTING
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bar Alexander Barkov
              Reporter:
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated: