Skip to content

Commit 2af28a3

Browse files
committed
MDEV-11782: Redefine the innodb_encrypt_log format
Write only one encryption key to the checkpoint page. Use 4 bytes of nonce. Encrypt more of each redo log block, only skipping the 4-byte field LOG_BLOCK_HDR_NO which the initialization vector is derived from. Issue notes, not warning messages for rewriting the redo log files. recv_recovery_from_checkpoint_finish(): Do not generate any redo log, because we must avoid that before rewriting the redo log files, or otherwise a crash during a redo log rewrite (removing or adding encryption) may end up making the database unrecoverable. Instead, do these tasks in innobase_start_or_create_for_mysql(). Issue a firm "Missing MLOG_CHECKPOINT" error message. Remove some unreachable code and duplicated error messages for log corruption. LOG_HEADER_FORMAT_ENCRYPTED: A flag for identifying an encrypted redo log format. log_group_t::is_encrypted(), log_t::is_encrypted(): Determine if the redo log is in encrypted format. recv_find_max_checkpoint(): Interpret LOG_HEADER_FORMAT_ENCRYPTED. srv_prepare_to_delete_redo_log_files(): Display NOTE messages about adding or removing encryption. Do not issue warnings for redo log resizing any more. innobase_start_or_create_for_mysql(): Rebuild the redo logs also when the encryption changes. innodb_log_checksums_func_update(): Always use the CRC-32C checksum if innodb_encrypt_log. If needed, issue a warning that innodb_encrypt_log implies innodb_log_checksums. log_group_write_buf(): Compute the checksum on the encrypted block contents, so that transmission errors or incomplete blocks can be detected without decrypting. Rewrite most of the redo log encryption code. Only remember one encryption key at a time (but remember up to 5 when upgrading from the MariaDB 10.1 format.)
1 parent 743ac7c commit 2af28a3

34 files changed

+748
-1288
lines changed

mysql-test/mysql-test-run.pl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4345,10 +4345,7 @@ ($$)
43454345
qr/error .*connecting to master/,
43464346
qr/InnoDB: Error: in ALTER TABLE `test`.`t[12]`/,
43474347
qr/InnoDB: Error: table `test`.`t[12]` .*does not exist in the InnoDB internal/,
4348-
qr/InnoDB: Warning: Setting innodb_use_sys_malloc/,
43494348
qr/InnoDB: Warning: a long semaphore wait:/,
4350-
qr/InnoDB: Disabling redo log encryption/,
4351-
qr/InnoDB: Redo log crypto: Can't initialize to key version -1u/,
43524349
qr/InnoDB: Dumping buffer pool.*/,
43534350
qr/InnoDB: Buffer pool.*/,
43544351
qr/InnoDB: Warning: Writer thread is waiting this semaphore/,
@@ -4422,9 +4419,6 @@ ($$)
44224419
qr|InnoDB: TABLE to scan your table for corruption|,
44234420
qr/InnoDB: See also */,
44244421
qr/InnoDB: Cannot open .*ib_buffer_pool.* for reading: No such file or directory*/,
4425-
qr/InnoDB: Upgrading redo log:*/,
4426-
qr|InnoDB: Starting to delete and rewrite log files.|,
4427-
qr/InnoDB: New log files created, LSN=*/,
44284422
qr|InnoDB: Creating foreign key constraint system tables.|,
44294423
qr/InnoDB: Table .*mysql.*innodb_table_stats.* not found./,
44304424
qr/InnoDB: User stopword table .* does not exist./

mysql-test/suite/encryption/r/innodb-log-encrypt-crash.result

Lines changed: 0 additions & 19 deletions
This file was deleted.

mysql-test/suite/encryption/r/innodb-log-encrypt.result

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#
2+
# MDEV-9011: Redo log encryption does not work
3+
#
4+
#
5+
# MDEV-9422 Encrypted redo log checksum errors
6+
# on restart after killing busy server instance
7+
#
8+
SET GLOBAL innodb_log_checksums=0;
9+
Warnings:
10+
Warning 138 innodb_encrypt_log implies innodb_log_checksums
11+
SELECT @@global.innodb_log_checksums;
12+
@@global.innodb_log_checksums
13+
1
14+
CREATE TABLE t0 (
15+
pk bigint auto_increment,
16+
col_int int,
17+
col_int_key int,
18+
col_char char(12),
19+
col_char_key char(12),
20+
primary key (pk),
21+
key (col_int_key),
22+
key (col_char_key)
23+
) ENGINE=InnoDB ENCRYPTED=YES ENCRYPTION_KEY_ID=1;
24+
CREATE TEMPORARY TABLE t LIKE t0;
25+
INSERT INTO t VALUES
26+
(NULL,1,1,'private','secret'),(NULL,2,2,'sacred','success'),
27+
(NULL,3,3,'story','secure'),(NULL,4,4,'security','sacrament');
28+
SET GLOBAL innodb_flush_log_at_trx_commit=1;
29+
INSERT INTO t0
30+
SELECT NULL, t1.col_int, t1.col_int_key, t1.col_char, t1.col_char_key
31+
FROM t t1, t t2, t t3, t t4, t t5;
32+
# Kill the server
33+
# ibdata1 expecting NOT FOUND
34+
NOT FOUND /private|secret|sacr(ed|ament)|success|story|secur(e|ity)/ in ibdata1
35+
# t0.ibd expecting NOT FOUND
36+
NOT FOUND /private|secret|sacr(ed|ament)|success|story|secur(e|ity)/ in t0.ibd
37+
# ib_logfile0 expecting NOT FOUND
38+
NOT FOUND /private|secret|sacr(ed|ament)|success|story|secur(e|ity)/ in ib_logfile0
39+
# ib_logfile1 expecting NOT FOUND
40+
NOT FOUND /private|secret|sacr(ed|ament)|success|story|secur(e|ity)/ in ib_logfile1
41+
# Restart without redo log encryption
42+
SELECT COUNT(*) FROM t0;
43+
COUNT(*)
44+
1024
45+
CHECK TABLE t0;
46+
Table Op Msg_type Msg_text
47+
test.t0 check status OK
48+
SET GLOBAL innodb_flush_log_at_trx_commit=1;
49+
INSERT INTO t0 VALUES(NULL, 5, 5, 'public', 'gossip');
50+
# Kill the server
51+
# ib_logfile0 expecting NOT FOUND
52+
NOT FOUND /private|secret|sacr(ed|ament)|success|story|secur(e|ity)/ in ib_logfile0
53+
# ib_logfile0 expecting FOUND
54+
FOUND /public|gossip/ in ib_logfile0
55+
# ibdata1 expecting NOT FOUND
56+
NOT FOUND /private|secret|sacr(ed|ament)|success|story|secur(e|ity)|public|gossip/ in ibdata1
57+
# t0.ibd expecting NOT FOUND
58+
NOT FOUND /private|secret|sacr(ed|ament)|success|story|secur(e|ity)|public|gossip/ in t0.ibd
59+
SELECT COUNT(*) FROM t0;
60+
COUNT(*)
61+
1025
62+
CHECK TABLE t0;
63+
Table Op Msg_type Msg_text
64+
test.t0 check status OK
65+
DROP TABLE t0;

mysql-test/suite/encryption/r/innodb_encrypt_log_corruption.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ WHERE engine = 'innodb'
4141
AND support IN ('YES', 'DEFAULT', 'ENABLED');
4242
ENGINE SUPPORT COMMENT TRANSACTIONS XA SAVEPOINTS
4343
FOUND /InnoDB: Invalid log block checksum. block: 2372 checkpoint no: 1 expected: 3362026715 found: 144444122/ in mysqld.1.err
44-
FOUND /InnoDB: Ignoring the redo log due to missing MLOG_CHECKPOINT between the checkpoint 1213964 and the end 1213952\./ in mysqld.1.err
44+
FOUND /InnoDB: Missing MLOG_CHECKPOINT between the checkpoint 1213964 and the end 1213952\./ in mysqld.1.err
4545
# --innodb-force-recovery=6 (skip the entire redo log)
4646
SELECT * FROM INFORMATION_SCHEMA.ENGINES
4747
WHERE engine = 'innodb'
@@ -54,7 +54,6 @@ SELECT * FROM INFORMATION_SCHEMA.ENGINES
5454
WHERE engine = 'innodb'
5555
AND support IN ('YES', 'DEFAULT', 'ENABLED');
5656
ENGINE SUPPORT COMMENT TRANSACTIONS XA SAVEPOINTS
57-
FOUND /InnoDB: Ignoring the redo log due to missing MLOG_CHECKPOINT between the checkpoint 1213964 and the end 1213952\./ in mysqld.1.err
5857
# --innodb-force-recovery=6 (skip the entire redo log)
5958
SELECT * FROM INFORMATION_SCHEMA.ENGINES
6059
WHERE engine = 'innodb'
@@ -90,6 +89,7 @@ SELECT COUNT(*) `1` FROM INFORMATION_SCHEMA.ENGINES WHERE engine='innodb'
9089
AND support IN ('YES', 'DEFAULT', 'ENABLED');
9190
1
9291
1
92+
FOUND /InnoDB: Encrypting redo log/ in mysqld.1.err
9393
ib_buffer_pool
9494
ib_logfile0
9595
ib_logfile1

mysql-test/suite/encryption/t/innodb-log-encrypt-crash.opt

Lines changed: 0 additions & 6 deletions
This file was deleted.

mysql-test/suite/encryption/t/innodb-log-encrypt-crash.test

Lines changed: 0 additions & 41 deletions
This file was deleted.

mysql-test/suite/encryption/t/innodb-log-encrypt.test

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)