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

ASAN heap-use-after-free in copy_if_not_alloced / make_sortkey

    XMLWordPrintable

    Details

      Description

      Note: It might well be a duplicate of MDEV-18738, but since nobody could tell for sure, I'm filing it separately.

      CREATE TABLE t1 (a INT, b TIME, c TIME);
      INSERT INTO t1 VALUES (NULL,'22:56:45','22:56:45'),(4,'12:51:42','12:51:42');
      SELECT REPLACE( BINARY c, a, b ) f FROM t1 GROUP BY f WITH ROLLUP;
       
      # Cleanup
      DROP TABLE t1;
      

      10.1 ASAN d88dfd87

      ==12774==ERROR: AddressSanitizer: heap-use-after-free on address 0x603000056d78 at pc 0x55a62066514f bp 0x7f1fdf3f8aa0 sp 0x7f1fdf3f8a98
      READ of size 8 at 0x603000056d78 thread T24
          #0 0x55a62066514e in copy_if_not_alloced(String*, String*, unsigned int) /data/src/10.1/sql/sql_string.cc:915
          #1 0x55a620b784ff in Item_func_replace::val_str(String*) /data/src/10.1/sql/item_strfunc.cc:1197
          #2 0x55a620329b86 in Item::str_result(String*) /data/src/10.1/sql/item.h:1099
          #3 0x55a6209d9798 in make_sortkey /data/src/10.1/sql/filesort.cc:1003
          #4 0x55a6209de6bf in find_all_keys /data/src/10.1/sql/filesort.cc:840
          #5 0x55a6209de6bf in filesort(THD*, TABLE*, st_sort_field*, unsigned int, SQL_SELECT*, unsigned long long, bool, unsigned long long*, unsigned long long*, Filesort_tracker*) /data/src/10.1/sql/filesort.cc:301
          #6 0x55a6205c0ab3 in create_sort_index /data/src/10.1/sql/sql_select.cc:21677
          #7 0x55a6205e7476 in JOIN::exec_inner() /data/src/10.1/sql/sql_select.cc:3245
          #8 0x55a6205e8bd2 in JOIN::exec() /data/src/10.1/sql/sql_select.cc:2562
          #9 0x55a6205dd425 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/10.1/sql/sql_select.cc:3499
          #10 0x55a6205ddc13 in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.1/sql/sql_select.cc:388
          #11 0x55a6204acfe6 in execute_sqlcom_select /data/src/10.1/sql/sql_parse.cc:5941
          #12 0x55a6204c7404 in mysql_execute_command(THD*) /data/src/10.1/sql/sql_parse.cc:3038
          #13 0x55a6204dec7d in mysql_parse(THD*, char*, unsigned int, Parser_state*) /data/src/10.1/sql/sql_parse.cc:7459
          #14 0x55a6204e5a1d in dispatch_command(enum_server_command, THD*, char*, unsigned int) /data/src/10.1/sql/sql_parse.cc:1499
          #15 0x55a6204ec16e in do_command(THD*) /data/src/10.1/sql/sql_parse.cc:1131
          #16 0x55a620797334 in do_handle_one_connection(THD*) /data/src/10.1/sql/sql_connect.cc:1330
          #17 0x55a620797845 in handle_one_connection /data/src/10.1/sql/sql_connect.cc:1242
          #18 0x55a620eed24a in pfs_spawn_thread /data/src/10.1/storage/perfschema/pfs.cc:1861
          #19 0x7f2001280493 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x7493)
          #20 0x7f1fff21b93e in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xe893e)
       
      0x603000056d78 is located 8 bytes inside of 24-byte region [0x603000056d70,0x603000056d88)
      freed by thread T24 here:
          #0 0x7f20014ea9f6 in __interceptor_realloc (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x549f6)
          #1 0x55a62180aea5 in my_realloc /data/src/10.1/mysys/my_malloc.c:166
          #2 0x55a62192a4da (/data/bld/10.1-asan/bin/mysqld+0x1d9f4da)
       
      previously allocated by thread T24 here:
          #0 0x7f20014ea73f in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x5473f)
          #1 0x55a62180a852 in my_malloc /data/src/10.1/mysys/my_malloc.c:101
       
      Thread T24 created by T0 here:
          #0 0x7f20014b9bba in pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x23bba)
          #1 0x55a620ef8a5f in spawn_thread_v1 /data/src/10.1/storage/perfschema/pfs.cc:1911
       
      SUMMARY: AddressSanitizer: heap-use-after-free /data/src/10.1/sql/sql_string.cc:915 copy_if_not_alloced(String*, String*, unsigned int)
      Shadow bytes around the buggy address:
        0x0c0680002d50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c0680002d60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c0680002d70: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c0680002d80: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c0680002d90: fa fa fa fa fa fa fa fa fa fa fa fa 00 00 00 00
      =>0x0c0680002da0: fa fa 00 00 00 fa fa fa 00 00 00 fa fa fa fd[fd]
        0x0c0680002db0: fd fa fa fa fd fd fd fa fa fa 00 00 00 fa fa fa
        0x0c0680002dc0: 00 00 00 fa fa fa fd fd fd fa fa fa 00 00 00 00
        0x0c0680002dd0: fa fa fd fd fd fa fa fa fd fd fd fd fa fa fd fd
        0x0c0680002de0: fd fd fa fa fd fd fd fd fa fa fd fd fd fd fa fa
        0x0c0680002df0: fd fd fd fd fa fa fd fd fd fd fa fa 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
        Contiguous container OOB:fc
        ASan internal:           fe
      ==12774==ABORTING
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              bar Alexander Barkov
              Reporter:
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              1 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.