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

Server crash in base_list_iterator::next or in TABLE_LIST::is_recursive_with_table

    XMLWordPrintable

Details

    Description

      CREATE TABLE t (a INT, b INT);
      INSERT INTO t VALUES (1,1),(2,2);
      CREATE ALGORITHM=MERGE VIEW view1 AS SELECT MAX(a) as f FROM t;
      --delimiter $
      CREATE PROCEDURE sp()
      BEGIN
        SELECT * FROM view1;
        SELECT * FROM x;
      END $
      --delimiter ;
       
      --error ER_NO_SUCH_TABLE
      CALL sp;
      ALTER TABLE t DROP a;
      CALL sp;
       
      # Cleanup
      DROP PROCEDURE sp;
      DROP VIEW view1;
      DROP TABLE t;
      

      If it doesn't fail right away, please try an ASAN build.

      10.2 debug 9b30212f

      #3  <signal handler called>
      #4  base_list_iterator::next (this=0x7f6de80b8480) at /data/src/10.2/sql/sql_list.h:470
      #5  0x000055727a582787 in List_iterator<TABLE_LIST>::operator++ (this=0x7f6de80b8480) at /data/src/10.2/sql/sql_list.h:580
      #6  0x000055727a6d35f9 in st_select_lex::cleanup (this=0x7f6dcc18e2a8) at /data/src/10.2/sql/sql_union.cc:1553
      #7  0x000055727a62c87d in mysql_select (thd=0x7f6dcc000d90, tables=0x7f6dcc0966a8, wild_num=0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147749632, result=0x7f6dcc082fc8, unit=0x7f6dcc18db68, select_lex=0x7f6dcc18e2a8) at /data/src/10.2/sql/sql_select.cc:3848
      #8  0x000055727a62096a in handle_select (thd=0x7f6dcc000d90, lex=0x7f6dcc18daa8, result=0x7f6dcc082fc8, setup_tables_done_option=0) at /data/src/10.2/sql/sql_select.cc:361
      #9  0x000055727a5eb2d1 in execute_sqlcom_select (thd=0x7f6dcc000d90, all_tables=0x7f6dcc0966a8) at /data/src/10.2/sql/sql_parse.cc:6249
      #10 0x000055727a5e1c20 in mysql_execute_command (thd=0x7f6dcc000d90) at /data/src/10.2/sql/sql_parse.cc:3558
      #11 0x000055727a533812 in sp_instr_stmt::exec_core (this=0x7f6dcc096cd0, thd=0x7f6dcc000d90, nextp=0x7f6de80b95dc) at /data/src/10.2/sql/sp_head.cc:3332
      #12 0x000055727a532e67 in sp_lex_keeper::reset_lex_and_exec_core (this=0x7f6dcc096d10, thd=0x7f6dcc000d90, nextp=0x7f6de80b95dc, open_tables=false, instr=0x7f6dcc096cd0) at /data/src/10.2/sql/sp_head.cc:3095
      #13 0x000055727a5334b7 in sp_instr_stmt::execute (this=0x7f6dcc096cd0, thd=0x7f6dcc000d90, nextp=0x7f6de80b95dc) at /data/src/10.2/sql/sp_head.cc:3248
      #14 0x000055727a52e473 in sp_head::execute (this=0x7f6dcc0957d8, thd=0x7f6dcc000d90, merge_da_on_success=true) at /data/src/10.2/sql/sp_head.cc:1326
      #15 0x000055727a53069d in sp_head::execute_procedure (this=0x7f6dcc0957d8, thd=0x7f6dcc000d90, args=0x7f6dcc0056d0) at /data/src/10.2/sql/sp_head.cc:2202
      #16 0x000055727a5e0224 in do_execute_sp (thd=0x7f6dcc000d90, sp=0x7f6dcc0957d8) at /data/src/10.2/sql/sql_parse.cc:2980
      #17 0x000055727a5e89c3 in mysql_execute_command (thd=0x7f6dcc000d90) at /data/src/10.2/sql/sql_parse.cc:5598
      #18 0x000055727a5ef05f in mysql_parse (thd=0x7f6dcc000d90, rawbuf=0x7f6dcc0126f8 "CALL sp", length=7, parser_state=0x7f6de80ba5f0, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:7761
      #19 0x000055727a5dd2f4 in dispatch_command (command=COM_QUERY, thd=0x7f6dcc000d90, packet=0x7f6dcc008b51 "CALL sp", packet_length=7, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:1827
      #20 0x000055727a5dbdef in do_command (thd=0x7f6dcc000d90) at /data/src/10.2/sql/sql_parse.cc:1381
      #21 0x000055727a736103 in do_handle_one_connection (connect=0x55727c8c0980) at /data/src/10.2/sql/sql_connect.cc:1336
      #22 0x000055727a735e68 in handle_one_connection (arg=0x55727c8c0980) at /data/src/10.2/sql/sql_connect.cc:1241
      #23 0x000055727af5d870 in pfs_spawn_thread (arg=0x55727c8a3d40) at /data/src/10.2/storage/perfschema/pfs.cc:1869
      #24 0x00007f6ded4ca609 in start_thread (arg=<optimized out>) at pthread_create.c:477
      #25 0x00007f6ded0a6293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
      

      10.2 ASAN 9b30212f

      ==2774987==ERROR: AddressSanitizer: heap-use-after-free on address 0x62500002e1a0 at pc 0x55dd0191f808 bp 0x7f30c45d7490 sp 0x7f30c45d7480
      READ of size 8 at 0x62500002e1a0 thread T5
          #0 0x55dd0191f807 in base_list_iterator::next() /data/src/10.2/sql/sql_list.h:470
          #1 0x55dd019d3ad0 in List_iterator<TABLE_LIST>::operator++(int) /data/src/10.2/sql/sql_list.h:580
          #2 0x55dd01d4578d in st_select_lex::cleanup() /data/src/10.2/sql/sql_union.cc:1553
          #3 0x55dd01b87d0c 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:3848
          #4 0x55dd01b645fb in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.2/sql/sql_select.cc:361
          #5 0x55dd01adb9e4 in execute_sqlcom_select /data/src/10.2/sql/sql_parse.cc:6249
          #6 0x55dd01ac8929 in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:3558
          #7 0x55dd019176bd in sp_instr_stmt::exec_core(THD*, unsigned int*) /data/src/10.2/sql/sp_head.cc:3332
          #8 0x55dd019161de in sp_lex_keeper::reset_lex_and_exec_core(THD*, unsigned int*, bool, sp_instr*) /data/src/10.2/sql/sp_head.cc:3095
          #9 0x55dd01916f31 in sp_instr_stmt::execute(THD*, unsigned int*) /data/src/10.2/sql/sp_head.cc:3248
          #10 0x55dd0190b279 in sp_head::execute(THD*, bool) /data/src/10.2/sql/sp_head.cc:1326
          #11 0x55dd0190fa50 in sp_head::execute_procedure(THD*, List<Item>*) /data/src/10.2/sql/sp_head.cc:2202
          #12 0x55dd01ac48e6 in do_execute_sp /data/src/10.2/sql/sql_parse.cc:2980
          #13 0x55dd01ad6a3a in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:5598
          #14 0x55dd01ae4f19 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:7761
          #15 0x55dd01abe01c in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1827
          #16 0x55dd01abaddb in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1381
          #17 0x55dd01e42345 in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1336
          #18 0x55dd01e41c08 in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #19 0x55dd031dc853 in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1869
          #20 0x7f30cf32c608 in start_thread /build/glibc-ZN95T4/glibc-2.31/nptl/pthread_create.c:477
          #21 0x7f30cef06292 in __clone (/lib/x86_64-linux-gnu/libc.so.6+0x122292)
       
      0x62500002e1a0 is located 4256 bytes inside of 8268-byte region [0x62500002d100,0x62500002f14c)
      freed by thread T5 here:
          #0 0x7f30cf8937cf in __interceptor_free (/lib/x86_64-linux-gnu/libasan.so.5+0x10d7cf)
          #1 0x55dd032fa64a in free_memory /data/src/10.2/mysys/safemalloc.c:279
          #2 0x55dd032f9b96 in sf_free /data/src/10.2/mysys/safemalloc.c:197
          #3 0x55dd032c5ede in my_free /data/src/10.2/mysys/my_malloc.c:218
          #4 0x55dd032a3ca7 in free_root /data/src/10.2/mysys/my_alloc.c:395
          #5 0x55dd0190b6e0 in sp_head::execute(THD*, bool) /data/src/10.2/sql/sp_head.cc:1431
          #6 0x55dd0190fa50 in sp_head::execute_procedure(THD*, List<Item>*) /data/src/10.2/sql/sp_head.cc:2202
          #7 0x55dd01ac48e6 in do_execute_sp /data/src/10.2/sql/sql_parse.cc:2980
          #8 0x55dd01ad6a3a in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:5598
          #9 0x55dd01ae4f19 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:7761
          #10 0x55dd01abe01c in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1827
          #11 0x55dd01abaddb in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1381
          #12 0x55dd01e42345 in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1336
          #13 0x55dd01e41c08 in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #14 0x55dd031dc853 in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1869
          #15 0x7f30cf32c608 in start_thread /build/glibc-ZN95T4/glibc-2.31/nptl/pthread_create.c:477
       
      previously allocated by thread T5 here:
          #0 0x7f30cf893bc8 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
          #1 0x55dd032f9508 in sf_malloc /data/src/10.2/mysys/safemalloc.c:118
          #2 0x55dd032c546d in my_malloc /data/src/10.2/mysys/my_malloc.c:101
          #3 0x55dd032a2adf in alloc_root /data/src/10.2/mysys/my_alloc.c:243
          #4 0x55dd01af5848 in Query_arena::memdup_w_gap(void const*, unsigned long, unsigned int) /data/src/10.2/sql/sql_class.h:998
          #5 0x55dd01ac2dd3 in alloc_query(THD*, char const*, unsigned int) /data/src/10.2/sql/sql_parse.cc:2686
          #6 0x55dd01916e1d in sp_instr_stmt::execute(THD*, unsigned int*) /data/src/10.2/sql/sp_head.cc:3236
          #7 0x55dd0190b279 in sp_head::execute(THD*, bool) /data/src/10.2/sql/sp_head.cc:1326
          #8 0x55dd0190fa50 in sp_head::execute_procedure(THD*, List<Item>*) /data/src/10.2/sql/sp_head.cc:2202
          #9 0x55dd01ac48e6 in do_execute_sp /data/src/10.2/sql/sql_parse.cc:2980
          #10 0x55dd01ad6a3a in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:5598
          #11 0x55dd01ae4f19 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:7761
          #12 0x55dd01abe01c in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1827
          #13 0x55dd01abaddb in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1381
          #14 0x55dd01e42345 in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1336
          #15 0x55dd01e41c08 in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #16 0x55dd031dc853 in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1869
          #17 0x7f30cf32c608 in start_thread /build/glibc-ZN95T4/glibc-2.31/nptl/pthread_create.c:477
       
      Thread T5 created by T0 here:
          #0 0x7f30cf7c0805 in pthread_create (/lib/x86_64-linux-gnu/libasan.so.5+0x3a805)
          #1 0x55dd031dcc44 in spawn_thread_v1 /data/src/10.2/storage/perfschema/pfs.cc:1919
          #2 0x55dd01860083 in inline_mysql_thread_create /data/src/10.2/include/mysql/psi/mysql_thread.h:1246
          #3 0x55dd01877c2b in create_thread_to_handle_connection(CONNECT*) /data/src/10.2/sql/mysqld.cc:6567
          #4 0x55dd018783c6 in create_new_thread /data/src/10.2/sql/mysqld.cc:6637
          #5 0x55dd01879558 in handle_connections_sockets() /data/src/10.2/sql/mysqld.cc:6895
          #6 0x55dd01876f7c in mysqld_main(int, char**) /data/src/10.2/sql/mysqld.cc:6186
          #7 0x55dd0185e93c in main /data/src/10.2/sql/main.cc:25
          #8 0x7f30cee0b0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
       
      SUMMARY: AddressSanitizer: heap-use-after-free /data/src/10.2/sql/sql_list.h:470 in base_list_iterator::next()
      Shadow bytes around the buggy address:
        0x0c4a7fffdbe0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a7fffdbf0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a7fffdc00: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a7fffdc10: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a7fffdc20: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      =>0x0c4a7fffdc30: fd fd fd fd[fd]fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a7fffdc40: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a7fffdc50: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a7fffdc60: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a7fffdc70: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a7fffdc80: 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
        Freed heap region:       fd
        Stack left redzone:      f1
        Stack mid redzone:       f2
        Stack right redzone:     f3
        Stack after return:      f5
        Stack use after scope:   f8
        Global redzone:          f9
        Global init order:       f6
        Poisoned by user:        f7
        Container overflow:      fc
        Array cookie:            ac
        Intra object redzone:    bb
        ASan internal:           fe
        Left alloca redzone:     ca
        Right alloca redzone:    cb
        Shadow gap:              cc
      ==2774987==ABORTING
      

      10.4 debug 1bebc8de

      #3  <signal handler called>
      #4  0x00005651d3c09f4c in TABLE_LIST::is_recursive_with_table (this=0xa5a5a5a5a5a5a5a5) at /data/src/10.4/sql/sql_cte.cc:1146
      #5  0x00005651d3acc28c in st_select_lex::cleanup (this=0x7f3e0007a3c0) at /data/src/10.4/sql/sql_union.cc:2089
      #6  0x00005651d3a0fe4d in mysql_select (thd=0x7f3e00000d90, tables=0x7f3e0007a990, wild_num=0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147749632, result=0x7f3e00075210, unit=0x7f3e0007bb58, select_lex=0x7f3e0007a3c0) at /data/src/10.4/sql/sql_select.cc:4718
      #7  0x00005651d39ff759 in handle_select (thd=0x7f3e00000d90, lex=0x7f3e0007ba98, result=0x7f3e00075210, setup_tables_done_option=0) at /data/src/10.4/sql/sql_select.cc:410
      #8  0x00005651d39c488c in execute_sqlcom_select (thd=0x7f3e00000d90, all_tables=0x7f3e0007a990) at /data/src/10.4/sql/sql_parse.cc:6400
      #9  0x00005651d39badf9 in mysql_execute_command (thd=0x7f3e00000d90) at /data/src/10.4/sql/sql_parse.cc:3925
      #10 0x00005651d38c774a in sp_instr_stmt::exec_core (this=0x7f3e0007b080, thd=0x7f3e00000d90, nextp=0x7f3e110fa07c) at /data/src/10.4/sql/sp_head.cc:3687
      #11 0x00005651d38c6ad3 in sp_lex_keeper::reset_lex_and_exec_core (this=0x7f3e0007b0c8, thd=0x7f3e00000d90, nextp=0x7f3e110fa07c, open_tables=false, instr=0x7f3e0007b080) at /data/src/10.4/sql/sp_head.cc:3419
      #12 0x00005651d38c72f2 in sp_instr_stmt::execute (this=0x7f3e0007b080, thd=0x7f3e00000d90, nextp=0x7f3e110fa07c) at /data/src/10.4/sql/sp_head.cc:3593
      #13 0x00005651d38c09ce in sp_head::execute (this=0x7f3e00079578, thd=0x7f3e00000d90, merge_da_on_success=true) at /data/src/10.4/sql/sp_head.cc:1364
      #14 0x00005651d38c3786 in sp_head::execute_procedure (this=0x7f3e00079578, thd=0x7f3e00000d90, args=0x7f3e00005b88) at /data/src/10.4/sql/sp_head.cc:2370
      #15 0x00005651d39b8273 in do_execute_sp (thd=0x7f3e00000d90, sp=0x7f3e00079578) at /data/src/10.4/sql/sql_parse.cc:3040
      #16 0x00005651d39b8f2b in Sql_cmd_call::execute (this=0x7f3e00013500, thd=0x7f3e00000d90) at /data/src/10.4/sql/sql_parse.cc:3282
      #17 0x00005651d39c32eb in mysql_execute_command (thd=0x7f3e00000d90) at /data/src/10.4/sql/sql_parse.cc:6143
      #18 0x00005651d39c8897 in mysql_parse (thd=0x7f3e00000d90, rawbuf=0x7f3e00013458 "CALL sp", length=7, parser_state=0x7f3e110fb550, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:7938
      #19 0x00005651d39b4b9d in dispatch_command (command=COM_QUERY, thd=0x7f3e00000d90, packet=0x7f3e000087b1 "CALL sp", packet_length=7, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:1839
      #20 0x00005651d39b3405 in do_command (thd=0x7f3e00000d90) at /data/src/10.4/sql/sql_parse.cc:1357
      #21 0x00005651d3b42289 in do_handle_one_connection (connect=0x5651d71090b0) at /data/src/10.4/sql/sql_connect.cc:1412
      #22 0x00005651d3b41fd2 in handle_one_connection (arg=0x5651d71090b0) at /data/src/10.4/sql/sql_connect.cc:1316
      #23 0x00005651d4560f46 in pfs_spawn_thread (arg=0x5651d70568e0) at /data/src/10.4/storage/perfschema/pfs.cc:1869
      #24 0x00007f3e179ac609 in start_thread (arg=<optimized out>) at pthread_create.c:477
      #25 0x00007f3e17217293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
      

      Reproducible with at least MyISAM and InnoDB.
      The failure appeared in 10.2 branch after this commit:

      commit 190e8a4c2aeb417b405756b193e135c542d46b34
      Author: Igor Babaev
      Date:   Tue Nov 10 16:02:30 2020 -0800
       
          MDEV-23619 MariaDB crash on WITH RECURSIVE UNION ALL (CTE) query
      

      Non-debug build doesn't crash on my machine, but non-debug ASAN build still produces heap-use-after-free.

      Attachments

        Activity

          People

            igor Igor Babaev
            elenst Elena Stepanova
            Votes:
            0 Vote for this issue
            Watchers:
            3 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.