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

ASAN heap-use-after-free in Field_blob::pack / THD::binlog_update_row upon DML on table with virtual column

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.3(EOL), 10.4(EOL), 10.5, 10.6, 10.7(EOL), 10.8(EOL), 10.9(EOL), 10.10(EOL)
    • 10.5, 10.6
    • None

    Description

      Set to Minor because only 10.3 seems to be affected.

      --source include/have_log_bin.inc
       
      CREATE TABLE t1 (id INT PRIMARY KEY, b VARCHAR(8), vb BLOB AS (b) VIRTUAL) WITH SYSTEM VERSIONING;
      INSERT INTO t1 (id,b) VALUES (1,'foo');
      REPLACE INTO t1 (id, b) SELECT id, b FROM t1;
       
      # Cleanup
      DROP TABLE t1;
      

      10.3 7d04ce6a ASAN

      ==694614==ERROR: AddressSanitizer: heap-use-after-free on address 0x60c000024830 at pc 0x7fa906989480 bp 0x7fa8fb556000 sp 0x7fa8fb5557a8
      READ of size 3 at 0x60c000024830 thread T6
          #0 0x7fa90698947f  (/lib/x86_64-linux-gnu/libasan.so.5+0x9b47f)
          #1 0x55cf136eb7a4 in Field_blob::pack(unsigned char*, unsigned char const*, unsigned int) /data/src/10.3/sql/field.cc:8781
          #2 0x55cf13aa7f44 in pack_row(TABLE*, st_bitmap const*, unsigned char*, unsigned char const*) /data/src/10.3/sql/rpl_record.cc:106
          #3 0x55cf12ee25a4 in THD::binlog_update_row(TABLE*, bool, unsigned char const*, unsigned char const*) /data/src/10.3/sql/sql_class.cc:6778
          #4 0x55cf1377503c in Update_rows_log_event::binlog_row_logging_function(THD*, TABLE*, bool, unsigned char const*, unsigned char const*) /data/src/10.3/sql/log_event.h:4857
          #5 0x55cf137674a9 in binlog_log_row_internal /data/src/10.3/sql/handler.cc:6318
          #6 0x55cf1376799f in binlog_log_row(TABLE*, unsigned char const*, unsigned char const*, bool (*)(THD*, TABLE*, bool, unsigned char const*, unsigned char const*)) /data/src/10.3/sql/handler.cc:6352
          #7 0x55cf1376a11b in handler::ha_update_row(unsigned char const*, unsigned char const*) /data/src/10.3/sql/handler.cc:6512
          #8 0x55cf12f2ece5 in write_record(THD*, TABLE*, st_copy_info*) /data/src/10.3/sql/sql_insert.cc:1955
          #9 0x55cf12f3f81e in select_insert::send_data(List<Item>&) /data/src/10.3/sql/sql_insert.cc:3938
          #10 0x55cf13109ff9 in end_send /data/src/10.3/sql/sql_select.cc:20887
          #11 0x55cf130fe996 in do_select /data/src/10.3/sql/sql_select.cc:19204
          #12 0x55cf13092cca in JOIN::exec_inner() /data/src/10.3/sql/sql_select.cc:4120
          #13 0x55cf13090647 in JOIN::exec() /data/src/10.3/sql/sql_select.cc:3914
          #14 0x55cf130940b8 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.3/sql/sql_select.cc:4319
          #15 0x55cf1306ad2e in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.3/sql/sql_select.cc:370
          #16 0x55cf12fcf5b3 in mysql_execute_command(THD*) /data/src/10.3/sql/sql_parse.cc:4597
          #17 0x55cf12fe6a81 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.3/sql/sql_parse.cc:7840
          #18 0x55cf12fbd8c5 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.3/sql/sql_parse.cc:1852
          #19 0x55cf12fba3fc in do_command(THD*) /data/src/10.3/sql/sql_parse.cc:1398
          #20 0x55cf13384ceb in do_handle_one_connection(CONNECT*) /data/src/10.3/sql/sql_connect.cc:1403
          #21 0x55cf133845a5 in handle_one_connection /data/src/10.3/sql/sql_connect.cc:1308
          #22 0x55cf1499e21c in pfs_spawn_thread /data/src/10.3/storage/perfschema/pfs.cc:1869
          #23 0x7fa906494608 in start_thread /build/glibc-ZN95T4/glibc-2.31/nptl/pthread_create.c:477
          #24 0x7fa90606e292 in __clone (/lib/x86_64-linux-gnu/libc.so.6+0x122292)
       
      0x60c000024830 is located 112 bytes inside of 124-byte region [0x60c0000247c0,0x60c00002483c)
      freed by thread T6 here:
          #0 0x7fa9069fb7cf in __interceptor_free (/lib/x86_64-linux-gnu/libasan.so.5+0x10d7cf)
          #1 0x55cf14ae9a4d in free_memory /data/src/10.3/mysys/safemalloc.c:279
          #2 0x55cf14ae9009 in sf_free /data/src/10.3/mysys/safemalloc.c:197
          #3 0x55cf14ab731c in my_free /data/src/10.3/mysys/my_malloc.c:223
          #4 0x55cf12d0be7f in String::free() /data/src/10.3/sql/sql_string.h:369
          #5 0x55cf12d59e3f in String::set(char const*, unsigned long, charset_info_st const*) /data/src/10.3/sql/sql_string.h:289
          #6 0x55cf136ddf82 in Field_varstring::val_str(String*, String*) /data/src/10.3/sql/field.cc:7665
          #7 0x55cf12d395a7 in Field::val_str(String*) /data/src/10.3/sql/field.h:854
          #8 0x55cf13713968 in Field_blob::store_field(Field*) /data/src/10.3/sql/field.h:3693
          #9 0x55cf137213f5 in field_conv_incompatible /data/src/10.3/sql/field_conv.cc:836
          #10 0x55cf13721496 in field_conv(Field*, Field*) /data/src/10.3/sql/field_conv.cc:849
          #11 0x55cf137b52cb in save_field_in_field /data/src/10.3/sql/item.cc:6733
          #12 0x55cf137b5a98 in Item_field::save_in_field(Field*, bool) /data/src/10.3/sql/item.cc:6784
          #13 0x55cf132dcd65 in TABLE::update_virtual_fields(handler*, enum_vcol_update_mode) /data/src/10.3/sql/table.cc:7972
          #14 0x55cf12f2d5bd in write_record(THD*, TABLE*, st_copy_info*) /data/src/10.3/sql/sql_insert.cc:1801
          #15 0x55cf12f3f81e in select_insert::send_data(List<Item>&) /data/src/10.3/sql/sql_insert.cc:3938
          #16 0x55cf13109ff9 in end_send /data/src/10.3/sql/sql_select.cc:20887
          #17 0x55cf130fe996 in do_select /data/src/10.3/sql/sql_select.cc:19204
          #18 0x55cf13092cca in JOIN::exec_inner() /data/src/10.3/sql/sql_select.cc:4120
          #19 0x55cf13090647 in JOIN::exec() /data/src/10.3/sql/sql_select.cc:3914
          #20 0x55cf130940b8 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.3/sql/sql_select.cc:4319
          #21 0x55cf1306ad2e in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.3/sql/sql_select.cc:370
          #22 0x55cf12fcf5b3 in mysql_execute_command(THD*) /data/src/10.3/sql/sql_parse.cc:4597
          #23 0x55cf12fe6a81 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.3/sql/sql_parse.cc:7840
          #24 0x55cf12fbd8c5 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.3/sql/sql_parse.cc:1852
          #25 0x55cf12fba3fc in do_command(THD*) /data/src/10.3/sql/sql_parse.cc:1398
          #26 0x55cf13384ceb in do_handle_one_connection(CONNECT*) /data/src/10.3/sql/sql_connect.cc:1403
          #27 0x55cf133845a5 in handle_one_connection /data/src/10.3/sql/sql_connect.cc:1308
          #28 0x55cf1499e21c in pfs_spawn_thread /data/src/10.3/storage/perfschema/pfs.cc:1869
          #29 0x7fa906494608 in start_thread /build/glibc-ZN95T4/glibc-2.31/nptl/pthread_create.c:477
       
      previously allocated by thread T6 here:
          #0 0x7fa9069fbbc8 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
          #1 0x55cf14ae89bd in sf_malloc /data/src/10.3/mysys/safemalloc.c:118
          #2 0x55cf14ab6825 in my_malloc /data/src/10.3/mysys/my_malloc.c:101
          #3 0x55cf131d9ded in String::realloc_raw(unsigned long) /data/src/10.3/sql/sql_string.cc:101
          #4 0x55cf12d0bf9c in String::realloc(unsigned long) /data/src/10.3/sql/sql_string.h:385
          #5 0x55cf131dab29 in String::copy() /data/src/10.3/sql/sql_string.cc:212
          #6 0x55cf13713a71 in Field_blob::store_field(Field*) /data/src/10.3/sql/field.h:3696
          #7 0x55cf137213f5 in field_conv_incompatible /data/src/10.3/sql/field_conv.cc:836
          #8 0x55cf13721496 in field_conv(Field*, Field*) /data/src/10.3/sql/field_conv.cc:849
          #9 0x55cf137b52cb in save_field_in_field /data/src/10.3/sql/item.cc:6733
          #10 0x55cf137b5a98 in Item_field::save_in_field(Field*, bool) /data/src/10.3/sql/item.cc:6784
          #11 0x55cf132dcd65 in TABLE::update_virtual_fields(handler*, enum_vcol_update_mode) /data/src/10.3/sql/table.cc:7972
          #12 0x55cf132de7bc in TABLE::vers_update_fields() /data/src/10.3/sql/table.cc:8109
          #13 0x55cf12e78bd8 in fill_record(THD*, TABLE*, List<Item>&, List<Item>&, bool, bool) /data/src/10.3/sql/sql_base.cc:8448
          #14 0x55cf12e79827 in fill_record_n_invoke_before_triggers(THD*, TABLE*, List<Item>&, List<Item>&, bool, trg_event_type) /data/src/10.3/sql/sql_base.cc:8575
          #15 0x55cf12f4008b in select_insert::store_values(List<Item>&) /data/src/10.3/sql/sql_insert.cc:3981
          #16 0x55cf12f3f31c in select_insert::send_data(List<Item>&) /data/src/10.3/sql/sql_insert.cc:3916
          #17 0x55cf13109ff9 in end_send /data/src/10.3/sql/sql_select.cc:20887
          #18 0x55cf130fe996 in do_select /data/src/10.3/sql/sql_select.cc:19204
          #19 0x55cf13092cca in JOIN::exec_inner() /data/src/10.3/sql/sql_select.cc:4120
          #20 0x55cf13090647 in JOIN::exec() /data/src/10.3/sql/sql_select.cc:3914
          #21 0x55cf130940b8 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.3/sql/sql_select.cc:4319
          #22 0x55cf1306ad2e in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.3/sql/sql_select.cc:370
          #23 0x55cf12fcf5b3 in mysql_execute_command(THD*) /data/src/10.3/sql/sql_parse.cc:4597
          #24 0x55cf12fe6a81 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.3/sql/sql_parse.cc:7840
          #25 0x55cf12fbd8c5 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.3/sql/sql_parse.cc:1852
          #26 0x55cf12fba3fc in do_command(THD*) /data/src/10.3/sql/sql_parse.cc:1398
          #27 0x55cf13384ceb in do_handle_one_connection(CONNECT*) /data/src/10.3/sql/sql_connect.cc:1403
          #28 0x55cf133845a5 in handle_one_connection /data/src/10.3/sql/sql_connect.cc:1308
          #29 0x55cf1499e21c in pfs_spawn_thread /data/src/10.3/storage/perfschema/pfs.cc:1869
       
      Thread T6 created by T0 here:
          #0 0x7fa906928805 in pthread_create (/lib/x86_64-linux-gnu/libasan.so.5+0x3a805)
          #1 0x55cf1499e60d in spawn_thread_v1 /data/src/10.3/storage/perfschema/pfs.cc:1919
          #2 0x55cf12ce515e in inline_mysql_thread_create /data/src/10.3/include/mysql/psi/mysql_thread.h:1275
          #3 0x55cf12cfdb2d in create_thread_to_handle_connection(CONNECT*) /data/src/10.3/sql/mysqld.cc:6658
          #4 0x55cf12cfe2c8 in create_new_thread /data/src/10.3/sql/mysqld.cc:6728
          #5 0x55cf12cff45a in handle_connections_sockets() /data/src/10.3/sql/mysqld.cc:6986
          #6 0x55cf12cfce1e in mysqld_main(int, char**) /data/src/10.3/sql/mysqld.cc:6280
          #7 0x55cf12ce395c in main /data/src/10.3/sql/main.cc:25
          #8 0x7fa905f730b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
       
      SUMMARY: AddressSanitizer: heap-use-after-free (/lib/x86_64-linux-gnu/libasan.so.5+0x9b47f) 
      Shadow bytes around the buggy address:
        0x0c187fffc8b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04
        0x0c187fffc8c0: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
        0x0c187fffc8d0: 00 00 00 00 00 00 00 04 fa fa fa fa fa fa fa fa
        0x0c187fffc8e0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        0x0c187fffc8f0: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
      =>0x0c187fffc900: fd fd fd fd fd fd[fd]fd fa fa fa fa fa fa fa fa
        0x0c187fffc910: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04
        0x0c187fffc920: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
        0x0c187fffc930: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa
        0x0c187fffc940: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c187fffc950: 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
      ==694614==ABORTING
      

      No obvious problem on a non-ASAN build.
      The test case is not applicable to pre-10.3 versions due to the use of system versioning.
      Couldn't reproduce on 10.4+, neither could find what had fixed it there.

      Attachments

        Issue Links

          Activity

            People

              Elkin Andrei Elkin
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.