Skip to content

Commit 8815fb3

Browse files
committed
MDEV-8158 InnoDB: Failing assertion: new_state->key_version != ENCRYPTION_KEY_VERSION_INVALID on dynamic change of encryption variables
don't allow to enable srv_encrypt_tables if no encryption plugin is loaded
1 parent 8827eb8 commit 8815fb3

File tree

4 files changed

+119
-6
lines changed

4 files changed

+119
-6
lines changed

mysql-test/suite/sys_vars/r/innodb_encrypt_tables_basic.result

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,23 @@ where variable_name='innodb_encrypt_tables';
1919
VARIABLE_NAME VARIABLE_VALUE
2020
INNODB_ENCRYPT_TABLES OFF
2121
set global innodb_encrypt_tables=ON;
22+
ERROR 42000: Variable 'innodb_encrypt_tables' can't be set to the value of 'ON'
23+
show warnings;
24+
Level Code Message
25+
Warning 138 InnoDB: cannot enable encryption, encryption plugin is not available
26+
Error 1231 Variable 'innodb_encrypt_tables' can't be set to the value of 'ON'
2227
select @@global.innodb_encrypt_tables;
2328
@@global.innodb_encrypt_tables
24-
ON
29+
OFF
2530
set global innodb_encrypt_tables=OFF;
2631
select @@global.innodb_encrypt_tables;
2732
@@global.innodb_encrypt_tables
2833
OFF
2934
set global innodb_encrypt_tables=1;
35+
ERROR 42000: Variable 'innodb_encrypt_tables' can't be set to the value of '1'
3036
select @@global.innodb_encrypt_tables;
3137
@@global.innodb_encrypt_tables
32-
ON
38+
OFF
3339
set session innodb_encrypt_tables=1;
3440
ERROR HY000: Variable 'innodb_encrypt_tables' is a GLOBAL variable and should be set with SET GLOBAL
3541
set global innodb_encrypt_tables=1.1;

mysql-test/suite/sys_vars/t/innodb_encrypt_tables_basic.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ where variable_name='innodb_encrypt_tables';
1919
#
2020
# show that it's writable
2121
#
22+
--error ER_WRONG_VALUE_FOR_VAR
2223
set global innodb_encrypt_tables=ON;
24+
show warnings;
2325
select @@global.innodb_encrypt_tables;
2426
set global innodb_encrypt_tables=OFF;
2527
select @@global.innodb_encrypt_tables;
28+
--error ER_WRONG_VALUE_FOR_VAR
2629
set global innodb_encrypt_tables=1;
2730
select @@global.innodb_encrypt_tables;
2831
--error ER_GLOBAL_VARIABLE

storage/innobase/handler/ha_innodb.cc

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,10 @@ ib_cb_t innodb_api_cb[] = {
547547
(ib_cb_t) ib_cursor_stmt_begin
548548
};
549549

550+
551+
static void innodb_remember_check_sysvar_funcs();
552+
mysql_var_check_func check_sysvar_enum;
553+
550554
static MYSQL_THDVAR_UINT(default_encryption_key_id, PLUGIN_VAR_RQCMDARG,
551555
"Default encryption key id used for table encryption.",
552556
NULL, NULL,
@@ -637,6 +641,17 @@ static ibool innodb_have_lzma=IF_LZMA(1, 0);
637641
static ibool innodb_have_bzip2=IF_BZIP2(1, 0);
638642
static ibool innodb_have_snappy=IF_SNAPPY(1, 0);
639643

644+
static
645+
int
646+
innodb_encrypt_tables_validate(
647+
/*==================================*/
648+
THD* thd, /*!< in: thread handle */
649+
struct st_mysql_sys_var* var, /*!< in: pointer to system
650+
variable */
651+
void* save, /*!< out: immediate result
652+
for update function */
653+
struct st_mysql_value* value); /*!< in: incoming string */
654+
640655
static const char innobase_hton_name[]= "InnoDB";
641656

642657
static MYSQL_THDVAR_BOOL(support_xa, PLUGIN_VAR_OPCMDARG,
@@ -3157,6 +3172,8 @@ innobase_init(
31573172

31583173
innobase_hton->table_options = innodb_table_option_list;
31593174

3175+
innodb_remember_check_sysvar_funcs();
3176+
31603177
ut_a(DATA_MYSQL_TRUE_VARCHAR == (ulint)MYSQL_TYPE_VARCHAR);
31613178

31623179
#ifndef DBUG_OFF
@@ -19165,8 +19182,9 @@ static TYPELIB srv_encrypt_tables_typelib = {
1916519182
static MYSQL_SYSVAR_ENUM(encrypt_tables, srv_encrypt_tables,
1916619183
PLUGIN_VAR_OPCMDARG,
1916719184
"Enable encryption for tables. "
19168-
"Don't forget to enable --innodb-encrypt-log too",
19169-
NULL, NULL, 0, &srv_encrypt_tables_typelib);
19185+
"Don't forget to enable --innodb-encrypt-log too",
19186+
innodb_encrypt_tables_validate, NULL, 0,
19187+
&srv_encrypt_tables_typelib);
1917019188

1917119189
static MYSQL_SYSVAR_UINT(encryption_threads, srv_n_fil_crypt_threads,
1917219190
PLUGIN_VAR_RQCMDARG,
@@ -20099,3 +20117,37 @@ innodb_compression_algorithm_validate(
2009920117
#endif
2010020118
DBUG_RETURN(0);
2010120119
}
20120+
20121+
static
20122+
int
20123+
innodb_encrypt_tables_validate(
20124+
/*=================================*/
20125+
THD* thd, /*!< in: thread handle */
20126+
struct st_mysql_sys_var* var, /*!< in: pointer to system
20127+
variable */
20128+
void* save, /*!< out: immediate result
20129+
for update function */
20130+
struct st_mysql_value* value) /*!< in: incoming string */
20131+
{
20132+
if (check_sysvar_enum(thd, var, save, value))
20133+
return 1;
20134+
20135+
long encrypt_tables = *(long*)save;
20136+
20137+
if (encrypt_tables
20138+
&& !encryption_key_id_exists(FIL_DEFAULT_ENCRYPTION_KEY)) {
20139+
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
20140+
HA_ERR_UNSUPPORTED,
20141+
"InnoDB: cannot enable encryption, "
20142+
"encryption plugin is not available");
20143+
return 1;
20144+
}
20145+
return 0;
20146+
}
20147+
20148+
static void innodb_remember_check_sysvar_funcs()
20149+
{
20150+
/* remember build-in sysvar check functions */
20151+
ut_ad((MYSQL_SYSVAR_NAME(checksum_algorithm).flags & 0x1FF) == PLUGIN_VAR_ENUM);
20152+
check_sysvar_enum = MYSQL_SYSVAR_NAME(checksum_algorithm).check;
20153+
}

storage/xtradb/handler/ha_innodb.cc

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,10 @@ ib_cb_t innodb_api_cb[] = {
612612
(ib_cb_t) ib_cursor_stmt_begin
613613
};
614614

615+
616+
static void innodb_remember_check_sysvar_funcs();
617+
mysql_var_check_func check_sysvar_enum;
618+
615619
static MYSQL_THDVAR_UINT(default_encryption_key_id, PLUGIN_VAR_RQCMDARG,
616620
"Default encryption key id used for table encryption.",
617621
NULL, NULL,
@@ -727,6 +731,17 @@ innodb_compression_algorithm_validate(
727731
for update function */
728732
struct st_mysql_value* value); /*!< in: incoming string */
729733

734+
static
735+
int
736+
innodb_encrypt_tables_validate(
737+
/*==================================*/
738+
THD* thd, /*!< in: thread handle */
739+
struct st_mysql_sys_var* var, /*!< in: pointer to system
740+
variable */
741+
void* save, /*!< out: immediate result
742+
for update function */
743+
struct st_mysql_value* value); /*!< in: incoming string */
744+
730745
static const char innobase_hton_name[]= "InnoDB";
731746

732747
static MYSQL_THDVAR_BOOL(support_xa, PLUGIN_VAR_OPCMDARG,
@@ -3503,6 +3518,8 @@ innobase_init(
35033518
innobase_hton->fake_trx_id=wsrep_fake_trx_id;
35043519
#endif /* WITH_WSREP */
35053520

3521+
innodb_remember_check_sysvar_funcs();
3522+
35063523
ut_a(DATA_MYSQL_TRUE_VARCHAR == (ulint)MYSQL_TYPE_VARCHAR);
35073524

35083525
#ifndef DBUG_OFF
@@ -20347,8 +20364,9 @@ static TYPELIB srv_encrypt_tables_typelib = {
2034720364
static MYSQL_SYSVAR_ENUM(encrypt_tables, srv_encrypt_tables,
2034820365
PLUGIN_VAR_OPCMDARG,
2034920366
"Enable encryption for tables. "
20350-
"Don't forget to enable --innodb-encrypt-log too",
20351-
NULL, NULL, 0, &srv_encrypt_tables_typelib);
20367+
"Don't forget to enable --innodb-encrypt-log too",
20368+
innodb_encrypt_tables_validate, NULL, 0,
20369+
&srv_encrypt_tables_typelib);
2035220370

2035320371
static MYSQL_SYSVAR_UINT(encryption_threads, srv_n_fil_crypt_threads,
2035420372
PLUGIN_VAR_RQCMDARG,
@@ -21327,3 +21345,37 @@ innodb_compression_algorithm_validate(
2132721345
#endif
2132821346
DBUG_RETURN(0);
2132921347
}
21348+
21349+
static
21350+
int
21351+
innodb_encrypt_tables_validate(
21352+
/*=================================*/
21353+
THD* thd, /*!< in: thread handle */
21354+
struct st_mysql_sys_var* var, /*!< in: pointer to system
21355+
variable */
21356+
void* save, /*!< out: immediate result
21357+
for update function */
21358+
struct st_mysql_value* value) /*!< in: incoming string */
21359+
{
21360+
if (check_sysvar_enum(thd, var, save, value))
21361+
return 1;
21362+
21363+
long encrypt_tables = *(long*)save;
21364+
21365+
if (encrypt_tables
21366+
&& !encryption_key_id_exists(FIL_DEFAULT_ENCRYPTION_KEY)) {
21367+
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
21368+
HA_ERR_UNSUPPORTED,
21369+
"InnoDB: cannot enable encryption, "
21370+
"encryption plugin is not available");
21371+
return 1;
21372+
}
21373+
return 0;
21374+
}
21375+
21376+
static void innodb_remember_check_sysvar_funcs()
21377+
{
21378+
/* remember build-in sysvar check functions */
21379+
ut_ad((MYSQL_SYSVAR_NAME(checksum_algorithm).flags & 0x1FF) == PLUGIN_VAR_ENUM);
21380+
check_sysvar_enum = MYSQL_SYSVAR_NAME(checksum_algorithm).check;
21381+
}

0 commit comments

Comments
 (0)