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

ASAN heap-use-after-free in my_charlen_utf8 / my_well_formed_char_length_utf8 on 2nd execution of SP with ALTER trying to add bad CHECK

    XMLWordPrintable

Details

    Description

      Note: it might be the same problem as MDEV-16788, but the stack trace and the test case are different, so before closing it as a duplicate please make sure that the patch for MDEV-16788 does actually fix the problem here.

      CREATE TABLE t1 (a INT);
      CREATE PROCEDURE sp() ALTER TABLE t1 ADD CONSTRAINT CHECK (b > 0);
      --error ER_BAD_FIELD_ERROR
      CALL sp;
      --error ER_BAD_FIELD_ERROR
      CALL sp;
       
      # Cleanup
      DROP PROCEDURE sp;
      DROP TABLE t1;
      

      10.2 4ddcb4eb46c6

      ==1816==ERROR: AddressSanitizer: heap-use-after-free on address 0x6250000dcba0 at pc 0x55887fd9bdce bp 0x7f0212486450 sp 0x7f0212486448
      READ of size 1 at 0x6250000dcba0 thread T5
          #0 0x55887fd9bdcd in my_charlen_utf8 /data/src/10.2/strings/ctype-utf8.c:5400
          #1 0x55887fd9be39 in my_well_formed_char_length_utf8 /data/src/10.2/strings/ctype-mb.ic:187
          #2 0x55887e575d82 in Well_formed_prefix_status::Well_formed_prefix_status(charset_info_st const*, char const*, char const*, unsigned long) /data/src/10.2/sql/sql_string.h:62
          #3 0x55887e575dc8 in Well_formed_prefix::Well_formed_prefix(charset_info_st const*, char const*, unsigned long, unsigned long) /data/src/10.2/sql/sql_string.h:76
          #4 0x55887e6c5ec1 in check_string_char_length(st_mysql_lex_string*, unsigned int, unsigned int, charset_info_st const*, bool) /data/src/10.2/sql/sql_parse.cc:9824
          #5 0x55887e8994e4 in mysql_prepare_create_table /data/src/10.2/sql/sql_table.cc:4209
          #6 0x55887e89c669 in mysql_create_frm_image(THD*, char const*, char const*, HA_CREATE_INFO*, Alter_info*, int, st_key**, unsigned int*, st_mysql_const_unsigned_lex_string*) /data/src/10.2/sql/sql_table.cc:4656
          #7 0x55887e89dbc1 in create_table_impl /data/src/10.2/sql/sql_table.cc:4902
          #8 0x55887e8b8e28 in mysql_alter_table(THD*, char*, char*, HA_CREATE_INFO*, TABLE_LIST*, Alter_info*, unsigned int, st_order*, bool) /data/src/10.2/sql/sql_table.cc:9248
          #9 0x55887e9e3709 in Sql_cmd_alter_table::execute(THD*) /data/src/10.2/sql/sql_alter.cc:324
          #10 0x55887e6b0230 in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:6225
          #11 0x55887f031ead in sp_instr_stmt::exec_core(THD*, unsigned int*) /data/src/10.2/sql/sp_head.cc:3246
          #12 0x55887f030af9 in sp_lex_keeper::reset_lex_and_exec_core(THD*, unsigned int*, bool, sp_instr*) /data/src/10.2/sql/sp_head.cc:3009
          #13 0x55887f031777 in sp_instr_stmt::execute(THD*, unsigned int*) /data/src/10.2/sql/sp_head.cc:3162
          #14 0x55887f027078 in sp_head::execute(THD*, bool) /data/src/10.2/sql/sp_head.cc:1327
          #15 0x55887f02ae65 in sp_head::execute_procedure(THD*, List<Item>*) /data/src/10.2/sql/sp_head.cc:2116
          #16 0x55887e69b3de in do_execute_sp /data/src/10.2/sql/sql_parse.cc:2912
          #17 0x55887e6ad6da in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:5825
          #18 0x55887e6bacb9 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:8009
          #19 0x55887e6958a0 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1824
          #20 0x55887e692944 in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1378
          #21 0x55887e9d53a5 in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1335
          #22 0x55887e9d4dba in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #23 0x55887f3e48ed in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1862
          #24 0x7f021e912493 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x7493)
          #25 0x7f021ccf893e in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xe893e)
       
      0x6250000dcba0 is located 2720 bytes inside of 8268-byte region [0x6250000dc100,0x6250000de14c)
      freed by thread T5 here:
          #0 0x7f021eb7c527 in __interceptor_free (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x54527)
          #1 0x55887fd06a2b in free_memory /data/src/10.2/mysys/safemalloc.c:279
          #2 0x55887fd06031 in sf_free /data/src/10.2/mysys/safemalloc.c:197
          #3 0x55887fcd522a in my_free /data/src/10.2/mysys/my_malloc.c:217
          #4 0x55887fcb68a0 in free_root /data/src/10.2/mysys/my_alloc.c:398
          #5 0x55887f027216 in sp_head::execute(THD*, bool) /data/src/10.2/sql/sp_head.cc:1346
          #6 0x55887f02ae65 in sp_head::execute_procedure(THD*, List<Item>*) /data/src/10.2/sql/sp_head.cc:2116
          #7 0x55887e69b3de in do_execute_sp /data/src/10.2/sql/sql_parse.cc:2912
          #8 0x55887e6ad6da in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:5825
          #9 0x55887e6bacb9 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:8009
          #10 0x55887e6958a0 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1824
          #11 0x55887e692944 in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1378
          #12 0x55887e9d53a5 in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1335
          #13 0x55887e9d4dba in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #14 0x55887f3e48ed in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1862
          #15 0x7f021e912493 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x7493)
       
      previously allocated by thread T5 here:
          #0 0x7f021eb7c73f in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x5473f)
          #1 0x55887fd057a1 in sf_malloc /data/src/10.2/mysys/safemalloc.c:118
          #2 0x55887fcd4962 in my_malloc /data/src/10.2/mysys/my_malloc.c:101
          #3 0x55887fcb5805 in alloc_root /data/src/10.2/mysys/my_alloc.c:241
          #4 0x55887e6ca1c1 in Query_arena::memdup_w_gap(void const*, unsigned long, unsigned int) /data/src/10.2/sql/sql_class.h:986
          #5 0x55887e699d66 in alloc_query(THD*, char const*, unsigned int) /data/src/10.2/sql/sql_parse.cc:2647
          #6 0x55887f031663 in sp_instr_stmt::execute(THD*, unsigned int*) /data/src/10.2/sql/sp_head.cc:3150
          #7 0x55887f027078 in sp_head::execute(THD*, bool) /data/src/10.2/sql/sp_head.cc:1327
          #8 0x55887f02ae65 in sp_head::execute_procedure(THD*, List<Item>*) /data/src/10.2/sql/sp_head.cc:2116
          #9 0x55887e69b3de in do_execute_sp /data/src/10.2/sql/sql_parse.cc:2912
          #10 0x55887e6ad6da in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:5825
          #11 0x55887e6bacb9 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:8009
          #12 0x55887e6958a0 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1824
          #13 0x55887e692944 in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1378
          #14 0x55887e9d53a5 in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1335
          #15 0x55887e9d4dba in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #16 0x55887f3e48ed in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1862
          #17 0x7f021e912493 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x7493)
       
      Thread T5 created by T0 here:
          #0 0x7f021eb4bbba in pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x23bba)
          #1 0x55887f3e4eb5 in spawn_thread_v1 /data/src/10.2/storage/perfschema/pfs.cc:1912
          #2 0x55887e48fd8e in inline_mysql_thread_create /data/src/10.2/include/mysql/psi/mysql_thread.h:1239
          #3 0x55887e4a4cb6 in create_thread_to_handle_connection(CONNECT*) /data/src/10.2/sql/mysqld.cc:6457
          #4 0x55887e4a53bb in create_new_thread /data/src/10.2/sql/mysqld.cc:6527
          #5 0x55887e4a63d2 in handle_connections_sockets() /data/src/10.2/sql/mysqld.cc:6802
          #6 0x55887e4a420b in mysqld_main(int, char**) /data/src/10.2/sql/mysqld.cc:6076
          #7 0x55887e48e12f in main /data/src/10.2/sql/main.cc:25
          #8 0x7f021cc302b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)
       
      SUMMARY: AddressSanitizer: heap-use-after-free /data/src/10.2/strings/ctype-utf8.c:5400 my_charlen_utf8
      Shadow bytes around the buggy address:
        0x0c4a80013920: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a80013930: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a80013940: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a80013950: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a80013960: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      =>0x0c4a80013970: fd fd fd fd[fd]fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a80013980: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a80013990: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a800139a0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a800139b0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a800139c0: 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
        Contiguous container OOB:fc
        ASan internal:           fe
      ==1816==ABORTING
      

      Reproducible with at least MyISAM and InnoDB.

      Valgrind fails in a similar fashion.
      Non-ASAN builds don't crash, but with some luck fail with an odd error indicating a corruption. e.g.:

      mysqltest: At line 6: query 'CALL sp' failed with wrong errno 1059: 'Identifier name '' is too long', instead of 1054...
      

      Attachments

        Issue Links

          Activity

            People

              sanja Oleksandr Byelkin
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              4 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.