Skip to content

Commit 57b94de

Browse files
PS-8428 postfix: ALTER TABLE t ADD FULLTEXT crashes the server when --innodb_encrypt_online_alter_logs=ON (percona#4917)
https://jira.percona.com/browse/PS-8428 Original assumption that legacy Percona-specific encryption functions use only 256-bit primitives turned out to be wrong. Restored 'key_length' parameter in the - 'my_legacy_aes_256_cbc_nopad_encrypt()' - 'my_legacy_aes_256_cbc_nopad_decrypt()' - 'my_legacy_aes_256_cbc_nopad_crypt()' Functions themselves renamed to - 'my_legacy_aes_cbc_nopad_encrypt()' - 'my_legacy_aes_cbc_nopad_decrypt()' - 'my_legacy_aes_cbc_nopad_crypt()' 'percona_rpl_encryption_master_binlog_ps_encrypted' and 'rpl.percona_rpl_encryption_slave_binlog_ps_encrypted' MTR test cases now pass as expected.
1 parent d3581e9 commit 57b94de

File tree

4 files changed

+46
-41
lines changed

4 files changed

+46
-41
lines changed

include/my_aes.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,39 +138,39 @@ longlong my_aes_get_size(uint32 source_length, enum my_aes_opmode opmode);
138138
bool my_aes_needs_iv(my_aes_opmode opmode);
139139

140140
/**
141-
Encrypt a buffer using AES 256-bit CBC with no padding
141+
Encrypt a buffer using AES CBC with no padding
142142
143143
@param [in] source Pointer to data for encryption
144144
@param [in] source_length Size of original data
145145
@param [out] dest Buffer to place encrypted data (must be large
146146
enough)
147-
@param [in] key 32-bytes key to be used for encryption
147+
@param [in] key Key to be used for encryption
148+
@param [in] key_length Size of the key
148149
@param [in] iv 16-bytes initialization vector.
149150
@return size of encrypted data, or MY_AES_BAD_DATA in case of an error
150151
*/
151152

152-
int my_legacy_aes_256_cbc_nopad_encrypt(const unsigned char *source,
153-
uint32 source_length,
154-
unsigned char *dest,
155-
const unsigned char *key,
156-
const unsigned char *iv);
153+
int my_legacy_aes_cbc_nopad_encrypt(const unsigned char *source,
154+
uint32 source_length, unsigned char *dest,
155+
const unsigned char *key, uint32 key_length,
156+
const unsigned char *iv);
157157

158158
/**
159-
Decrypt a buffer encrypted with AES 256-bit CBC with no padding
159+
Decrypt a buffer encrypted with AES CBC with no padding
160160
161161
@param [in] source Pointer to data for decryption
162162
@param [in] source_length size of encrypted data
163163
@param [out] dest buffer to place decrypted data (must be large
164164
enough)
165-
@param [in] key 32-bytes key to be used for decryption
165+
@param [in] key Key to be used for decryption
166+
@param [in] key_length Size of the key
166167
@param [in] iv 16-bytes initialization vector
167168
@return size of original data, or MY_AES_BAD_DATA in case of an error
168169
*/
169170

170-
int my_legacy_aes_256_cbc_nopad_decrypt(const unsigned char *source,
171-
uint32 source_length,
172-
unsigned char *dest,
173-
const unsigned char *key,
174-
const unsigned char *iv);
171+
int my_legacy_aes_cbc_nopad_decrypt(const unsigned char *source,
172+
uint32 source_length, unsigned char *dest,
173+
const unsigned char *key, uint32 key_length,
174+
const unsigned char *iv);
175175

176176
#endif /* MY_AES_INCLUDED */

mysys/my_aes_openssl.cc

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,17 @@ bool my_aes_needs_iv(my_aes_opmode opmode) {
263263
assert(iv_length == 0 || iv_length == MY_AES_IV_SIZE);
264264
return iv_length != 0 ? true : false;
265265
}
266-
static int my_legacy_aes_256_cbc_nopad_crypt(
266+
267+
static int my_legacy_aes_cbc_nopad_crypt(
267268
bool encrypt, const unsigned char *source, uint32 source_length,
268-
unsigned char *dest, const unsigned char *key, const unsigned char *iv) {
269+
unsigned char *dest, const unsigned char *key, uint32 key_length,
270+
const unsigned char *iv) {
271+
assert(key_length == 32 || key_length == 16);
272+
269273
if (key == nullptr || iv == nullptr) return MY_AES_BAD_DATA;
270274

271-
auto cipher = aes_evp_type(my_aes_256_cbc);
275+
auto cipher =
276+
aes_evp_type(key_length == 32 ? my_aes_256_cbc : my_aes_128_cbc);
272277
assert(cipher != nullptr);
273278

274279
auto evp_cipher_deleter = [](EVP_CIPHER_CTX *ctx) {
@@ -319,8 +324,9 @@ static int my_legacy_aes_256_cbc_nopad_crypt(
319324
*/
320325
unsigned char mask[MY_AES_BLOCK_SIZE];
321326

322-
int mask_result = my_aes_encrypt(iv, sizeof(mask), mask, key, 32,
323-
my_aes_256_ecb, nullptr, false);
327+
int mask_result = my_aes_encrypt(
328+
iv, sizeof(mask), mask, key, key_length,
329+
key_length == 32 ? my_aes_256_ecb : my_aes_128_ecb, nullptr, false);
324330
if (mask_result != MY_AES_BLOCK_SIZE)
325331
return clear_error_helper(MY_AES_BAD_DATA);
326332

@@ -332,20 +338,18 @@ static int my_legacy_aes_256_cbc_nopad_crypt(
332338
return clear_error_helper(u_len + f_len);
333339
}
334340

335-
int my_legacy_aes_256_cbc_nopad_encrypt(const unsigned char *source,
336-
uint32 source_length,
337-
unsigned char *dest,
338-
const unsigned char *key,
339-
const unsigned char *iv) {
340-
return my_legacy_aes_256_cbc_nopad_crypt(true, source, source_length, dest,
341-
key, iv);
341+
int my_legacy_aes_cbc_nopad_encrypt(const unsigned char *source,
342+
uint32 source_length, unsigned char *dest,
343+
const unsigned char *key, uint32 key_length,
344+
const unsigned char *iv) {
345+
return my_legacy_aes_cbc_nopad_crypt(true, source, source_length, dest, key,
346+
key_length, iv);
342347
}
343348

344-
int my_legacy_aes_256_cbc_nopad_decrypt(const unsigned char *source,
345-
uint32 source_length,
346-
unsigned char *dest,
347-
const unsigned char *key,
348-
const unsigned char *iv) {
349-
return my_legacy_aes_256_cbc_nopad_crypt(false, source, source_length, dest,
350-
key, iv);
349+
int my_legacy_aes_cbc_nopad_decrypt(const unsigned char *source,
350+
uint32 source_length, unsigned char *dest,
351+
const unsigned char *key, uint32 key_length,
352+
const unsigned char *iv) {
353+
return my_legacy_aes_cbc_nopad_crypt(false, source, source_length, dest, key,
354+
key_length, iv);
351355
}

sql/event_crypt.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ bool decrypt_event(uint32 offs, const Binlog_crypt_data &crypto, uchar *buf,
1414
crypto.set_iv(iv, offs);
1515
memcpy(buf + EVENT_LEN_OFFSET, buf, 4);
1616

17-
assert(crypto.get_keys_length() == 32);
18-
if (my_legacy_aes_256_cbc_nopad_decrypt(buf + 4, buf_len - 4, ebuf + 4,
19-
crypto.get_key(), iv) !=
20-
static_cast<int>(buf_len - 4)) {
17+
if (my_legacy_aes_cbc_nopad_decrypt(
18+
buf + 4, buf_len - 4, ebuf + 4, crypto.get_key(),
19+
crypto.get_keys_length(), iv) != static_cast<int>(buf_len - 4)) {
2120
memcpy(buf, buf + EVENT_LEN_OFFSET, 4);
2221
return true;
2322
}

storage/innobase/row/row0log.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,9 @@ bool log_tmp_block_encrypt(const byte *src_block, ulint size, byte *dst_block,
314314
}
315315

316316
assert(crypt_info.encryption_klen == 32);
317-
int res = my_legacy_aes_256_cbc_nopad_encrypt(src_block, size, dst_block,
318-
crypt_info.encryption_key, iv);
317+
int res = my_legacy_aes_cbc_nopad_encrypt(src_block, size, dst_block,
318+
crypt_info.encryption_key,
319+
crypt_info.encryption_klen, iv);
319320

320321
if (res != static_cast<int>(size)) {
321322
ib::error() << "Unable to encrypt data block src: "
@@ -344,8 +345,9 @@ bool log_tmp_block_decrypt(const byte *src_block, ulint size, byte *dst_block,
344345
}
345346

346347
assert(crypt_info.encryption_klen == 32);
347-
int res = my_legacy_aes_256_cbc_nopad_decrypt(src_block, size, dst_block,
348-
crypt_info.encryption_key, iv);
348+
int res = my_legacy_aes_cbc_nopad_decrypt(src_block, size, dst_block,
349+
crypt_info.encryption_key,
350+
crypt_info.encryption_klen, iv);
349351

350352
if (res != static_cast<int>(size)) {
351353
ib::error() << "Unable to decrypt data block src: "

0 commit comments

Comments
 (0)