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

Server crashes in TABLE_LIST::reinit_before_use upon ADD FOREIGN KEY on 2nd execution of PS/SP

    XMLWordPrintable

    Details

      Description

      --source include/have_innodb.inc
       
      CREATE TABLE t1 (pk INT PRIMARY KEY, i INT, KEY(i)) ENGINE=InnoDB;
       
      PREPARE stmt FROM "ALTER TABLE t1 ADD FOREIGN KEY (i) REFERENCES t1 (pk)"; 
      EXECUTE stmt;
      EXECUTE stmt;
       
      # Cleanup
      DROP TABLE t1;
      

      10.0 debug 8634f7e528

      #3  <signal handler called>
      #4  0x0000000000735a88 in TABLE_LIST::reinit_before_use (this=0x7efd258f94b0, thd=0x7efd2df69070) at /data/src/10.0/sql/table.cc:6464
      #5  0x000000000066d640 in reinit_stmt_before_use (thd=0x7efd2df69070, lex=0x7efd25b9f090) at /data/src/10.0/sql/sql_prepare.cc:2622
      #6  0x0000000000670761 in Prepared_statement::execute (this=0x7efd2592f870, expanded_query=0x7efd3bb12bd0, open_cursor=false) at /data/src/10.0/sql/sql_prepare.cc:3950
      #7  0x000000000066f91e in Prepared_statement::execute_loop (this=0x7efd2592f870, expanded_query=0x7efd3bb12bd0, open_cursor=false, packet=0x0, packet_end=0x0) at /data/src/10.0/sql/sql_prepare.cc:3629
      #8  0x000000000066dc0c in mysql_sql_stmt_execute (thd=0x7efd2df69070) at /data/src/10.0/sql/sql_prepare.cc:2779
      #9  0x000000000064da33 in mysql_execute_command (thd=0x7efd2df69070) at /data/src/10.0/sql/sql_parse.cc:2568
      #10 0x0000000000658372 in mysql_parse (thd=0x7efd2df69070, rawbuf=0x7efd258f8088 "EXECUTE stmt", length=12, parser_state=0x7efd3bb13640) at /data/src/10.0/sql/sql_parse.cc:6644
      #11 0x000000000064ac2c in dispatch_command (command=COM_QUERY, thd=0x7efd2df69070, packet=0x7efd339ef071 "EXECUTE stmt", packet_length=12) at /data/src/10.0/sql/sql_parse.cc:1301
      #12 0x0000000000649f20 in do_command (thd=0x7efd2df69070) at /data/src/10.0/sql/sql_parse.cc:1003
      #13 0x000000000076baa8 in do_handle_one_connection (thd_arg=0x7efd2df69070) at /data/src/10.0/sql/sql_connect.cc:1377
      #14 0x000000000076b81a in handle_one_connection (arg=0x7efd2df69070) at /data/src/10.0/sql/sql_connect.cc:1292
      #15 0x0000000000acd6de in pfs_spawn_thread (arg=0x7efd2df19670) at /data/src/10.0/storage/perfschema/pfs.cc:1861
      #16 0x00007efd3b756494 in start_thread (arg=0x7efd3bb14700) at pthread_create.c:333
      #17 0x00007efd39b0f93f in clone () from /lib/x86_64-linux-gnu/libc.so.6
      

      10.0 8634f7e528 ASAN

      ==22916==ERROR: AddressSanitizer: use-after-poison on address 0x6250000dd680 at pc 0x8fc505 bp 0x7fd1d13e0140 sp 0x7fd1d13e0138
      WRITE of size 8 at 0x6250000dd680 thread T21
          #0 0x8fc504 in TABLE_LIST::reinit_before_use(THD*) /data/src/10.0/sql/table.cc:6454
          #1 0x70a581 in reinit_stmt_before_use(THD*, LEX*) /data/src/10.0/sql/sql_prepare.cc:2622
          #2 0x71519d in Prepared_statement::execute(String*, bool) /data/src/10.0/sql/sql_prepare.cc:3950
          #3 0x715d3a in Prepared_statement::execute_loop(String*, bool, unsigned char*, unsigned char*) /data/src/10.0/sql/sql_prepare.cc:3629
          #4 0x71697a in mysql_sql_stmt_execute(THD*) /data/src/10.0/sql/sql_prepare.cc:2779
          #5 0x6cee96 in mysql_execute_command(THD*) /data/src/10.0/sql/sql_parse.cc:2568
          #6 0x6e5006 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /data/src/10.0/sql/sql_parse.cc:6644
          #7 0x6e8c25 in dispatch_command(enum_server_command, THD*, char*, unsigned int) /data/src/10.0/sql/sql_parse.cc:1301
          #8 0x6ed51e in do_command(THD*) /data/src/10.0/sql/sql_parse.cc:1003
          #9 0x97ddd3 in do_handle_one_connection(THD*) /data/src/10.0/sql/sql_connect.cc:1377
          #10 0x97e03a in handle_one_connection /data/src/10.0/sql/sql_connect.cc:1292
          #11 0x11b8302 in pfs_spawn_thread /data/src/10.0/storage/perfschema/pfs.cc:1861
          #12 0x7fd1e8c16493 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x7493)
          #13 0x7fd1e6fcf93e in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xe893e)
       
      0x6250000dd680 is located 5504 bytes inside of 8332-byte region [0x6250000dc100,0x6250000de18c)
      allocated by thread T21 here:
          #0 0x7fd1e8e8073f in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x5473f)
          #1 0x18f8ae4 in sf_malloc /data/src/10.0/mysys/safemalloc.c:115
          #2 0x19db8ca (/data/bld/10.0-asan/bin/mysqld+0x19db8ca)
       
      Thread T21 created by T0 here:
          #0 0x7fd1e8e4fbba in pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x23bba)
          #1 0x11c3b59 in spawn_thread_v1 /data/src/10.0/storage/perfschema/pfs.cc:1911
       
      SUMMARY: AddressSanitizer: use-after-poison /data/src/10.0/sql/table.cc:6454 TABLE_LIST::reinit_before_use(THD*)
      Shadow bytes around the buggy address:
        0x0c4a80013a80: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c4a80013a90: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c4a80013aa0: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c4a80013ab0: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c4a80013ac0: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
      =>0x0c4a80013ad0:[f7]f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c4a80013ae0: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c4a80013af0: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c4a80013b00: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c4a80013b10: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c4a80013b20: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
      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
      ==22916==ABORTING
      

      10.0 8634f7e528 non-debug

      #2  <signal handler called>
      #3  placeholder (this=0x4) at /data/src/10.0/sql/table.h:2113
      #4  lock_tables (thd=0x7faf2ea75008, tables=0x7faf260ed550, count=<optimized out>, flags=0) at /data/src/10.0/sql/sql_base.cc:5483
      #5  0x0000000000622192 in mysql_alter_table (thd=0x7faf2ea75008, new_db=0x0, new_name=0x0, create_info=0x7faf3be28150, table_list=0x7faf260ed550, alter_info=0x11fec40 <my_collation_utf8_general_ci_handler>, order_num=0, order=0x0, ignore=false) at /data/src/10.0/sql/sql_table.cc:9032
      #6  0x00000000006604bd in Sql_cmd_alter_table::execute (this=0x7faf261c8590, thd=0x7faf2ea75008) at /data/src/10.0/sql/sql_alter.cc:312
      #7  0x00000000005a50e4 in mysql_execute_command (thd=0x7faf2ea75008) at /data/src/10.0/sql/sql_parse.cc:5125
      #8  0x00000000005ba137 in Prepared_statement::execute (this=this@entry=0x7faf26327608, expanded_query=expanded_query@entry=0x7faf3be29840, open_cursor=open_cursor@entry=false) at /data/src/10.0/sql/sql_prepare.cc:3975
      #9  0x00000000005ba228 in Prepared_statement::execute_loop (this=0x7faf26327608, expanded_query=0x7faf3be29840, open_cursor=<optimized out>, packet=<optimized out>, packet_end=<optimized out>) at /data/src/10.0/sql/sql_prepare.cc:3629
      #10 0x00000000005ba552 in mysql_sql_stmt_execute (thd=<optimized out>) at /data/src/10.0/sql/sql_prepare.cc:2779
      #11 0x00000000005a638c in mysql_execute_command (thd=0x7faf2ea75008) at /data/src/10.0/sql/sql_parse.cc:2568
      #12 0x00000000005abb08 in mysql_parse (thd=0x7faf2ea75008, rawbuf=<optimized out>, length=12, parser_state=0x7faf3be2a6e0) at /data/src/10.0/sql/sql_parse.cc:6644
      #13 0x00000000005ad4ed in dispatch_command (command=<optimized out>, thd=0x7faf2ea75008, packet=<optimized out>, packet_length=<optimized out>) at /data/src/10.0/sql/sql_parse.cc:1301
      #14 0x00000000005adf5f in do_command (thd=<optimized out>) at /data/src/10.0/sql/sql_parse.cc:1003
      #15 0x000000000065dc04 in do_handle_one_connection (thd_arg=thd_arg@entry=0x7faf2ea75008) at /data/src/10.0/sql/sql_connect.cc:1377
      #16 0x000000000065dc48 in handle_one_connection (arg=arg@entry=0x7faf2ea75008) at /data/src/10.0/sql/sql_connect.cc:1292
      #17 0x0000000000892664 in pfs_spawn_thread (arg=0x7faf3943f808) at /data/src/10.0/storage/perfschema/pfs.cc:1861
      #18 0x00007faf3ba69494 in start_thread (arg=0x7faf3be2b700) at pthread_create.c:333
      #19 0x00007faf39e2293f in clone () from /lib/x86_64-linux-gnu/libc.so.6
      

      10.3 779151db80d non-debug

      #2  <signal handler called>
      #3  MDL_lock::can_grant_lock (this=this@entry=0x558e3b219190, type_arg=1409363792, requestor_ctx=requestor_ctx@entry=0x7fbb54000ac8, ignore_lock_priority=ignore_lock_priority@entry=false) at /data/src/10.3/sql/mdl.cc:1559
      #4  0x0000558e38fba338 in MDL_context::try_acquire_lock_impl (this=this@entry=0x7fbb54000ac8, mdl_request=mdl_request@entry=0x7fbb54012fd0, out_ticket=out_ticket@entry=0x7fbba80c2f18) at /data/src/10.3/sql/mdl.cc:1925
      #5  0x0000558e38fba916 in MDL_context::acquire_lock (this=this@entry=0x7fbb54000ac8, mdl_request=0x7fbb54012fd0, lock_wait_timeout=lock_wait_timeout@entry=86400) at /data/src/10.3/sql/mdl.cc:2069
      #6  0x0000558e38fbb4de in MDL_context::acquire_locks (this=this@entry=0x7fbb54000ac8, mdl_requests=mdl_requests@entry=0x7fbba80c3030, lock_wait_timeout=86400) at /data/src/10.3/sql/mdl.cc:2268
      #7  0x0000558e38e81c9d in lock_table_names (thd=thd@entry=0x7fbb540009a8, options=..., tables_start=0x7fbb54012b78, tables_end=<optimized out>, lock_wait_timeout=<optimized out>, flags=flags@entry=0) at /data/src/10.3/sql/sql_base.cc:3869
      #8  0x0000558e38e834a2 in open_tables (thd=thd@entry=0x7fbb540009a8, options=..., start=0x7fbb540add78, counter=counter@entry=0x7fbba80c33f8, flags=flags@entry=0, prelocking_strategy=prelocking_strategy@entry=0x7fbba80c3400) at /data/src/10.3/sql/sql_base.cc:4088
      #9  0x0000558e38f69da4 in open_tables (prelocking_strategy=0x7fbba80c3400, flags=0, counter=0x7fbba80c33f8, tables=<optimized out>, thd=0x7fbb540009a8) at /data/src/10.3/sql/sql_base.h:250
      #10 mysql_alter_table (thd=<optimized out>, new_db=<optimized out>, new_name=<optimized out>, create_info=<optimized out>, table_list=0x7fbb540add70, alter_info=0x7fbba80c4c30, order_num=0, order=0x0, ignore=false) at /data/src/10.3/sql/sql_table.cc:9853
      #11 0x0000558e38fb5d38 in Sql_cmd_alter_table::execute (this=0x558e39f23908 <MDL_lock::m_scoped_lock_strategy>, thd=0x7fbb540009a8) at /data/src/10.3/sql/sql_alter.cc:497
      #12 0x0000558e38ed7467 in mysql_execute_command (thd=0x7fbb540009a8) at /data/src/10.3/sql/sql_parse.cc:6285
      #13 0x0000558e38ef0a37 in Prepared_statement::execute (this=this@entry=0x7fbb54006508, expanded_query=expanded_query@entry=0x7fbba80c6e10, open_cursor=open_cursor@entry=false) at /data/src/10.3/sql/sql_prepare.cc:4788
      #14 0x0000558e38ef0b84 in Prepared_statement::execute_loop (this=0x7fbb54006508, expanded_query=0x7fbba80c6e10, open_cursor=<optimized out>, packet=<optimized out>, packet_end=<optimized out>) at /data/src/10.3/sql/sql_prepare.cc:4216
      #15 0x0000558e38ef0fc2 in mysql_sql_stmt_execute (thd=0x7fbb540009a8) at /data/src/10.3/sql/sql_prepare.cc:3324
      #16 0x0000558e38ed9cf2 in mysql_execute_command (thd=0x7fbb540009a8) at /data/src/10.3/sql/sql_parse.cc:3785
      #17 0x0000558e38eddb09 in mysql_parse (thd=0x7fbb540009a8, rawbuf=<optimized out>, length=12, parser_state=0x7fbba80c8630, is_com_multi=<optimized out>, is_next_command=<optimized out>) at /data/src/10.3/sql/sql_parse.cc:8092
      #18 0x0000558e38ee0e5e in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x7fbb540009a8, packet=packet@entry=0x7fbb54009319 "EXECUTE stmt", packet_length=packet_length@entry=12, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /data/src/10.3/sql/sql_parse.cc:1851
      #19 0x0000558e38ee1500 in do_command (thd=0x7fbb540009a8) at /data/src/10.3/sql/sql_parse.cc:1396
      #20 0x0000558e38fb31f4 in do_handle_one_connection (connect=connect@entry=0x558e3b583f18) at /data/src/10.3/sql/sql_connect.cc:1402
      #21 0x0000558e38fb3394 in handle_one_connection (arg=arg@entry=0x558e3b583f18) at /data/src/10.3/sql/sql_connect.cc:1308
      #22 0x0000558e39296634 in pfs_spawn_thread (arg=0x558e3b5f4c98) at /data/src/10.3/storage/perfschema/pfs.cc:1862
      #23 0x00007fbbaf50f494 in start_thread (arg=0x7fbba80c9700) at pthread_create.c:333
      #24 0x00007fbbadb1093f in clone () from /lib/x86_64-linux-gnu/libc.so.6
      

      Also reproducible with a stored procedure instead of a prepared statement.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              svoj Sergey Vojtovich
              Reporter:
              elenst Elena Stepanova
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: