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

ASAN heap-use-after-free in my_strnncoll_binary upon a mix of char functions

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.1(EOL), 10.2(EOL), 10.3(EOL), 10.4(EOL), 10.5, 10.6, 10.7(EOL), 10.8(EOL), 10.9(EOL), 10.10(EOL), 10.11, 11.0(EOL), 11.1(EOL), 11.2(EOL), 11.3(EOL), 11.4, 11.5(EOL)
    • 10.5, 10.6, 10.11, 11.4
    • Data types, Server
    • None

    Description

      SELECT BIT_AND(NULL) AS f FROM DUAL ORDER BY GREATEST( CAST( CONVERT( 'foo' USING latin1 ) AS BINARY(1) ), CHARSET('foo') );
      

      10.1 6567636b ASAN

      ==23747==ERROR: AddressSanitizer: heap-use-after-free on address 0x60c000028eb0 at pc 0x564fd6a93d76 bp 0x7f38d33468e0 sp 0x7f38d33468d8
      READ of size 1 at 0x60c000028eb0 thread T6
          #0 0x564fd6a93d75 in my_strnncoll_binary /data/src/10.1/strings/ctype-bin.c:85
          #1 0x564fd6a93e0b in my_strnncollsp_binary /data/src/10.1/strings/ctype-bin.c:126
          #2 0x564fd589ed80 in sortcmp(String const*, String const*, charset_info_st const*) /data/src/10.1/sql/sql_string.cc:771
          #3 0x564fd5d494d9 in Item_func_min_max::val_str(String*) /data/src/10.1/sql/item_func.cc:2977
          #4 0x564fd5c59c97 in Item_copy_string::copy() /data/src/10.1/sql/item.cc:4063
          #5 0x564fd57e4cfb in copy_fields(TMP_TABLE_PARAM*) /data/src/10.1/sql/sql_select.cc:23163
          #6 0x564fd57f2e35 in end_send_group(JOIN*, st_join_table*, bool) /data/src/10.1/sql/sql_select.cc:19816
          #7 0x564fd57dd27d in do_select /data/src/10.1/sql/sql_select.cc:18091
          #8 0x564fd582226e in JOIN::exec_inner() /data/src/10.1/sql/sql_select.cc:3275
          #9 0x564fd5823556 in JOIN::exec() /data/src/10.1/sql/sql_select.cc:2562
          #10 0x564fd5817da9 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
          #11 0x564fd5818597 in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.1/sql/sql_select.cc:388
          #12 0x564fd56e7603 in execute_sqlcom_select /data/src/10.1/sql/sql_parse.cc:5991
          #13 0x564fd570194d in mysql_execute_command(THD*) /data/src/10.1/sql/sql_parse.cc:3042
          #14 0x564fd5719af0 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /data/src/10.1/sql/sql_parse.cc:7509
          #15 0x564fd57208a2 in dispatch_command(enum_server_command, THD*, char*, unsigned int) /data/src/10.1/sql/sql_parse.cc:1496
          #16 0x564fd5727074 in do_command(THD*) /data/src/10.1/sql/sql_parse.cc:1124
          #17 0x564fd59cf5e7 in do_handle_one_connection(THD*) /data/src/10.1/sql/sql_connect.cc:1330
          #18 0x564fd59cfaf8 in handle_one_connection /data/src/10.1/sql/sql_connect.cc:1242
          #19 0x564fd629f24e in pfs_spawn_thread /data/src/10.1/storage/perfschema/pfs.cc:1861
          #20 0x7f38dfab1493 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x7493)
          #21 0x7f38dde6a93e in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xe893e)
       
      0x60c000028eb0 is located 112 bytes inside of 124-byte region [0x60c000028e40,0x60c000028ebc)
      freed by thread T6 here:
          #0 0x7f38dfd1b527 in __interceptor_free (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x54527)
          #1 0x564fd6a6b7cf in free_memory /data/src/10.1/mysys/safemalloc.c:276
       
      previously allocated by thread T6 here:
          #0 0x7f38dfd1b73f in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x5473f)
          #1 0x564fd6a6b8a0 in sf_malloc /data/src/10.1/mysys/safemalloc.c:115
          #2 0x564fd6b642da (/data/bld/10.1-asan/bin/mysqld+0x1da02da)
       
      Thread T6 created by T0 here:
          #0 0x7f38dfceabba in pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x23bba)
          #1 0x564fd62aaaa5 in spawn_thread_v1 /data/src/10.1/storage/perfschema/pfs.cc:1911
       
      SUMMARY: AddressSanitizer: heap-use-after-free /data/src/10.1/strings/ctype-bin.c:85 my_strnncoll_binary
      Shadow bytes around the buggy address:
        0x0c187fffd180: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c187fffd190: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c187fffd1a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c187fffd1b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c187fffd1c0: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
      =>0x0c187fffd1d0: fd fd fd fd fd fd[fd]fd fa fa fa fa fa fa fa fa
        0x0c187fffd1e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04
        0x0c187fffd1f0: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
        0x0c187fffd200: 00 00 00 00 00 00 00 04 fa fa fa fa fa fa fa fa
        0x0c187fffd210: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c187fffd220: fa fa fa fa fa fa fa fa 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
        Contiguous container OOB:fc
        ASan internal:           fe
      ==23747==ABORTING
      

      No crash on non-ASAN builds, they produce the result, I can't tell if it's correct or not:

      f
      18446744073709551615
      Warnings:
      Warning	1292	Truncated incorrect BINARY(1) value: 'foo'
      

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.