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

Server crash in base_list::push_back or ASAN use-after-poison in multi_update::prepare upon 2nd execution of SP with erroneous UPDATE

    Details

      Description

      CREATE TABLE t (f INT);
      CREATE ALGORITHM = MERGE VIEW v AS SELECT f FROM ( SELECT a2.f AS f FROM t AS a1, t AS a2 ) AS sq;
      CREATE PROCEDURE sp() UPDATE v SET f = 1;
       
      --error 1288
      CALL sp;
      --error 1288
      CALL sp;
       
      # Cleanup
      DROP PROCEDURE sp;
      DROP VIEW v;
      DROP TABLE t;
      

      10.2 af9649c72

      #3  <signal handler called>
      #4  0x0000564dc40e67f1 in base_list::push_back (this=0x8f8f8f8f8f8f8f8f, info=0x7fe01803ed48, mem_root=0x7fe0342782c0) at /data/src/10.2/sql/sql_list.h:218
      #5  0x0000564dc40f5ca9 in List<Item>::push_back (this=0x8f8f8f8f8f8f8f8f, a=0x7fe01803ed48, mem_root=0x7fe0342782c0) at /data/src/10.2/sql/sql_list.h:531
      #6  0x0000564dc42ad6e7 in multi_update::prepare (this=0x7fe01803eec0, not_used_values=..., lex_unit=0x7fe01815efa0) at /data/src/10.2/sql/sql_update.cc:1769
      #7  0x0000564dc41fd1c9 in JOIN::prepare (this=0x7fe01803ef88, tables_init=0x7fe01815da10, wild_num=0, conds_init=0x0, og_num=0, order_init=0x0, skip_order_by=false, group_init=0x0, having_init=0x0, proc_param_init=0x0, select_lex_arg=0x7fe01815f6d8, unit_arg=0x7fe01815efa0) at /data/src/10.2/sql/sql_select.cc:1051
      #8  0x0000564dc42068a3 in mysql_select (thd=0x7fe018000b00, tables=0x7fe01815da10, wild_num=0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=1342177408, result=0x7fe01803eec0, unit=0x7fe01815efa0, select_lex=0x7fe01815f6d8) at /data/src/10.2/sql/sql_select.cc:3782
      #9  0x0000564dc42acc1c in mysql_multi_update (thd=0x7fe018000b00, table_list=0x7fe01815da10, fields=0x7fe01815f800, values=0x7fe01815fcd8, conds=0x0, options=0, handle_duplicates=DUP_ERROR, ignore=false, unit=0x7fe01815efa0, select_lex=0x7fe01815f6d8, result=0x7fe034277950) at /data/src/10.2/sql/sql_update.cc:1604
      #10 0x0000564dc41be8c4 in mysql_execute_command (thd=0x7fe018000b00) at /data/src/10.2/sql/sql_parse.cc:4357
      #11 0x0000564dc45b49d6 in sp_instr_stmt::exec_core (this=0x7fe01815e1f0, thd=0x7fe018000b00, nextp=0x7fe0342781a4) at /data/src/10.2/sql/sp_head.cc:3246
      #12 0x0000564dc45b4041 in sp_lex_keeper::reset_lex_and_exec_core (this=0x7fe01815e230, thd=0x7fe018000b00, nextp=0x7fe0342781a4, open_tables=false, instr=0x7fe01815e1f0) at /data/src/10.2/sql/sp_head.cc:3009
      #13 0x0000564dc45b4681 in sp_instr_stmt::execute (this=0x7fe01815e1f0, thd=0x7fe018000b00, nextp=0x7fe0342781a4) at /data/src/10.2/sql/sp_head.cc:3162
      #14 0x0000564dc45af845 in sp_head::execute (this=0x7fe01815ce38, thd=0x7fe018000b00, merge_da_on_success=true) at /data/src/10.2/sql/sp_head.cc:1327
      #15 0x0000564dc45b18d5 in sp_head::execute_procedure (this=0x7fe01815ce38, thd=0x7fe018000b00, args=0x7fe018005418) at /data/src/10.2/sql/sp_head.cc:2116
      #16 0x0000564dc41ba7db in do_execute_sp (thd=0x7fe018000b00, sp=0x7fe01815ce38) at /data/src/10.2/sql/sql_parse.cc:2912
      #17 0x0000564dc41c3bb0 in mysql_execute_command (thd=0x7fe018000b00) at /data/src/10.2/sql/sql_parse.cc:5825
      #18 0x0000564dc41ca13d in mysql_parse (thd=0x7fe018000b00, rawbuf=0x7fe018012488 "CALL sp", length=7, parser_state=0x7fe034279200, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:8011
      #19 0x0000564dc41b7a97 in dispatch_command (command=COM_QUERY, thd=0x7fe018000b00, packet=0x7fe01808cb81 "CALL sp", packet_length=7, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:1824
      #20 0x0000564dc41b63fa in do_command (thd=0x7fe018000b00) at /data/src/10.2/sql/sql_parse.cc:1378
      #21 0x0000564dc4308785 in do_handle_one_connection (connect=0x564dc81acd70) at /data/src/10.2/sql/sql_connect.cc:1335
      #22 0x0000564dc4308512 in handle_one_connection (arg=0x564dc81acd70) at /data/src/10.2/sql/sql_connect.cc:1241
      #23 0x0000564dc472b7ac in pfs_spawn_thread (arg=0x564dc81b7ac0) at /data/src/10.2/storage/perfschema/pfs.cc:1862
      #24 0x00007fe03b473494 in start_thread (arg=0x7fe03427a700) at pthread_create.c:333
      #25 0x00007fe03985993f in clone () from /lib/x86_64-linux-gnu/libc.so.6
      

      Reproducible on debug- and non-debug builds of 10.2, 10.3, 10.4 with at least MyISAM and InnoDB.
      ASAN shows a similar failure, use it in case non-ASAN build doesn't crash on whatever reason:

      10.2 ASAN af9649c722

      ==26401==ERROR: AddressSanitizer: use-after-poison on address 0x6250000d60e0 at pc 0x55fd23c2bf63 bp 0x7fccbbc2e650 sp 0x7fccbbc2e648
      READ of size 8 at 0x6250000d60e0 thread T5
          #0 0x55fd23c2bf62 in multi_update::prepare(List<Item>&, st_select_lex_unit*) /data/src/10.2/sql/sql_update.cc:1769
          #1 0x55fd23a67f50 in JOIN::prepare(TABLE_LIST*, unsigned int, Item*, unsigned int, st_order*, bool, st_order*, Item*, st_order*, st_select_lex*, st_select_lex_unit*) /data/src/10.2/sql/sql_select.cc:1051
          #2 0x55fd23a81f8b in mysql_select(THD*, 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.2/sql/sql_select.cc:3782
          #3 0x55fd23c2a34b in mysql_multi_update(THD*, TABLE_LIST*, List<Item>*, List<Item>*, Item*, unsigned long long, enum_duplicates, bool, st_select_lex_unit*, st_select_lex*, multi_update**) /data/src/10.2/sql/sql_update.cc:1604
          #4 0x55fd239d54b7 in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:4357
          #5 0x55fd24367265 in sp_instr_stmt::exec_core(THD*, unsigned int*) /data/src/10.2/sql/sp_head.cc:3246
          #6 0x55fd24365eb1 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 0x55fd24366b2f in sp_instr_stmt::execute(THD*, unsigned int*) /data/src/10.2/sql/sp_head.cc:3162
          #8 0x55fd2435c430 in sp_head::execute(THD*, bool) /data/src/10.2/sql/sp_head.cc:1327
          #9 0x55fd2436021d in sp_head::execute_procedure(THD*, List<Item>*) /data/src/10.2/sql/sp_head.cc:2116
          #10 0x55fd239cd48d in do_execute_sp /data/src/10.2/sql/sql_parse.cc:2912
          #11 0x55fd239df843 in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:5825
          #12 0x55fd239ecf01 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:8011
          #13 0x55fd239c794f in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1824
          #14 0x55fd239c49f3 in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1378
          #15 0x55fd23d0923e in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1335
          #16 0x55fd23d08c53 in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #17 0x55fd2471a5c1 in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1862
          #18 0x7fccc80b5493 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x7493)
          #19 0x7fccc649b93e in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xe893e)
       
      0x6250000d60e0 is located 6112 bytes inside of 8268-byte region [0x6250000d4900,0x6250000d694c)
      allocated by thread T5 here:
          #0 0x7fccc831f73f in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x5473f)
          #1 0x55fd2503d003 in sf_malloc /data/src/10.2/mysys/safemalloc.c:118
          #2 0x55fd2500c1c4 in my_malloc /data/src/10.2/mysys/my_malloc.c:101
          #3 0x55fd24fed067 in alloc_root /data/src/10.2/mysys/my_alloc.c:242
          #4 0x55fd239fc409 in Query_arena::memdup_w_gap(void const*, unsigned long, unsigned int) /data/src/10.2/sql/sql_class.h:987
          #5 0x55fd239cbe15 in alloc_query(THD*, char const*, unsigned int) /data/src/10.2/sql/sql_parse.cc:2647
          #6 0x55fd24366a1b in sp_instr_stmt::execute(THD*, unsigned int*) /data/src/10.2/sql/sp_head.cc:3150
          #7 0x55fd2435c430 in sp_head::execute(THD*, bool) /data/src/10.2/sql/sp_head.cc:1327
          #8 0x55fd2436021d in sp_head::execute_procedure(THD*, List<Item>*) /data/src/10.2/sql/sp_head.cc:2116
          #9 0x55fd239cd48d in do_execute_sp /data/src/10.2/sql/sql_parse.cc:2912
          #10 0x55fd239df843 in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:5825
          #11 0x55fd239ecf01 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:8011
          #12 0x55fd239c794f in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1824
          #13 0x55fd239c49f3 in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1378
          #14 0x55fd23d0923e in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1335
          #15 0x55fd23d08c53 in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #16 0x55fd2471a5c1 in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1862
          #17 0x7fccc80b5493 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x7493)
       
      Thread T5 created by T0 here:
          #0 0x7fccc82eebba in pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x23bba)
          #1 0x55fd2471ab89 in spawn_thread_v1 /data/src/10.2/storage/perfschema/pfs.cc:1912
          #2 0x55fd237c142e in inline_mysql_thread_create /data/src/10.2/include/mysql/psi/mysql_thread.h:1239
          #3 0x55fd237d6318 in create_thread_to_handle_connection(CONNECT*) /data/src/10.2/sql/mysqld.cc:6454
          #4 0x55fd237d6a1d in create_new_thread /data/src/10.2/sql/mysqld.cc:6524
          #5 0x55fd237d7a34 in handle_connections_sockets() /data/src/10.2/sql/mysqld.cc:6799
          #6 0x55fd237d586d in mysqld_main(int, char**) /data/src/10.2/sql/mysqld.cc:6073
          #7 0x55fd237bf7cf in main /data/src/10.2/sql/main.cc:25
          #8 0x7fccc63d32b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)
       
      SUMMARY: AddressSanitizer: use-after-poison /data/src/10.2/sql/sql_update.cc:1769 multi_update::prepare(List<Item>&, st_select_lex_unit*)
      Shadow bytes around the buggy address:
        0x0c4a80012bc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
        0x0c4a80012bd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
        0x0c4a80012be0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
        0x0c4a80012bf0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
        0x0c4a80012c00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      =>0x0c4a80012c10: 00 00 00 00 00 00 00 00 00 00 00 00[f7]f7 f7 f7
        0x0c4a80012c20: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c4a80012c30: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c4a80012c40: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c4a80012c50: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c4a80012c60: 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
      ==26401==ABORTING
      

        Attachments

          Activity

            People

            • Assignee:
              sanja Oleksandr Byelkin
              Reporter:
              elenst Elena Stepanova
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: