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

ASAN heap-use-after-free in my_charlen_utf8 / handle_if_exists_options on 2nd execution of SP with ALTER adding CHECK constraint

    XMLWordPrintable

Details

    Description

      Note: it might be the same problem as MDEV-16932, 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-16932 does actually fix the problem here.

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

      10.2 4ddcb4eb46c6

      ==2802==ERROR: AddressSanitizer: heap-use-after-free on address 0x6250000dcba0 at pc 0x563075b51ba0 bp 0x7f42e0065da0 sp 0x7f42e0065d98
      READ of size 1 at 0x6250000dcba0 thread T5
          #0 0x563075b51b9f in my_strcasecmp_utf8 /data/src/10.2/strings/ctype-utf8.c:5304
          #1 0x56307465bb42 in handle_if_exists_options /data/src/10.2/sql/sql_table.cc:6217
          #2 0x56307466db96 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:8984
          #3 0x563074799709 in Sql_cmd_alter_table::execute(THD*) /data/src/10.2/sql/sql_alter.cc:324
          #4 0x563074466230 in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:6225
          #5 0x563074de7ead in sp_instr_stmt::exec_core(THD*, unsigned int*) /data/src/10.2/sql/sp_head.cc:3246
          #6 0x563074de6af9 in sp_lex_keeper::reset_lex_and_exec_core(THD*, unsigned int*, bool, sp_instr*) /data/src/10.2/sql/sp_head.cc:3009
          #7 0x563074de7777 in sp_instr_stmt::execute(THD*, unsigned int*) /data/src/10.2/sql/sp_head.cc:3162
          #8 0x563074ddd078 in sp_head::execute(THD*, bool) /data/src/10.2/sql/sp_head.cc:1327
          #9 0x563074de0e65 in sp_head::execute_procedure(THD*, List<Item>*) /data/src/10.2/sql/sp_head.cc:2116
          #10 0x5630744513de in do_execute_sp /data/src/10.2/sql/sql_parse.cc:2912
          #11 0x5630744636da in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:5825
          #12 0x563074470cb9 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:8009
          #13 0x56307444b8a0 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1824
          #14 0x563074448944 in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1378
          #15 0x56307478b3a5 in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1335
          #16 0x56307478adba in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #17 0x56307519a8ed in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1862
          #18 0x7f42ec4ef493 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x7493)
          #19 0x7f42ea8d593e 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 0x7f42ec759527 in __interceptor_free (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x54527)
          #1 0x563075abca2b in free_memory /data/src/10.2/mysys/safemalloc.c:279
          #2 0x563075abc031 in sf_free /data/src/10.2/mysys/safemalloc.c:197
          #3 0x563075a8b22a in my_free /data/src/10.2/mysys/my_malloc.c:217
          #4 0x563075a6c8a0 in free_root /data/src/10.2/mysys/my_alloc.c:398
          #5 0x563074ddd216 in sp_head::execute(THD*, bool) /data/src/10.2/sql/sp_head.cc:1346
          #6 0x563074de0e65 in sp_head::execute_procedure(THD*, List<Item>*) /data/src/10.2/sql/sp_head.cc:2116
          #7 0x5630744513de in do_execute_sp /data/src/10.2/sql/sql_parse.cc:2912
          #8 0x5630744636da in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:5825
          #9 0x563074470cb9 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:8009
          #10 0x56307444b8a0 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1824
          #11 0x563074448944 in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1378
          #12 0x56307478b3a5 in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1335
          #13 0x56307478adba in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #14 0x56307519a8ed in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1862
          #15 0x7f42ec4ef493 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x7493)
       
      previously allocated by thread T5 here:
          #0 0x7f42ec75973f in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x5473f)
          #1 0x563075abb7a1 in sf_malloc /data/src/10.2/mysys/safemalloc.c:118
          #2 0x563075a8a962 in my_malloc /data/src/10.2/mysys/my_malloc.c:101
          #3 0x563075a6b805 in alloc_root /data/src/10.2/mysys/my_alloc.c:241
          #4 0x5630744801c1 in Query_arena::memdup_w_gap(void const*, unsigned long, unsigned int) /data/src/10.2/sql/sql_class.h:986
          #5 0x56307444fd66 in alloc_query(THD*, char const*, unsigned int) /data/src/10.2/sql/sql_parse.cc:2647
          #6 0x563074de7663 in sp_instr_stmt::execute(THD*, unsigned int*) /data/src/10.2/sql/sp_head.cc:3150
          #7 0x563074ddd078 in sp_head::execute(THD*, bool) /data/src/10.2/sql/sp_head.cc:1327
          #8 0x563074de0e65 in sp_head::execute_procedure(THD*, List<Item>*) /data/src/10.2/sql/sp_head.cc:2116
          #9 0x5630744513de in do_execute_sp /data/src/10.2/sql/sql_parse.cc:2912
          #10 0x5630744636da in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:5825
          #11 0x563074470cb9 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:8009
          #12 0x56307444b8a0 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1824
          #13 0x563074448944 in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1378
          #14 0x56307478b3a5 in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1335
          #15 0x56307478adba in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #16 0x56307519a8ed in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1862
          #17 0x7f42ec4ef493 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x7493)
       
      Thread T5 created by T0 here:
          #0 0x7f42ec728bba in pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x23bba)
          #1 0x56307519aeb5 in spawn_thread_v1 /data/src/10.2/storage/perfschema/pfs.cc:1912
          #2 0x563074245d8e in inline_mysql_thread_create /data/src/10.2/include/mysql/psi/mysql_thread.h:1239
          #3 0x56307425acb6 in create_thread_to_handle_connection(CONNECT*) /data/src/10.2/sql/mysqld.cc:6457
          #4 0x56307425b3bb in create_new_thread /data/src/10.2/sql/mysqld.cc:6527
          #5 0x56307425c3d2 in handle_connections_sockets() /data/src/10.2/sql/mysqld.cc:6802
          #6 0x56307425a20b in mysqld_main(int, char**) /data/src/10.2/sql/mysqld.cc:6076
          #7 0x56307424412f in main /data/src/10.2/sql/main.cc:25
          #8 0x7f42ea80d2b0 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:5304 my_strcasecmp_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
      ==2802==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 4: query 'CALL sp' failed: 1059: Identifier name '' is too long
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              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.