From 5099d6de61fd03b8225dfba9e4becb13b5a74c67 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 8 Aug 2017 14:52:08 +0200 Subject: [PATCH] MDEV-12863 No table can be created after second encryption plugin attempted to load when deinitializing encryption plugins, disable server-wide encryption only if this plugin is the one that is used for encryption. --- .../encryption/r/second_plugin-12863.result | 7 +++++++ .../encryption/t/second_plugin-12863.test | 16 +++++++++++++++ sql/encryption.cc | 20 +++++++++++++------ 3 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 mysql-test/suite/encryption/r/second_plugin-12863.result create mode 100644 mysql-test/suite/encryption/t/second_plugin-12863.test diff --git a/mysql-test/suite/encryption/r/second_plugin-12863.result b/mysql-test/suite/encryption/r/second_plugin-12863.result new file mode 100644 index 00000000000..8775b1b8fb3 --- /dev/null +++ b/mysql-test/suite/encryption/r/second_plugin-12863.result @@ -0,0 +1,7 @@ +call mtr.add_suppression('debug.key.management'); +install soname 'debug_key_management'; +ERROR HY000: Can't initialize function 'debug_key_management'; Plugin initialization function failed. +create table t1 (a varchar(255)) engine=innodb encrypted=yes; +create table t2 (a varchar(255)) engine=innodb; +create table t3 (a varchar(255)) engine=innodb encrypted=no; +drop table t1, t2, t3; diff --git a/mysql-test/suite/encryption/t/second_plugin-12863.test b/mysql-test/suite/encryption/t/second_plugin-12863.test new file mode 100644 index 00000000000..c04fccf9716 --- /dev/null +++ b/mysql-test/suite/encryption/t/second_plugin-12863.test @@ -0,0 +1,16 @@ +# +# MDEV-12863 No table can be created after second encryption plugin attempted to load +# +--source include/have_innodb.inc +--source include/have_file_key_management_plugin.inc + +call mtr.add_suppression('debug.key.management'); + +--error 1123 +install soname 'debug_key_management'; + +create table t1 (a varchar(255)) engine=innodb encrypted=yes; +create table t2 (a varchar(255)) engine=innodb; +create table t3 (a varchar(255)) engine=innodb encrypted=no; + +drop table t1, t2, t3; diff --git a/sql/encryption.cc b/sql/encryption.cc index a92296e8b66..52eab262570 100644 --- a/sql/encryption.cc +++ b/sql/encryption.cc @@ -98,19 +98,27 @@ int initialize_encryption_plugin(st_plugin_int *plugin) int finalize_encryption_plugin(st_plugin_int *plugin) { - encryption_handler.encryption_key_get_func= - (uint (*)(uint, uint, uchar*, uint*))no_key; - encryption_handler.encryption_key_get_latest_version_func= no_key; - encryption_handler.encryption_ctx_size_func= zero_size; + bool used= plugin_ref_to_int(encryption_manager) == plugin; + + if (used) + { + encryption_handler.encryption_key_get_func= + (uint (*)(uint, uint, uchar*, uint*))no_key; + encryption_handler.encryption_key_get_latest_version_func= no_key; + encryption_handler.encryption_ctx_size_func= zero_size; + } if (plugin && plugin->plugin->deinit && plugin->plugin->deinit(NULL)) { DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.", plugin->name.str)); } - if (encryption_manager) + + if (used) + { plugin_unlock(NULL, encryption_manager); - encryption_manager= 0; + encryption_manager= 0; + } return 0; }