From fb252f70c17c0ade38082ca5db198dca68b810ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 14 Dec 2018 15:44:51 +0200 Subject: MDEV-12112 corruption in encrypted table may be overlooked After validating the post-encryption checksum on an encrypted page, Mariabackup should decrypt the page and validate the pre-encryption checksum as well. This should reduce the probability of accepting invalid pages as valid ones. This is a backport and refactoring of a patch that was originally written by Thirunarayanan Balathandayuthapani for the 10.2 branch. --- .../mariabackup/encrypted_page_corruption.opt | 6 +++ .../mariabackup/encrypted_page_corruption.result | 7 +++ .../mariabackup/encrypted_page_corruption.test | 50 ++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 mysql-test/suite/mariabackup/encrypted_page_corruption.opt create mode 100644 mysql-test/suite/mariabackup/encrypted_page_corruption.result create mode 100644 mysql-test/suite/mariabackup/encrypted_page_corruption.test (limited to 'mysql-test') diff --git a/mysql-test/suite/mariabackup/encrypted_page_corruption.opt b/mysql-test/suite/mariabackup/encrypted_page_corruption.opt new file mode 100644 index 00000000000..74a6450a1ef --- /dev/null +++ b/mysql-test/suite/mariabackup/encrypted_page_corruption.opt @@ -0,0 +1,6 @@ +--innodb-encrypt-log=ON +--plugin-load-add=$FILE_KEY_MANAGEMENT_SO +--loose-file-key-management +--loose-file-key-management-filekey=FILE:$MTR_SUITE_DIR/filekeys-data.key +--loose-file-key-management-filename=$MTR_SUITE_DIR/filekeys-data.enc +--loose-file-key-management-encryption-algorithm=aes_cbc diff --git a/mysql-test/suite/mariabackup/encrypted_page_corruption.result b/mysql-test/suite/mariabackup/encrypted_page_corruption.result new file mode 100644 index 00000000000..c985c48dbc0 --- /dev/null +++ b/mysql-test/suite/mariabackup/encrypted_page_corruption.result @@ -0,0 +1,7 @@ +call mtr.add_suppression("\\[ERROR\\] InnoDB: The page .* in file .* cannot be decrypted."); +CREATE TABLE t1(c VARCHAR(128)) ENGINE INNODB, encrypted=yes; +insert into t1 select repeat('a',100); +# Corrupt the table +# xtrabackup backup +FOUND /Database page corruption detected/ in backup.log +drop table t1; diff --git a/mysql-test/suite/mariabackup/encrypted_page_corruption.test b/mysql-test/suite/mariabackup/encrypted_page_corruption.test new file mode 100644 index 00000000000..f8f7bdb6567 --- /dev/null +++ b/mysql-test/suite/mariabackup/encrypted_page_corruption.test @@ -0,0 +1,50 @@ +--source include/have_file_key_management.inc + +call mtr.add_suppression("\\[ERROR\\] InnoDB: The page .* in file .* cannot be decrypted."); +CREATE TABLE t1(c VARCHAR(128)) ENGINE INNODB, encrypted=yes; +insert into t1 select repeat('a',100); + +let $MYSQLD_DATADIR=`select @@datadir`; +let t1_IBD = $MYSQLD_DATADIR/test/t1.ibd; + +--source include/shutdown_mysqld.inc + +--echo # Corrupt the table + +perl; +use strict; +use warnings; +use Fcntl qw(:DEFAULT :seek); + +my $ibd_file = $ENV{'t1_IBD'}; + +my $chunk; +my $len; + +sysopen IBD_FILE, $ibd_file, O_RDWR || die "Unable to open $ibd_file"; +sysseek IBD_FILE, 16384 * 3, SEEK_CUR; +$chunk = '\xAA\xAA\xAA\xAA'; +syswrite IBD_FILE, $chunk, 4; + +close IBD_FILE; +EOF + +--source include/start_mysqld.inc + +echo # xtrabackup backup; +let $targetdir=$MYSQLTEST_VARDIR/tmp/backup; +let $backuplog=$MYSQLTEST_VARDIR/tmp/backup.log; + +--disable_result_log +--error 1 +exec $XTRABACKUP --defaults-file=$MYSQLTEST_VARDIR/my.cnf --backup --target-dir=$targetdir > $backuplog; +--enable_result_log + + +--let SEARCH_PATTERN=Database page corruption detected +--let SEARCH_FILE=$backuplog +--source include/search_pattern_in_file.inc +remove_file $backuplog; + +drop table t1; +rmdir $targetdir; -- cgit v1.2.1