Skip to content

Commit 37a65e3

Browse files
author
Jan Lindström
committed
MDEV-9793: getting mysqld crypto key from key version failed
Make sure that we read all possible encryption keys from checkpoint and if log block checksum does not match, print all found checkpoint encryption keys.
1 parent 4ddb9de commit 37a65e3

File tree

6 files changed

+78
-6
lines changed

6 files changed

+78
-6
lines changed

storage/innobase/include/log0crypt.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (C) 2013, 2015, Google Inc. All Rights Reserved.
4-
Copyright (C) 2014, 2015, MariaDB Corporation. All Rights Reserved.
4+
Copyright (C) 2014, 2016, MariaDB Corporation. All Rights Reserved.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -117,4 +117,12 @@ log_crypt_print_error(
117117
/*==================*/
118118
log_crypt_err_t err_info); /*!< out: error info */
119119

120+
/*********************************************************************//**
121+
Print checkpoint no from log block and all encryption keys from
122+
checkpoints if they are present. Used for problem analysis. */
123+
void
124+
log_crypt_print_checkpoint_keys(
125+
/*============================*/
126+
const byte* log_block);
127+
120128
#endif // log0crypt.h

storage/innobase/log/log0crypt.cc

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,34 @@ static
127127
const crypt_info_t*
128128
get_crypt_info(
129129
/*===========*/
130-
const byte* log_block) {
130+
const byte* log_block)
131+
{
131132
ib_uint64_t checkpoint_no = log_block_get_checkpoint_no(log_block);
132133
return get_crypt_info(checkpoint_no);
133134
}
134135

136+
/*********************************************************************//**
137+
Print checkpoint no from log block and all encryption keys from
138+
checkpoints if they are present. Used for problem analysis. */
139+
void
140+
log_crypt_print_checkpoint_keys(
141+
/*============================*/
142+
const byte* log_block)
143+
{
144+
ib_uint64_t checkpoint_no = log_block_get_checkpoint_no(log_block);
145+
146+
if (crypt_info.size()) {
147+
fprintf(stderr, "InnoDB: redo log checkpoint: %lu [ chk key ]: ", checkpoint_no);
148+
for (size_t i = 0; i < crypt_info.size(); i++) {
149+
struct crypt_info_t* it = &crypt_info[i];
150+
fprintf(stderr, "[ %lu %u ] ",
151+
it->checkpoint_no,
152+
it->key_version);
153+
}
154+
fprintf(stderr, "\n");
155+
}
156+
}
157+
135158
/*********************************************************************//**
136159
Call AES CTR to encrypt/decrypt log blocks. */
137160
static
@@ -280,10 +303,13 @@ static
280303
bool
281304
add_crypt_info(crypt_info_t* info)
282305
{
306+
const crypt_info_t* found=NULL;
283307
/* so that no one is searching array while we modify it */
284308
ut_ad(mutex_own(&(log_sys->mutex)));
285309

286-
if (get_crypt_info(info->checkpoint_no) != NULL) {
310+
found = get_crypt_info(info->checkpoint_no);
311+
312+
if (found != NULL && found->checkpoint_no == info->checkpoint_no) {
287313
// already present...
288314
return true;
289315
}

storage/innobase/log/log0recv.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2714,6 +2714,8 @@ recv_scan_log_recs(
27142714

27152715
/* Garbage or an incompletely written log block */
27162716

2717+
/* Print checkpoint encryption keys if present */
2718+
log_crypt_print_checkpoint_keys(log_block);
27172719
finished = TRUE;
27182720

27192721
if (maybe_encrypted) {

storage/xtradb/include/log0crypt.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (C) 2013, 2015, Google Inc. All Rights Reserved.
4-
Copyright (C) 2014, 2015, MariaDB Corporation. All Rights Reserved.
4+
Copyright (C) 2014, 2016, MariaDB Corporation. All Rights Reserved.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -117,4 +117,12 @@ log_crypt_print_error(
117117
/*==================*/
118118
log_crypt_err_t err_info); /*!< out: error info */
119119

120+
/*********************************************************************//**
121+
Print checkpoint no from log block and all encryption keys from
122+
checkpoints if they are present. Used for problem analysis. */
123+
void
124+
log_crypt_print_checkpoint_keys(
125+
/*============================*/
126+
const byte* log_block);
127+
120128
#endif // log0crypt.h

storage/xtradb/log/log0crypt.cc

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,34 @@ static
127127
const crypt_info_t*
128128
get_crypt_info(
129129
/*===========*/
130-
const byte* log_block) {
130+
const byte* log_block)
131+
{
131132
ib_uint64_t checkpoint_no = log_block_get_checkpoint_no(log_block);
132133
return get_crypt_info(checkpoint_no);
133134
}
134135

136+
/*********************************************************************//**
137+
Print checkpoint no from log block and all encryption keys from
138+
checkpoints if they are present. Used for problem analysis. */
139+
void
140+
log_crypt_print_checkpoint_keys(
141+
/*============================*/
142+
const byte* log_block)
143+
{
144+
ib_uint64_t checkpoint_no = log_block_get_checkpoint_no(log_block);
145+
146+
if (crypt_info.size()) {
147+
fprintf(stderr, "InnoDB: redo log checkpoint: %lu [ chk key ]: ", checkpoint_no);
148+
for (size_t i = 0; i < crypt_info.size(); i++) {
149+
struct crypt_info_t* it = &crypt_info[i];
150+
fprintf(stderr, "[ %lu %u ] ",
151+
it->checkpoint_no,
152+
it->key_version);
153+
}
154+
fprintf(stderr, "\n");
155+
}
156+
}
157+
135158
/*********************************************************************//**
136159
Call AES CTR to encrypt/decrypt log blocks. */
137160
static
@@ -280,10 +303,13 @@ static
280303
bool
281304
add_crypt_info(crypt_info_t* info)
282305
{
306+
const crypt_info_t* found=NULL;
283307
/* so that no one is searching array while we modify it */
284308
ut_ad(mutex_own(&(log_sys->mutex)));
285309

286-
if (get_crypt_info(info->checkpoint_no) != NULL) {
310+
found = get_crypt_info(info->checkpoint_no);
311+
312+
if (found != NULL && found->checkpoint_no == info->checkpoint_no) {
287313
// already present...
288314
return true;
289315
}

storage/xtradb/log/log0recv.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2786,6 +2786,8 @@ recv_scan_log_recs(
27862786

27872787
/* Garbage or an incompletely written log block */
27882788

2789+
/* Print checkpoint encryption keys if present */
2790+
log_crypt_print_checkpoint_keys(log_block);
27892791
finished = TRUE;
27902792

27912793
if (maybe_encrypted) {

0 commit comments

Comments
 (0)