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

Invalid value allowed for geometry, ASAN: use-after-poison in sp_get_geometry_mbr upon INSERT SELECT with spatial index

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 5.5, 10.1, 10.2, 10.3, 10.4
    • Fix Version/s: 10.1, 10.2, 10.3, 10.4
    • Component/s: GIS
    • Labels:
      None

      Description

      --source include/have_innodb.inc
       
      CREATE TABLE t1 (a POINT) ENGINE=InnoDB;
      CREATE TABLE t2 (b POINT NOT NULL, SPATIAL KEY (b)) ENGINE=MyISAM;
      INSERT INTO t1 () VALUES ('');
      INSERT INTO t2 SELECT * FROM t1;
       
      # Cleanup
      DROP TABLE t1, t2;
      

      10.4 6cedb671

      ==1025==ERROR: AddressSanitizer: use-after-poison on address 0x6290002a3294 at pc 0x55721388bfed bp 0x7fe5ba56db40 sp 0x7fe5ba56db38
      READ of size 1 at 0x6290002a3294 thread T27
          #0 0x55721388bfec in sp_get_geometry_mbr /data/src/10.4/storage/myisam/sp_key.c:196
          #1 0x55721388ba38 in sp_mbr_from_wkb /data/src/10.4/storage/myisam/sp_key.c:111
          #2 0x55721388b310 in sp_make_key /data/src/10.4/storage/myisam/sp_key.c:56
          #3 0x5572137f0add in _mi_make_key /data/src/10.4/storage/myisam/mi_key.c:67
          #4 0x557213845b29 in mi_write /data/src/10.4/storage/myisam/mi_write.c:125
          #5 0x55721379092f in ha_myisam::write_row(unsigned char const*) /data/src/10.4/storage/myisam/ha_myisam.cc:949
          #6 0x5572128ebe15 in handler::ha_write_row(unsigned char const*) /data/src/10.4/sql/handler.cc:6674
          #7 0x5572120bce26 in write_record(THD*, TABLE*, st_copy_info*) /data/src/10.4/sql/sql_insert.cc:2036
          #8 0x5572120cb095 in select_insert::send_data(List<Item>&) /data/src/10.4/sql/sql_insert.cc:3893
          #9 0x557212287268 in end_send /data/src/10.4/sql/sql_select.cc:21372
          #10 0x55721227fcc6 in evaluate_join_record /data/src/10.4/sql/sql_select.cc:20407
          #11 0x55721227e8e3 in sub_select(JOIN*, st_join_table*, bool) /data/src/10.4/sql/sql_select.cc:20187
          #12 0x55721227cccc in do_select /data/src/10.4/sql/sql_select.cc:19725
          #13 0x557212216133 in JOIN::exec_inner() /data/src/10.4/sql/sql_select.cc:4386
          #14 0x557212213a3f in JOIN::exec() /data/src/10.4/sql/sql_select.cc:4168
          #15 0x5572122174f1 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.4/sql/sql_select.cc:4600
          #16 0x5572121ed9b6 in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.4/sql/sql_select.cc:420
          #17 0x557212162711 in mysql_execute_command(THD*) /data/src/10.4/sql/sql_parse.cc:4643
          #18 0x557212178621 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.4/sql/sql_parse.cc:7898
          #19 0x5572121518de in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.4/sql/sql_parse.cc:1842
          #20 0x55721214e7d2 in do_command(THD*) /data/src/10.4/sql/sql_parse.cc:1360
          #21 0x5572124d3ba0 in do_handle_one_connection(CONNECT*) /data/src/10.4/sql/sql_connect.cc:1412
          #22 0x5572124d3554 in handle_one_connection /data/src/10.4/sql/sql_connect.cc:1316
          #23 0x557213930385 in pfs_spawn_thread /data/src/10.4/storage/perfschema/pfs.cc:1862
          #24 0x7fe5d1dac4a3 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x74a3)
          #25 0x7fe5d02f3d0e in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xe8d0e)
       
      0x6290002a3294 is located 148 bytes inside of 16520-byte region [0x6290002a3200,0x6290002a7288)
      allocated by thread T27 here:
          #0 0x7fe5d2083d28 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d28)
          #1 0x557212fa7eaf in mem_heap_create_block_func(mem_block_info_t*, unsigned long, char const*, unsigned int, unsigned long) /data/src/10.4/storage/innobase/mem/mem0mem.cc:280
          #2 0x557213145d6b in mem_heap_create_func /data/src/10.4/storage/innobase/include/mem0mem.ic:393
          #3 0x55721315a980 in row_sel_store_mysql_field /data/src/10.4/storage/innobase/row/row0sel.cc:2994
          #4 0x55721315bc5c in row_sel_store_mysql_rec /data/src/10.4/storage/innobase/row/row0sel.cc:3141
          #5 0x557213167815 in row_search_mvcc(unsigned char*, page_cur_mode_t, row_prebuilt_t*, unsigned long, unsigned long) /data/src/10.4/storage/innobase/row/row0sel.cc:5488
          #6 0x557212e0fbf3 in ha_innobase::index_read(unsigned char*, unsigned char const*, unsigned int, ha_rkey_function) /data/src/10.4/storage/innobase/handler/ha_innodb.cc:9305
          #7 0x557212e12b4d in ha_innobase::index_first(unsigned char*) /data/src/10.4/storage/innobase/handler/ha_innodb.cc:9678
          #8 0x557212e12fed in ha_innobase::rnd_next(unsigned char*) /data/src/10.4/storage/innobase/handler/ha_innodb.cc:9771
          #9 0x5572128ce620 in handler::ha_rnd_next(unsigned char*) /data/src/10.4/sql/handler.cc:2826
          #10 0x557212c99a2b in rr_sequential(READ_RECORD*) /data/src/10.4/sql/records.cc:477
          #11 0x557211fd5fa1 in READ_RECORD::read_record() /data/src/10.4/sql/records.h:69
          #12 0x557212284ead in join_init_read_record(st_join_table*) /data/src/10.4/sql/sql_select.cc:21128
          #13 0x55721227e72a in sub_select(JOIN*, st_join_table*, bool) /data/src/10.4/sql/sql_select.cc:20184
          #14 0x55721227cccc in do_select /data/src/10.4/sql/sql_select.cc:19725
          #15 0x557212216133 in JOIN::exec_inner() /data/src/10.4/sql/sql_select.cc:4386
          #16 0x557212213a3f in JOIN::exec() /data/src/10.4/sql/sql_select.cc:4168
          #17 0x5572122174f1 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.4/sql/sql_select.cc:4600
          #18 0x5572121ed9b6 in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.4/sql/sql_select.cc:420
          #19 0x557212162711 in mysql_execute_command(THD*) /data/src/10.4/sql/sql_parse.cc:4643
          #20 0x557212178621 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.4/sql/sql_parse.cc:7898
          #21 0x5572121518de in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.4/sql/sql_parse.cc:1842
          #22 0x55721214e7d2 in do_command(THD*) /data/src/10.4/sql/sql_parse.cc:1360
          #23 0x5572124d3ba0 in do_handle_one_connection(CONNECT*) /data/src/10.4/sql/sql_connect.cc:1412
          #24 0x5572124d3554 in handle_one_connection /data/src/10.4/sql/sql_connect.cc:1316
          #25 0x557213930385 in pfs_spawn_thread /data/src/10.4/storage/perfschema/pfs.cc:1862
          #26 0x7fe5d1dac4a3 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x74a3)
       
      Thread T27 created by T0 here:
          #0 0x7fe5d1ff2f59 in __interceptor_pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x30f59)
          #1 0x557213930772 in spawn_thread_v1 /data/src/10.4/storage/perfschema/pfs.cc:1912
          #2 0x557211ea96a8 in inline_mysql_thread_create /data/src/10.4/include/mysql/psi/mysql_thread.h:1268
          #3 0x557211ebdc4c in create_thread_to_handle_connection(CONNECT*) /data/src/10.4/sql/mysqld.cc:6234
          #4 0x557211ebe32f in create_new_thread(CONNECT*) /data/src/10.4/sql/mysqld.cc:6304
          #5 0x557211ebe6ba in handle_accepted_socket(st_mysql_socket, st_mysql_socket) /data/src/10.4/sql/mysqld.cc:6402
          #6 0x557211ebf30c in handle_connections_sockets() /data/src/10.4/sql/mysqld.cc:6560
          #7 0x557211ebd4cd in mysqld_main(int, char**) /data/src/10.4/sql/mysqld.cc:5892
          #8 0x557211ea758f in main /data/src/10.4/sql/main.cc:25
          #9 0x7fe5d022b2e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
       
      SUMMARY: AddressSanitizer: use-after-poison /data/src/10.4/storage/myisam/sp_key.c:196 in sp_get_geometry_mbr
      Shadow bytes around the buggy address:
        0x0c528004c600: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c528004c610: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c528004c620: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c528004c630: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c528004c640: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      =>0x0c528004c650: 00 f7[f7]f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c528004c660: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c528004c670: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c528004c680: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c528004c690: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c528004c6a0: 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
        Container overflow:      fc
        Array cookie:            ac
        Intra object redzone:    bb
        ASan internal:           fe
        Left alloca redzone:     ca
        Right alloca redzone:    cb
      ==1025==ABORTING
      

      or with Aria instead of MyISAM in the same test case:

      ==2280==ERROR: AddressSanitizer: use-after-poison on address 0x629000299294 at pc 0x55e86fb1999f bp 0x7f41fa8d4c10 sp 0x7f41fa8d4c08
      READ of size 1 at 0x629000299294 thread T27
          #0 0x55e86fb1999e in sp_get_geometry_mbr /data/src/10.4/storage/maria/ma_sp_key.c:215
          #1 0x55e86fb193ea in sp_mbr_from_wkb /data/src/10.4/storage/maria/ma_sp_key.c:130
          #2 0x55e86fb18838 in _ma_sp_make_key /data/src/10.4/storage/maria/ma_sp_key.c:67
          #3 0x55e86fa76623 in maria_write /data/src/10.4/storage/maria/ma_write.c:189
          #4 0x55e86f93574b in ha_maria::write_row(unsigned char const*) /data/src/10.4/storage/maria/ha_maria.cc:1247
          #5 0x55e86ec8de15 in handler::ha_write_row(unsigned char const*) /data/src/10.4/sql/handler.cc:6674
          #6 0x55e86e45ee26 in write_record(THD*, TABLE*, st_copy_info*) /data/src/10.4/sql/sql_insert.cc:2036
          #7 0x55e86e46d095 in select_insert::send_data(List<Item>&) /data/src/10.4/sql/sql_insert.cc:3893
          #8 0x55e86e629268 in end_send /data/src/10.4/sql/sql_select.cc:21372
          #9 0x55e86e621cc6 in evaluate_join_record /data/src/10.4/sql/sql_select.cc:20407
          #10 0x55e86e6208e3 in sub_select(JOIN*, st_join_table*, bool) /data/src/10.4/sql/sql_select.cc:20187
          #11 0x55e86e61eccc in do_select /data/src/10.4/sql/sql_select.cc:19725
          #12 0x55e86e5b8133 in JOIN::exec_inner() /data/src/10.4/sql/sql_select.cc:4386
          #13 0x55e86e5b5a3f in JOIN::exec() /data/src/10.4/sql/sql_select.cc:4168
          #14 0x55e86e5b94f1 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.4/sql/sql_select.cc:4600
          #15 0x55e86e58f9b6 in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.4/sql/sql_select.cc:420
          #16 0x55e86e504711 in mysql_execute_command(THD*) /data/src/10.4/sql/sql_parse.cc:4643
          #17 0x55e86e51a621 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.4/sql/sql_parse.cc:7898
          #18 0x55e86e4f38de in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.4/sql/sql_parse.cc:1842
          #19 0x55e86e4f07d2 in do_command(THD*) /data/src/10.4/sql/sql_parse.cc:1360
          #20 0x55e86e875ba0 in do_handle_one_connection(CONNECT*) /data/src/10.4/sql/sql_connect.cc:1412
          #21 0x55e86e875554 in handle_one_connection /data/src/10.4/sql/sql_connect.cc:1316
          #22 0x55e86fcd2385 in pfs_spawn_thread /data/src/10.4/storage/perfschema/pfs.cc:1862
          #23 0x7f42121134a3 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x74a3)
          #24 0x7f421065ad0e in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xe8d0e)
       
      0x629000299294 is located 148 bytes inside of 16520-byte region [0x629000299200,0x62900029d288)
      allocated by thread T27 here:
          #0 0x7f42123ead28 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.3+0xc1d28)
          #1 0x55e86f349eaf in mem_heap_create_block_func(mem_block_info_t*, unsigned long, char const*, unsigned int, unsigned long) /data/src/10.4/storage/innobase/mem/mem0mem.cc:280
          #2 0x55e86f4e7d6b in mem_heap_create_func /data/src/10.4/storage/innobase/include/mem0mem.ic:393
          #3 0x55e86f4fc980 in row_sel_store_mysql_field /data/src/10.4/storage/innobase/row/row0sel.cc:2994
          #4 0x55e86f4fdc5c in row_sel_store_mysql_rec /data/src/10.4/storage/innobase/row/row0sel.cc:3141
          #5 0x55e86f509815 in row_search_mvcc(unsigned char*, page_cur_mode_t, row_prebuilt_t*, unsigned long, unsigned long) /data/src/10.4/storage/innobase/row/row0sel.cc:5488
          #6 0x55e86f1b1bf3 in ha_innobase::index_read(unsigned char*, unsigned char const*, unsigned int, ha_rkey_function) /data/src/10.4/storage/innobase/handler/ha_innodb.cc:9305
          #7 0x55e86f1b4b4d in ha_innobase::index_first(unsigned char*) /data/src/10.4/storage/innobase/handler/ha_innodb.cc:9678
          #8 0x55e86f1b4fed in ha_innobase::rnd_next(unsigned char*) /data/src/10.4/storage/innobase/handler/ha_innodb.cc:9771
          #9 0x55e86ec70620 in handler::ha_rnd_next(unsigned char*) /data/src/10.4/sql/handler.cc:2826
          #10 0x55e86f03ba2b in rr_sequential(READ_RECORD*) /data/src/10.4/sql/records.cc:477
          #11 0x55e86e377fa1 in READ_RECORD::read_record() /data/src/10.4/sql/records.h:69
          #12 0x55e86e626ead in join_init_read_record(st_join_table*) /data/src/10.4/sql/sql_select.cc:21128
          #13 0x55e86e62072a in sub_select(JOIN*, st_join_table*, bool) /data/src/10.4/sql/sql_select.cc:20184
          #14 0x55e86e61eccc in do_select /data/src/10.4/sql/sql_select.cc:19725
          #15 0x55e86e5b8133 in JOIN::exec_inner() /data/src/10.4/sql/sql_select.cc:4386
          #16 0x55e86e5b5a3f in JOIN::exec() /data/src/10.4/sql/sql_select.cc:4168
          #17 0x55e86e5b94f1 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.4/sql/sql_select.cc:4600
          #18 0x55e86e58f9b6 in handle_select(THD*, LEX*, select_result*, unsigned long) /data/src/10.4/sql/sql_select.cc:420
          #19 0x55e86e504711 in mysql_execute_command(THD*) /data/src/10.4/sql/sql_parse.cc:4643
          #20 0x55e86e51a621 in mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool) /data/src/10.4/sql/sql_parse.cc:7898
          #21 0x55e86e4f38de in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool) /data/src/10.4/sql/sql_parse.cc:1842
          #22 0x55e86e4f07d2 in do_command(THD*) /data/src/10.4/sql/sql_parse.cc:1360
          #23 0x55e86e875ba0 in do_handle_one_connection(CONNECT*) /data/src/10.4/sql/sql_connect.cc:1412
          #24 0x55e86e875554 in handle_one_connection /data/src/10.4/sql/sql_connect.cc:1316
          #25 0x55e86fcd2385 in pfs_spawn_thread /data/src/10.4/storage/perfschema/pfs.cc:1862
          #26 0x7f42121134a3 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x74a3)
       
      Thread T27 created by T0 here:
          #0 0x7f4212359f59 in __interceptor_pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.3+0x30f59)
          #1 0x55e86fcd2772 in spawn_thread_v1 /data/src/10.4/storage/perfschema/pfs.cc:1912
          #2 0x55e86e24b6a8 in inline_mysql_thread_create /data/src/10.4/include/mysql/psi/mysql_thread.h:1268
          #3 0x55e86e25fc4c in create_thread_to_handle_connection(CONNECT*) /data/src/10.4/sql/mysqld.cc:6234
          #4 0x55e86e26032f in create_new_thread(CONNECT*) /data/src/10.4/sql/mysqld.cc:6304
          #5 0x55e86e2606ba in handle_accepted_socket(st_mysql_socket, st_mysql_socket) /data/src/10.4/sql/mysqld.cc:6402
          #6 0x55e86e26130c in handle_connections_sockets() /data/src/10.4/sql/mysqld.cc:6560
          #7 0x55e86e25f4cd in mysqld_main(int, char**) /data/src/10.4/sql/mysqld.cc:5892
          #8 0x55e86e24958f in main /data/src/10.4/sql/main.cc:25
          #9 0x7f42105922e0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
       
      SUMMARY: AddressSanitizer: use-after-poison /data/src/10.4/storage/maria/ma_sp_key.c:215 in sp_get_geometry_mbr
      Shadow bytes around the buggy address:
        0x0c528004b200: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c528004b210: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c528004b220: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c528004b230: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c528004b240: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
      =>0x0c528004b250: 00 f7[f7]f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c528004b260: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c528004b270: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c528004b280: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c528004b290: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c528004b2a0: 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
        Container overflow:      fc
        Array cookie:            ac
        Intra object redzone:    bb
        ASan internal:           fe
        Left alloca redzone:     ca
        Right alloca redzone:    cb
      ==2280==ABORTING
      

      Reproducible on all of 5.5-10.5.
      Not reproducible with InnoDB for the second table.
      Not reproducible with MyISAM or Aria for the first table.
      No obvious problem on a non-ASAN build, but the behavior seems questionable to begin with: why is inserting an empty string into a geometry field is allowed to begin with.

        Attachments

          Activity

            People

            Assignee:
            holyfoot Alexey Botchkov
            Reporter:
            elenst Elena Stepanova
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: