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

ASAN heap-use-after-free in Item_default_value::walk upon 2nd execution of SP

    XMLWordPrintable

Details

    Description

      CREATE TABLE t (f INT);
      INSERT INTO t VALUES (1),(2); # Optional, fails either way
      CREATE VIEW v AS SELECT * FROM t;
      CREATE PROCEDURE sp() UPDATE v SET f = DEFAULT;
      CALL sp;
      CALL sp;
       
      # Cleanup
      DROP PROCEDURE sp;
      DROP VIEW v;
      DROP TABLE t;
      

      10.2 600e4949 ASAN

      ==2716803==ERROR: AddressSanitizer: heap-use-after-free on address 0x62500007d420 at pc 0x5648d5a069db bp 0x7f580e4b55e0 sp 0x7f580e4b55d0
      READ of size 8 at 0x62500007d420 thread T5
          #0 0x5648d5a069da in Item_default_value::walk(bool (Item::*)(void*), bool, void*) /data/src/10.2/sql/item.h:5504
          #1 0x5648d5380afe in setup_defaults(THD*, List<Item>&, List<Item>&) /data/src/10.2/sql/sql_base.cc:7204
          #2 0x5648d5713f29 in mysql_update(THD*, TABLE_LIST*, List<Item>&, List<Item>&, Item*, unsigned int, st_order*, unsigned long long, enum_duplicates, bool, unsigned long long*, unsigned long long*) /data/src/10.2/sql/sql_update.cc:373
          #3 0x5648d5492491 in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:4056
          #4 0x5648d52dc5f7 in sp_instr_stmt::exec_core(THD*, unsigned int*) /data/src/10.2/sql/sp_head.cc:3331
          #5 0x5648d52db125 in sp_lex_keeper::reset_lex_and_exec_core(THD*, unsigned int*, bool, sp_instr*) /data/src/10.2/sql/sp_head.cc:3094
          #6 0x5648d52dbe6b in sp_instr_stmt::execute(THD*, unsigned int*) /data/src/10.2/sql/sp_head.cc:3247
          #7 0x5648d52d0263 in sp_head::execute(THD*, bool) /data/src/10.2/sql/sp_head.cc:1326
          #8 0x5648d52d4a2e in sp_head::execute_procedure(THD*, List<Item>*) /data/src/10.2/sql/sp_head.cc:2202
          #9 0x5648d548b710 in do_execute_sp /data/src/10.2/sql/sql_parse.cc:2981
          #10 0x5648d549d92d in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:5622
          #11 0x5648d54abb65 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:7793
          #12 0x5648d5484d6a in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1827
          #13 0x5648d5481b35 in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1381
          #14 0x5648d580d06b in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1336
          #15 0x5648d580c92e in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #16 0x5648d6babccf in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1869
          #17 0x7f5819356608 in start_thread /build/glibc-eX1tMB/glibc-2.31/nptl/pthread_create.c:477
          #18 0x7f5818f31292 in __clone (/lib/x86_64-linux-gnu/libc.so.6+0x122292)
       
      0x62500007d420 is located 800 bytes inside of 8268-byte region [0x62500007d100,0x62500007f14c)
      freed by thread T5 here:
          #0 0x7f58199d07cf in __interceptor_free (/lib/x86_64-linux-gnu/libasan.so.5+0x10d7cf)
          #1 0x5648d6ccacfc in free_memory /data/src/10.2/mysys/safemalloc.c:279
          #2 0x5648d6cca248 in sf_free /data/src/10.2/mysys/safemalloc.c:197
          #3 0x5648d6c965b4 in my_free /data/src/10.2/mysys/my_malloc.c:218
          #4 0x5648d6c74418 in free_root /data/src/10.2/mysys/my_alloc.c:401
          #5 0x5648d52d06ca in sp_head::execute(THD*, bool) /data/src/10.2/sql/sp_head.cc:1431
          #6 0x5648d52d4a2e in sp_head::execute_procedure(THD*, List<Item>*) /data/src/10.2/sql/sp_head.cc:2202
          #7 0x5648d548b710 in do_execute_sp /data/src/10.2/sql/sql_parse.cc:2981
          #8 0x5648d549d92d in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:5622
          #9 0x5648d54abb65 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:7793
          #10 0x5648d5484d6a in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1827
          #11 0x5648d5481b35 in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1381
          #12 0x5648d580d06b in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1336
          #13 0x5648d580c92e in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #14 0x5648d6babccf in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1869
          #15 0x7f5819356608 in start_thread /build/glibc-eX1tMB/glibc-2.31/nptl/pthread_create.c:477
       
      previously allocated by thread T5 here:
          #0 0x7f58199d0bc8 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
          #1 0x5648d6cc9bba in sf_malloc /data/src/10.2/mysys/safemalloc.c:118
          #2 0x5648d6c95b43 in my_malloc /data/src/10.2/mysys/my_malloc.c:101
          #3 0x5648d6c731b5 in alloc_root /data/src/10.2/mysys/my_alloc.c:243
          #4 0x5648d54bc3b0 in Query_arena::memdup_w_gap(void const*, unsigned long, unsigned int) /data/src/10.2/sql/sql_class.h:1012
          #5 0x5648d5489c03 in alloc_query(THD*, char const*, unsigned int) /data/src/10.2/sql/sql_parse.cc:2687
          #6 0x5648d52dbd57 in sp_instr_stmt::execute(THD*, unsigned int*) /data/src/10.2/sql/sp_head.cc:3235
          #7 0x5648d52d0263 in sp_head::execute(THD*, bool) /data/src/10.2/sql/sp_head.cc:1326
          #8 0x5648d52d4a2e in sp_head::execute_procedure(THD*, List<Item>*) /data/src/10.2/sql/sp_head.cc:2202
          #9 0x5648d548b710 in do_execute_sp /data/src/10.2/sql/sql_parse.cc:2981
          #10 0x5648d549d92d in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:5622
          #11 0x5648d54abb65 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:7793
          #12 0x5648d5484d6a in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1827
          #13 0x5648d5481b35 in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1381
          #14 0x5648d580d06b in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1336
          #15 0x5648d580c92e in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #16 0x5648d6babccf in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1869
          #17 0x7f5819356608 in start_thread /build/glibc-eX1tMB/glibc-2.31/nptl/pthread_create.c:477
       
      Thread T5 created by T0 here:
          #0 0x7f58198fd805 in pthread_create (/lib/x86_64-linux-gnu/libasan.so.5+0x3a805)
          #1 0x5648d6bac0c0 in spawn_thread_v1 /data/src/10.2/storage/perfschema/pfs.cc:1919
          #2 0x5648d52252a3 in inline_mysql_thread_create /data/src/10.2/include/mysql/psi/mysql_thread.h:1246
          #3 0x5648d523d1fa in create_thread_to_handle_connection(CONNECT*) /data/src/10.2/sql/mysqld.cc:6573
          #4 0x5648d523d995 in create_new_thread /data/src/10.2/sql/mysqld.cc:6643
          #5 0x5648d523eb38 in handle_connections_sockets() /data/src/10.2/sql/mysqld.cc:6901
          #6 0x5648d523c54b in mysqld_main(int, char**) /data/src/10.2/sql/mysqld.cc:6192
          #7 0x5648d5223b5c in main /data/src/10.2/sql/main.cc:25
          #8 0x7f5818e360b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
       
      SUMMARY: AddressSanitizer: heap-use-after-free /data/src/10.2/sql/item.h:5504 in Item_default_value::walk(bool (Item::*)(void*), bool, void*)
      Shadow bytes around the buggy address:
        0x0c4a80007a30: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a80007a40: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a80007a50: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a80007a60: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a80007a70: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
      =>0x0c4a80007a80: fd fd fd fd[fd]fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a80007a90: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a80007aa0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a80007ab0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a80007ac0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c4a80007ad0: 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
      ==2716803==ABORTING
      210830 19:33:03 [ERROR] mysqld got signal 6 ;
      This could be because you hit a bug. It is also possible that this binary
      or one of the libraries it was linked against is corrupt, improperly built,
      or misconfigured. This error can also be caused by malfunctioning hardware.
       
      To report this bug, see https://mariadb.com/kb/en/reporting-bugs
       
      We will try our best to scrape up some info that will hopefully help
      diagnose the problem, but since we have already crashed, 
      something is definitely wrong and this may fail.
       
      Server version: 10.2.41-MariaDB-debug-log
      key_buffer_size=1048576
      read_buffer_size=131072
      max_used_connections=1
      max_threads=153
      thread_count=1
      It is possible that mysqld could use up to 
      key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 63106 K  bytes of memory
      Hope that's ok; if not, decrease some variables in the equation.
       
      Thread pointer: 0x62a000060270
      Attempting backtrace. You can use the following information to find out
      where mysqld died. If you see no messages after this, something went
      terribly wrong...
      stack_bottom = 0x7f580e4b9d10 thread_stack 0x5b000
      /lib/x86_64-linux-gnu/libasan.so.5(+0x6cd30)[0x7f581992fd30]
      mysys/stacktrace.c:172(my_print_stacktrace)[0x5648d6ca7571]
      sql/signal_handler.cc:221(handle_fatal_signal)[0x5648d5acdbfd]
      sigaction.c:0(__restore_rt)[0x7f58193623c0]
      /lib/x86_64-linux-gnu/libc.so.6(gsignal+0xcb)[0x7f5818e5518b]
      /lib/x86_64-linux-gnu/libc.so.6(abort+0x12b)[0x7f5818e34859]
      /lib/x86_64-linux-gnu/libasan.so.5(+0x12b6a2)[0x7f58199ee6a2]
      /lib/x86_64-linux-gnu/libasan.so.5(+0x13624c)[0x7f58199f924c]
      /lib/x86_64-linux-gnu/libasan.so.5(+0x1178ec)[0x7f58199da8ec]
      /lib/x86_64-linux-gnu/libasan.so.5(+0x117363)[0x7f58199da363]
      /lib/x86_64-linux-gnu/libasan.so.5(__asan_report_load8+0x3b)[0x7f58199db1ab]
      sql/item.h:5504(Item_default_value::walk(bool (Item::*)(void*), bool, void*))[0x5648d5a069db]
      sql/sql_base.cc:7202(setup_defaults(THD*, List<Item>&, List<Item>&))[0x5648d5380aff]
      sql/sql_update.cc:378(mysql_update(THD*, TABLE_LIST*, List<Item>&, List<Item>&, Item*, unsigned int, st_order*, unsigned long long, enum_duplicates, bool, unsigned long long*, unsigned long long*))[0x5648d5713f2a]
      sql/sql_parse.cc:4056(mysql_execute_command(THD*))[0x5648d5492492]
      sql/sp_head.cc:3331(sp_instr_stmt::exec_core(THD*, unsigned int*))[0x5648d52dc5f8]
      sql/sp_head.cc:3094(sp_lex_keeper::reset_lex_and_exec_core(THD*, unsigned int*, bool, sp_instr*))[0x5648d52db126]
      sql/sp_head.cc:3247(sp_instr_stmt::execute(THD*, unsigned int*))[0x5648d52dbe6c]
      sql/sp_head.cc:1326(sp_head::execute(THD*, bool))[0x5648d52d0264]
      sql/sp_head.cc:2202(sp_head::execute_procedure(THD*, List<Item>*))[0x5648d52d4a2f]
      sql/sql_parse.cc:2981(do_execute_sp(THD*, sp_head*))[0x5648d548b711]
      sql/sql_parse.cc:5622(mysql_execute_command(THD*))[0x5648d549d92e]
      sql/sql_parse.cc:7793(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x5648d54abb66]
      sql/sql_parse.cc:1830(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool))[0x5648d5484d6b]
      sql/sql_parse.cc:1381(do_command(THD*))[0x5648d5481b36]
      sql/sql_connect.cc:1336(do_handle_one_connection(CONNECT*))[0x5648d580d06c]
      sql/sql_connect.cc:1242(handle_one_connection)[0x5648d580c92f]
      perfschema/pfs.cc:1871(pfs_spawn_thread)[0x5648d6babcd0]
      nptl/pthread_create.c:478(start_thread)[0x7f5819356609]
      /lib/x86_64-linux-gnu/libc.so.6(clone+0x43)[0x7f5818f31293]
       
      Trying to get some variables.
      Some pointers may be invalid and cause the dump to abort.
      Query (0x62500002d190): UPDATE v SET f = DEFAULT
       
      Connection ID (thread ID): 4
      Status: NOT_KILLED
       
      Optimizer switch: index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on
       
      The manual page at https://mariadb.com/kb/en/how-to-produce-a-full-stack-trace-for-mysqld/ contains
      information that should help you find out what is causing the crash.
      Writing a core file...
      Working directory at /dev/shm/var_auto_NR4S/mysqld.1/data
      Resource Limits:
      Limit                     Soft Limit           Hard Limit           Units     
      Max cpu time              unlimited            unlimited            seconds   
      Max file size             unlimited            unlimited            bytes     
      Max data size             unlimited            unlimited            bytes     
      Max stack size            8388608              unlimited            bytes     
      Max core file size        unlimited            unlimited            bytes     
      Max resident set          unlimited            unlimited            bytes     
      Max processes             385737               385737               processes 
      Max open files            1024                 1024                 files     
      Max locked memory         67108864             67108864             bytes     
      Max address space         unlimited            unlimited            bytes     
      Max file locks            unlimited            unlimited            locks     
      Max pending signals       385737               385737               signals   
      Max msgqueue size         819200               819200               bytes     
      Max nice priority         0                    0                    
      Max realtime priority     0                    0                    
      Max realtime timeout      unlimited            unlimited            us        
      Core pattern: |/usr/share/apport/apport %p %s %c %d %P %E
      

      The failure started happening on 10.2 branch after this commit:

      commit c47e4aab62c65e1a1d431f9888ba1bc6b9841687
      Author: Nikita Malyavin <nikitamalyavin@gmail.com>
      Date:   Sat Jun 26 20:11:56 2021 +0300
       
          MDEV-23597 Assertion `marked_for_read()' failed while evaluating DEFAULT
          
          The columns that are part of DEFAULT expression were not read-marked
      

      It doesn't appear to be reproducible on 10.3+, but it needs to be made sure of.

      Attachments

        Activity

          People

            nikitamalyavin Nikita Malyavin
            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.