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

Buffer overflow on instant ADD/DROP of generated column

    XMLWordPrintable

    Details

      Description

      PoC:

      CREATE TABLE v0 ( v1 TIME NOT NULL PRIMARY KEY ) ;
       ALTER TABLE v0 ADD COLUMN v0 INT GENERATED ALWAYS AS ( lpad ( 'x' , NULL = 32 , 'x' ) ) STORED ;
       SHOW LOCAL STATUS WHERE COALESCE ( 27 , 51 - 39 ) = 'x' ;
       DELETE FROM v0 WHERE 44707452.000000 ;
       ALTER TABLE v0 ADD COLUMN v0 INT GENERATED ALWAYS AS ( v1 + v1 ) , DROP COLUMN v0 ;
       SELECT COUNT ( * ) FROM v0 WHERE v1 = -128 AND v1 = 'x' ;
      

      Log and Asan report:

      2021-08-16 14:41:38 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
      2021-08-16 14:41:38 0 [Note] InnoDB: Number of pools: 1
      2021-08-16 14:41:38 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
      2021-08-16 14:41:38 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
      2021-08-16 14:41:38 0 [Note] InnoDB: Using liburing
      2021-08-16 14:41:38 0 [Note] InnoDB: Initializing buffer pool, total size = 134217728, chunk size = 134217728
      2021-08-16 14:41:38 0 [Note] InnoDB: Completed initialization of buffer pool
      2021-08-16 14:41:38 0 [Note] InnoDB: 128 rollback segments are active.
      2021-08-16 14:41:38 0 [Note] InnoDB: Creating shared tablespace for temporary tables
      2021-08-16 14:41:38 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
      2021-08-16 14:41:38 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
      2021-08-16 14:41:38 0 [Note] InnoDB: 10.7.0 started; log sequence number 42161; transaction id 14
      2021-08-16 14:41:38 0 [Note] InnoDB: Loading buffer pool(s) from /home/fuboat/mariadb-tmp/mysql-default-data/ib_buffer_pool
      2021-08-16 14:41:38 0 [Note] Plugin 'FEEDBACK' is disabled.
      2021-08-16 14:41:38 0 [Note] InnoDB: Buffer pool(s) load completed at 210816 14:41:38
      2021-08-16 14:41:38 0 [Note] Server socket created on IP: '0.0.0.0'.
      2021-08-16 14:41:38 0 [Note] Server socket created on IP: '::'.
      2021-08-16 14:41:38 0 [Note] /usr/local/mysql/bin//mysqld: ready for connections.
      Version: '10.7.0-MariaDB'  socket: '/tmp/0.socket'  port: 3306  Source distribution
      2021-08-16 14:41:39 0 [Note] /usr/local/mysql/bin//mysqld (initiated by: root[root] @ localhost []): Normal shutdown
      2021-08-16 14:41:39 0 [Note] InnoDB: FTS optimize thread exiting.
      2021-08-16 14:41:39 0 [Note] InnoDB: Starting shutdown...
      2021-08-16 14:41:39 0 [Note] InnoDB: Dumping buffer pool(s) to /home/fuboat/mariadb-tmp/mysql-default-data/ib_buffer_pool
      2021-08-16 14:41:39 0 [Note] InnoDB: Buffer pool(s) dump completed at 210816 14:41:39
      2021-08-16 14:41:39 0 [Note] InnoDB: Removed temporary tablespace data file: "./ibtmp1"
      2021-08-16 14:41:39 0 [Note] InnoDB: Shutdown completed; log sequence number 42173; transaction id 15
      2021-08-16 14:41:39 0 [Note] /usr/local/mysql/bin//mysqld: Shutdown complete
       
      2021-08-16 14:49:19 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
      2021-08-16 14:49:19 0 [Note] InnoDB: Number of pools: 1
      2021-08-16 14:49:19 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
      2021-08-16 14:49:19 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
      2021-08-16 14:49:19 0 [Note] InnoDB: Using liburing
      2021-08-16 14:49:19 0 [Note] InnoDB: Initializing buffer pool, total size = 134217728, chunk size = 134217728
      2021-08-16 14:49:19 0 [Note] InnoDB: Completed initialization of buffer pool
      2021-08-16 14:49:26 0 [Note] InnoDB: 128 rollback segments are active.
      2021-08-16 14:49:26 0 [Note] InnoDB: Creating shared tablespace for temporary tables
      2021-08-16 14:49:26 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
      2021-08-16 14:49:26 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
      2021-08-16 14:49:26 0 [Note] InnoDB: 10.7.0 started; log sequence number 42173; transaction id 14
      2021-08-16 14:49:26 0 [Note] InnoDB: Loading buffer pool(s) from /home/fuboat/mariadb-tmp/19/ib_buffer_pool
      2021-08-16 14:49:26 0 [Note] Plugin 'FEEDBACK' is disabled.
      2021-08-16 14:49:27 0 [Note] Server socket created on IP: '0.0.0.0'.
      2021-08-16 14:49:27 0 [Note] Server socket created on IP: '::'.
      2021-08-16 14:49:28 0 [Note] InnoDB: Buffer pool(s) load completed at 210816 14:49:28
      2021-08-16 14:49:28 0 [Note] /usr/local/mysql/bin//mysqld: ready for connections.
      Version: '10.7.0-MariaDB'  socket: '/tmp/19.socket'  port: 10019  Source distribution
      =================================================================
      ==2119277==ERROR: AddressSanitizer: use-after-poison on address 0x6190000d6d60 at pc 0x55a3184baacf bp 0x7f47ed829920 sp 0x7f47ed829910
      WRITE of size 64 at 0x6190000d6d60 thread T14
          #0 0x55a3184baace in prepare_inplace_add_virtual /experiment/mariadb-server/sql/field.h:1395
          #1 0x55a3184cc1db in prepare_inplace_alter_table_dict /experiment/mariadb-server/storage/innobase/handler/handler0alter.cc:6206
          #2 0x55a3184d9f06 in ha_innobase::prepare_inplace_alter_table(TABLE*, Alter_inplace_info*) /experiment/mariadb-server/storage/innobase/handler/handler0alter.cc:8270
          #3 0x55a3176a67d2 in mysql_inplace_alter_table /experiment/mariadb-server/sql/sql_table.cc:7326
          #4 0x55a3176a67d2 in mysql_alter_table(THD*, st_mysql_const_lex_string const*, st_mysql_const_lex_string const*, HA_CREATE_INFO*, TABLE_LIST*, Alter_info*, unsigned int, st_order*, bool, bool) /experiment/mariadb-server/sql/sql_table.cc:10205
          #5 0x55a3177fcf99 in Sql_cmd_alter_table::execute(THD*) /experiment/mariadb-server/sql/sql_alter.cc:550
          #6 0x55a31741717f in mysql_execute_command(THD*, bool) /experiment/mariadb-server/sql/sql_parse.cc:5997
          #7 0x55a3174245a0 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /experiment/mariadb-server/sql/sql_parse.cc:8030
          #8 0x55a31742a60b in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /experiment/mariadb-server/sql/sql_parse.cc:1896
          #9 0x55a31742f73c in do_command(THD*, bool) /experiment/mariadb-server/sql/sql_parse.cc:1404
          #10 0x55a3177eae56 in do_handle_one_connection(CONNECT*, bool) /experiment/mariadb-server/sql/sql_connect.cc:1418
          #11 0x55a3177eb33c in handle_one_connection /experiment/mariadb-server/sql/sql_connect.cc:1312
          #12 0x55a31827bc2b in pfs_spawn_thread /experiment/mariadb-server/storage/perfschema/pfs.cc:2201
          #13 0x7f4812443258 in start_thread (/usr/lib/libpthread.so.0+0x9258)
          #14 0x7f4811fee5e2 in __GI___clone (/usr/lib/libc.so.6+0xfe5e2)
       
      0x6190000d6d60 is located 480 bytes inside of 1152-byte region [0x6190000d6b80,0x6190000d7000)
      allocated by thread T14 here:
          #0 0x7f4812ad5279 in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145
          #1 0x55a3185c76c0 in ut_allocator<unsigned char, true>::allocate(unsigned long, unsigned char const*, unsigned int, bool, bool) /experiment/mariadb-server/storage/innobase/include/ut0new.h:375
          #2 0x55a3185c76c0 in mem_heap_create_block_func(mem_block_info_t*, unsigned long, unsigned long) /experiment/mariadb-server/storage/innobase/mem/mem0mem.cc:277
          #3 0x55a3184da801 in mem_heap_create_func /experiment/mariadb-server/storage/innobase/include/mem0mem.ic:377
          #4 0x55a3184da801 in ha_innobase::prepare_inplace_alter_table(TABLE*, Alter_inplace_info*) /experiment/mariadb-server/storage/innobase/handler/handler0alter.cc:7816
          #5 0x55a3176a67d2 in mysql_inplace_alter_table /experiment/mariadb-server/sql/sql_table.cc:7326
          #6 0x55a3176a67d2 in mysql_alter_table(THD*, st_mysql_const_lex_string const*, st_mysql_const_lex_string const*, HA_CREATE_INFO*, TABLE_LIST*, Alter_info*, unsigned int, st_order*, bool, bool) /experiment/mariadb-server/sql/sql_table.cc:10205
          #7 0x55a3177fcf99 in Sql_cmd_alter_table::execute(THD*) /experiment/mariadb-server/sql/sql_alter.cc:550
          #8 0x55a31741717f in mysql_execute_command(THD*, bool) /experiment/mariadb-server/sql/sql_parse.cc:5997
          #9 0x55a3174245a0 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /experiment/mariadb-server/sql/sql_parse.cc:8030
          #10 0x55a31742a60b in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /experiment/mariadb-server/sql/sql_parse.cc:1896
          #11 0x55a31742f73c in do_command(THD*, bool) /experiment/mariadb-server/sql/sql_parse.cc:1404
          #12 0x55a3177eae56 in do_handle_one_connection(CONNECT*, bool) /experiment/mariadb-server/sql/sql_connect.cc:1418
          #13 0x55a3177eb33c in handle_one_connection /experiment/mariadb-server/sql/sql_connect.cc:1312
          #14 0x55a31827bc2b in pfs_spawn_thread /experiment/mariadb-server/storage/perfschema/pfs.cc:2201
          #15 0x7f4812443258 in start_thread (/usr/lib/libpthread.so.0+0x9258)
       
      Thread T14 created by T0 here:
          #0 0x7f4812a76fa7 in __interceptor_pthread_create /build/gcc/src/gcc/libsanitizer/asan/asan_interceptors.cpp:216
          #1 0x55a31827bea9 in my_thread_create /experiment/mariadb-server/storage/perfschema/my_thread.h:48
          #2 0x55a31827bea9 in pfs_spawn_thread_v1 /experiment/mariadb-server/storage/perfschema/pfs.cc:2252
          #3 0x55a3170ecb3c in inline_mysql_thread_create /experiment/mariadb-server/include/mysql/psi/mysql_thread.h:1139
          #4 0x55a3170ecb3c in create_thread_to_handle_connection(CONNECT*) /experiment/mariadb-server/sql/mysqld.cc:5934
          #5 0x55a3170f87b6 in handle_accepted_socket(st_mysql_socket, st_mysql_socket) /experiment/mariadb-server/sql/mysqld.cc:6055
          #6 0x55a3170f936f in handle_connections_sockets() /experiment/mariadb-server/sql/mysqld.cc:6179
          #7 0x55a3170fca52 in mysqld_main(int, char**) /experiment/mariadb-server/sql/mysqld.cc:5829
          #8 0x7f4811f17b24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)
       
      SUMMARY: AddressSanitizer: use-after-poison /experiment/mariadb-server/sql/field.h:1395 in prepare_inplace_add_virtual
      Shadow bytes around the buggy address:
        0x0c3280012d50: f7 f7 fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c3280012d60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
        0x0c3280012d70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
        0x0c3280012d80: f7 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
        0x0c3280012d90: 00 00 00 00 00 00 f7 00 00 00 00 00 00 00 00 00
      =>0x0c3280012da0: 00 00 00 00 00 00 00 00 00 00 00 f7[f7]f7 f7 f7
        0x0c3280012db0: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c3280012dc0: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c3280012dd0: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c3280012de0: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7
        0x0c3280012df0: 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
        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
      ==2119277==ABORTING
      GNU gdb (GDB) 10.2
      Copyright (C) 2021 Free Software Foundation, Inc.
      License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
      This is free software: you are free to change and redistribute it.
      There is NO WARRANTY, to the extent permitted by law.
      Type "show copying" and "show warranty" for details.
      This GDB was configured as "x86_64-pc-linux-gnu".
      Type "show configuration" for configuration details.
      For bug reporting instructions, please see:
      <https://www.gnu.org/software/gdb/bugs/>.
      Find the GDB manual and other documentation resources online at:
          <http://www.gnu.org/software/gdb/documentation/>.
       
      For help, type "help".
      Type "apropos word" to search for commands related to "word"...
      Reading symbols from /usr/local/mysql/bin//mysqld...
      (gdb) (gdb) (gdb) quit
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              marko Marko Mäkelä
              Reporter:
              Zhiyong Zhiyong Wu
              Votes:
              0 Vote for this issue
              Watchers:
              4 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.