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

ASAN heap-use-after-free in String::copy / get_field_default_value

    XMLWordPrintable

Details

    Description

      The failure started happening after the same commit as MDEV-28393, but the tentative patch from MDEV-28393 doesn't fix it.

      CREATE TABLE t (a BLOB DEFAULT 'x');
      CREATE VIEW v AS SELECT * FROM t;
      INSERT INTO t () VALUES ();
      UPDATE t SET a = DEFAULT;
      SELECT * FROM information_schema.columns WHERE table_name = 'v';
       
      # Cleanup
      DROP VIEW v;
      DROP TABLE t;
      

      10.2 a7923b37

      ==3075970==ERROR: AddressSanitizer: heap-use-after-free on address 0x602000004398 at pc 0x7f8a43182983 bp 0x7f8a3806c170 sp 0x7f8a3806b920
      READ of size 1 at 0x602000004398 thread T5
          #0 0x7f8a43182982 in __interceptor_memcpy ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:806
          #1 0x55a15aec676a in String::copy(char const*, unsigned long, charset_info_st const*) /data/src/10.2/sql/sql_string.cc:200
          #2 0x55a15aec7179 in String::copy(char const*, unsigned int, charset_info_st const*, charset_info_st const*, unsigned int*) /data/src/10.2/sql/sql_string.cc:387
          #3 0x55a15ae5dc2c in get_field_default_value /data/src/10.2/sql/sql_show.cc:1823
          #4 0x55a15ae7f57f in get_schema_column_record /data/src/10.2/sql/sql_show.cc:5740
          #5 0x55a15ae60b9a in fill_schema_table_by_open /data/src/10.2/sql/sql_show.cc:4475
          #6 0x55a15ae9a429 in get_all_tables(THD*, TABLE_LIST*, Item*) /data/src/10.2/sql/sql_show.cc:5101
          #7 0x55a15aea14f3 in get_schema_tables_result(JOIN*, enum_schema_table_state) /data/src/10.2/sql/sql_show.cc:8573
          #8 0x55a15ae499a4 in JOIN::exec_inner() /data/src/10.2/sql/sql_select.cc:3615
          #9 0x55a15ae4bc79 in JOIN::exec() /data/src/10.2/sql/sql_select.cc:3446
          #10 0x55a15ae4c073 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:3849
          #11 0x55a15ae4ea7a in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.2/sql/sql_select.cc:361
          #12 0x55a15acf49a7 in execute_sqlcom_select /data/src/10.2/sql/sql_parse.cc:6271
          #13 0x55a15ad1aee1 in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:3582
          #14 0x55a15ad23747 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:7793
          #15 0x55a15ad29b8e in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1827
          #16 0x55a15ad2da2d in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1381
          #17 0x55a15b0109f6 in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1336
          #18 0x55a15b01112a in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #19 0x55a15c1a2324 in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1869
          #20 0x7f8a42c7bea6 in start_thread nptl/pthread_create.c:477
          #21 0x7f8a42880dee in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xfddee)
       
      0x602000004398 is located 8 bytes inside of 16-byte region [0x602000004390,0x6020000043a0)
      freed by thread T5 here:
          #0 0x7f8a431f2b6f in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:123
          #1 0x55a15b2689d5 in String::free() /data/src/10.2/sql/sql_string.h:351
          #2 0x55a15b2689d5 in String::~String() /data/src/10.2/sql/sql_string.h:187
          #3 0x55a15b2689d5 in Field_blob::~Field_blob() /data/src/10.2/sql/field.h:3308
          #4 0x55a15b2689d5 in Field_blob::~Field_blob() /data/src/10.2/sql/field.h:3308
          #5 0x55a15b2b67fa in Item_default_value::cleanup() /data/src/10.2/sql/item.cc:9064
          #6 0x55a15ac5bf33 in Item::delete_self() /data/src/10.2/sql/item.h:1964
          #7 0x55a15ac5bf33 in Query_arena::free_items() /data/src/10.2/sql/sql_class.cc:3642
          #8 0x55a15ac63532 in THD::cleanup_after_query() /data/src/10.2/sql/sql_class.cc:2097
          #9 0x55a15ad2337e in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:7815
          #10 0x55a15ad29b8e in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1827
          #11 0x55a15ad2da2d in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1381
          #12 0x55a15b0109f6 in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1336
          #13 0x55a15b01112a in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #14 0x55a15c1a2324 in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1869
          #15 0x7f8a42c7bea6 in start_thread nptl/pthread_create.c:477
       
      previously allocated by thread T5 here:
          #0 0x7f8a431f2e8f in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
          #1 0x55a15c25a9a2 in my_malloc /data/src/10.2/mysys/my_malloc.c:101
          #2 0x55a15aec5e23 in String::real_alloc(unsigned long) /data/src/10.2/sql/sql_string.cc:45
          #3 0x55a15b25d98c in String::alloc(unsigned long) /data/src/10.2/sql/sql_string.h:361
          #4 0x55a15b25d98c in Field_blob::store(char const*, unsigned int, charset_info_st const*) /data/src/10.2/sql/field.cc:8305
          #5 0x55a15b2239b3 in Field::set_default() /data/src/10.2/sql/field.cc:2457
          #6 0x55a15b2f8c72 in Item_default_value::save_in_field(Field*, bool) /data/src/10.2/sql/item.cc:9133
          #7 0x55a15ac2c516 in fill_record(THD*, TABLE*, List<Item>&, List<Item>&, bool, bool) /data/src/10.2/sql/sql_base.cc:8118
          #8 0x55a15ac2d2b9 in fill_record_n_invoke_before_triggers(THD*, TABLE*, List<Item>&, List<Item>&, bool, trg_event_type) /data/src/10.2/sql/sql_base.cc:8263
          #9 0x55a15af4f7ed 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:766
          #10 0x55a15ad15ddd in mysql_execute_command(THD*) /data/src/10.2/sql/sql_parse.cc:4056
          #11 0x55a15ad23747 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.2/sql/sql_parse.cc:7793
          #12 0x55a15ad29b8e in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.2/sql/sql_parse.cc:1827
          #13 0x55a15ad2da2d in do_command(THD*) /data/src/10.2/sql/sql_parse.cc:1381
          #14 0x55a15b0109f6 in do_handle_one_connection(CONNECT*) /data/src/10.2/sql/sql_connect.cc:1336
          #15 0x55a15b01112a in handle_one_connection /data/src/10.2/sql/sql_connect.cc:1241
          #16 0x55a15c1a2324 in pfs_spawn_thread /data/src/10.2/storage/perfschema/pfs.cc:1869
          #17 0x7f8a42c7bea6 in start_thread nptl/pthread_create.c:477
       
      Thread T5 created by T0 here:
          #0 0x7f8a4319e2a2 in __interceptor_pthread_create ../../../../src/libsanitizer/asan/asan_interceptors.cpp:214
          #1 0x55a15c1a75aa in spawn_thread_v1 /data/src/10.2/storage/perfschema/pfs.cc:1919
          #2 0x55a15ab1eecf in inline_mysql_thread_create /data/src/10.2/include/mysql/psi/mysql_thread.h:1246
          #3 0x55a15ab1eecf in create_thread_to_handle_connection(CONNECT*) /data/src/10.2/sql/mysqld.cc:6580
          #4 0x55a15ab2f26c in create_new_thread /data/src/10.2/sql/mysqld.cc:6650
          #5 0x55a15ab2f26c in handle_connections_sockets() /data/src/10.2/sql/mysqld.cc:6908
          #6 0x55a15ab3179f in mysqld_main(int, char**) /data/src/10.2/sql/mysqld.cc:6199
          #7 0x7f8a427a9d09 in __libc_start_main ../csu/libc-start.c:308
       
      SUMMARY: AddressSanitizer: heap-use-after-free ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:806 in __interceptor_memcpy
      Shadow bytes around the buggy address:
        0x0c047fff8820: fa fa fd fd fa fa fd fd fa fa fd fd fa fa fd fd
        0x0c047fff8830: fa fa fd fd fa fa fd fd fa fa fd fd fa fa 00 00
        0x0c047fff8840: fa fa 00 00 fa fa fd fd fa fa 00 00 fa fa 00 00
        0x0c047fff8850: fa fa 00 00 fa fa 00 00 fa fa 00 00 fa fa fd fd
        0x0c047fff8860: fa fa fd fd fa fa fd fd fa fa 00 00 fa fa 00 00
      =>0x0c047fff8870: fa fa fd[fd]fa fa 00 00 fa fa fa fa fa fa fa fa
        0x0c047fff8880: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c047fff8890: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c047fff88a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c047fff88b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c047fff88c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
      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
      ==3075970==ABORTING
      

      Attachments

        Activity

          People

            serg Sergei Golubchik
            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.