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

Server without encryption configs crashes if selecting from an implicitly encrypted table

    XMLWordPrintable

Details

    Description

      In my.cnf:

      plugin-load-add=file_key_management.so
      file-key-management-filename = /var/lib/mysql/keys.txt
      innodb-encrypt-tables

      Create table:

      create table t5 (
          -> `intcol1` int(32) DEFAULT NULL,
          ->   `intcol2` int(32) DEFAULT NULL,
          ->   `charcol1` varchar(128) DEFAULT NULL,
          ->   `charcol2` varchar(128) DEFAULT NULL,
          ->   `charcol3` varchar(128) DEFAULT NULL
          -> ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

      Insert some data:

      insert into t5 values (1,2,'maria','db','encryption');

      Data is encrypted (e.g., sample from xxd output):

      00044d0: 58a9 8252 4e9e 94d8 cd28 0755 3645 7eed  X..RN....(.U6E~.
      00044e0: 455c 054c 22b4 baa4 f507 8bd4 0e20 e509  E\.L"........ ..
      00044f0: 1d16 a362 dba4 ae16 7243 a465 15d2 4713  ...b....rC.e..G.
      0004500: f9ce 5426 5dcb fe4c 91ff 9985 69b9 7226  ..T&]..L....i.r&
      0004510: c72d 4a4e fa4e 039f c7d5 f296 9035 b3bc  .-JN.N.......5..

      Configs removed from my.cnf:

      #plugin-load-add=file_key_management.so
      #file-key-management-filename = /var/lib/mysql/keys.txt
      #innodb-encrypt-tables

      Server restarted:

      service mysql restart
      Restarting mysql (via systemctl):                          [  OK  ]

      Table created explicitly with encryption via alter statement gives appropriate error message:

      select * from mysqlslap.t1\G
      ERROR 1296 (HY000): Got error 192 'Table encrypted but decryption failed. This could be because correct encryption management plugin is not loaded, used encryption key is not available or encryption method does not match.' from InnoDB

      That table's alter and definition are as follows:

      alter table mysqlslap.t1 encrypted='yes' `encryption_key_id`=1;
      ...
      CREATE TABLE `t1` (
        `intcol1` int(32) DEFAULT NULL,
        `intcol2` int(32) DEFAULT NULL,
        `charcol1` varchar(128) DEFAULT NULL,
        `charcol2` varchar(128) DEFAULT NULL,
        `charcol3` varchar(128) DEFAULT NULL
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1 `encrypted`='yes' `encryption_key_id`=1

      Table encrypted implicitly via innodb-encrypt-tables crashes the server:

      select * from mysqlslap.t5\G
      ERROR 2013 (HY000): Lost connection to MySQL server during query

      From the error log:

      2016-02-13 21:28:47 7fc4d5e96b00  InnoDB: Dump of the ibuf bitmap page:
      2016-02-13 21:28:47 7fc4d5e96b00 InnoDB: Page dump in ascii and hex (16384 bytes):
       len 16384; hex 4324d13a000000010000000000000000000000000caec7a90005...
      InnoDB: End of page dump
      2016-02-13 21:28:47 7fc4d5e96b00 InnoDB: uncompressed page, stored checksum i
      n field1 1676373080, calculated checksums for field1: crc32 607276543, innodb
       237301233, none 3735928559, stored checksum in field2 4195245356, calculated
       checksums for field2: crc32 607276543, innodb 4195245356, none 3735928559, p
      age LSN 0 212786341, low 4 bytes of LSN at page end 212786341, page number (i
      f stored to page already) 3, space id (if created with >= MySQL-4.1.1 and sto
      red already) 2039
      InnoDB: page type 17855 meaning INDEX
      InnoDB: Page may be an index page where index id is 13434390939941133065
      InnoDB: Error: corruption in the tablespace. Bitmap shows insert
      InnoDB: buffer records to page n:o 3 though the page
      InnoDB: type is 17855, which is not an index leaf page!
      InnoDB: We try to resolve the problem by skipping the insert buffer
      InnoDB: merge for this page. Please run CHECK TABLE on your tables
      InnoDB: to determine if they are corrupt after this.
      InnoDB: Please submit a detailed bug report to http://bugs.mysql.com
       
      InnoDB: Next record offset is nonsensical 57565 in record at offset 101
      InnoDB: rec address 0x7fc4bedac065, space id 2039, page 3
      2016-02-13 21:28:47 7fc4d5e96b00 InnoDB: Page dump in ascii and hex (16384 bytes):
       len 16384; hex 63eb6c5800000003ffffff...
      InnoDB: End of page dump
      2016-02-13 21:28:47 7fc4d5e96b00 InnoDB: uncompressed page, stored checksum in field1 1676373080, calculated checksums for field1: crc32 607276543, innodb 237301233, none 3735928559, stored checksum in field2 4195245356, calculated checksums for field2: crc32 607276543, innodb 4195245356, none 3735928559, page LSN 0 212786341, low 4 bytes of LSN at page end 212786341, page number (if stored to page already) 3, space id (if created with >= MySQL-4.1.1 and stored already) 2039
      InnoDB: page type 17855 meaning INDEX
      InnoDB: Page may be an index page where index id is 13434390939941133065
      2016-02-13 21:28:47 7fc4d5e96b00  InnoDB: Assertion failure in thread 140483379161856 in file page0page.ic line 780
      InnoDB: We intentionally generate a memory trap.
      InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
      InnoDB: If you get repeated assertion failures or crashes, even
      InnoDB: immediately after the mysqld startup, there may be
      InnoDB: corruption in the InnoDB tablespace. Please refer to
      InnoDB: http://dev.mysql.com/doc/refman/5.6/en/forcing-innodb-recovery.html
      InnoDB: about forcing recovery.
      160213 21:28:47 [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 http://kb.askmonty.org/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.1.11-MariaDB-log
      key_buffer_size=134217728
      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 = 467110 K  bytes of memory
      Hope that's ok; if not, decrease some variables in the equation.
       
      Thread pointer: 0x0x7fc4b6a71008
      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 = 0x7fc4d5e96130 thread_stack 0x48400
      /usr/sbin/mysqld(my_print_stacktrace+0x2e)[0x7fc4d69e0cce]
      /usr/sbin/mysqld(handle_fatal_signal+0x38d)[0x7fc4d650e49d]
      /lib64/libpthread.so.0(+0xf100)[0x7fc4d5b2e100]
      /lib64/libc.so.6(gsignal+0x37)[0x7fc4d3c865f7]
      mysys/stacktrace.c:247(my_print_stacktrace)[0x7fc4d3c87ce8]
      include/page0page.ic:780(page_rec_get_next_low)[0x7fc4d67b6c89]
      row/row0sel.cc:4189(row_search_for_mysql(unsigned char*, unsigned long, row_prebuilt_t*, unsigned long, unsigned long))[0x7fc4d6751f10]
      handler/ha_innodb.cc:9603(ha_innobase::index_read(unsigned char*, unsigned char const*, unsigned int, ha_rkey_function))[0x7fc4d668c9da]
      handler/ha_innodb.cc:10033(ha_innobase::index_first(unsigned char*))[0x7fc4d66721e7]
      handler/ha_innodb.cc:10126(ha_innobase::rnd_next(unsigned char*))[0x7fc4d668e8ca]
      sql/handler.cc:2577(handler::ha_rnd_next(unsigned char*))[0x7fc4d6512d37]
      sql/records.cc:470(rr_sequential(READ_RECORD*))[0x7fc4d6615580]
      /usr/sbin/mysqld(_Z10sub_selectP4JOINP13st_join_tableb+0x169)[0x7fc4d63c7eb9]
      sql/sql_select.cc:18279(sub_select(JOIN*, st_join_table*, bool))[0x7fc4d63d5b0d]
      sql/sql_select.cc:3228(JOIN::exec_inner())[0x7fc4d63e585c]
      sql/sql_select.cc:2519(JOIN::exec())[0x7fc4d63e7854]
      sql/sql_select.cc:3453(mysql_select(THD*, Item***, 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*))[0x7fc4d63e3ef2]
      sql/sql_select.cc:384(handle_select(THD*, LEX*, select_result*, unsigned long))[0x7fc4d63e49d5]
      /usr/sbin/mysqld(+0x428521)[0x7fc4d6387521]
      sql/sql_parse.cc:5904(execute_sqlcom_select)[0x7fc4d63930f1]
      sql/sql_parse.cc:7304(mysql_parse(THD*, char*, unsigned int, Parser_state*))[0x7fc4d639686e]
      sql/sql_parse.cc:1488(dispatch_command(enum_server_command, THD*, char*, unsigned int))[0x7fc4d6399d2b]
      sql/sql_parse.cc:1111(do_command(THD*))[0x7fc4d639a5a9]
      sql/sql_connect.cc:1349(do_handle_one_connection(THD*))[0x7fc4d645d78a]
      sql/sql_connect.cc:1263(handle_one_connection)[0x7fc4d645d960]
      /lib64/libpthread.so.0(+0x7dc5)[0x7fc4d5b26dc5]
      /lib64/libc.so.6(clone+0x6d)[0x7fc4d3d4721d]
       
      Trying to get some variables.
      Some pointers may be invalid and cause the dump to abort.
      Query (0x7fc4b6af6020): select * from mysqlslap.t5
      Connection ID (thread ID): 3
      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
       
      The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
      information that should help you find out what is causing the crash.

      Note it is recoverable in this case by changing back the configs in the my.cnf:

      plugin-load-add=file_key_management.so
      file-key-management-filename = /var/lib/mysql/keys.txt
      innodb-encrypt-tables

      Restarting the server:

      service mysql restart
      Restarting mysql (via systemctl):                          [  OK  ]

      Selecting from the encrypted table:

      MariaDB [(none)]> select * from mysqlslap.t5 limit 1\G
      *************************** 1. row ***************************
       intcol1: 1
       intcol2: 2
      charcol1: maria
      charcol2: db
      charcol3: encryption

      Attachments

        Activity

          People

            jplindst Jan Lindström (Inactive)
            valerie@opengroupware.ch Valerie Parham-Thompson
            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.