Skip to content

Commit 892c426

Browse files
committed
MDEV-13542: Do not crash on decryption failure
fil_page_type_validate(): Remove. This debug check was mostly redundant and added little value to the code paths that deal with page_compressed or encrypted pages. fil_get_page_type_name(): Remove; unused function. fil_space_decrypt(): Return an error if the page is not supposed to be encrypted. It is possible that an unencrypted page contains a nonzero key_version field even though it is not supposed to be encrypted. Previously we would crash in such a situation. buf_page_decrypt_after_read(): Simplify the code. Remove some unnecessary error message about temporary tablespace corruption. This is where we would usually invoke fil_space_decrypt().
1 parent c9498f3 commit 892c426

File tree

7 files changed

+22
-188
lines changed

7 files changed

+22
-188
lines changed

storage/innobase/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ SET(INNOBASE_SOURCES
128128
include/fil0crypt.h
129129
include/fil0crypt.inl
130130
include/fil0fil.h
131-
include/fil0fil.inl
132131
include/fil0pagecompress.h
133132
include/fsp0file.h
134133
include/fsp0fsp.h

storage/innobase/buf/buf0buf.cc

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -403,28 +403,22 @@ static bool buf_page_decrypt_after_read(buf_page_t *bpage,
403403
return (true);
404404
}
405405

406-
if (node.space->purpose == FIL_TYPE_TEMPORARY
406+
buf_tmp_buffer_t* slot;
407+
408+
if (id.space() == SRV_TMP_SPACE_ID
407409
&& innodb_encrypt_temporary_tables) {
408-
buf_tmp_buffer_t* slot = buf_pool.io_buf_reserve();
410+
slot = buf_pool.io_buf_reserve();
409411
ut_a(slot);
410412
slot->allocate();
411-
412-
if (!buf_tmp_page_decrypt(slot->crypt_buf, dst_frame)) {
413-
slot->release();
414-
ib::error() << "Encrypted page " << id
415-
<< " in file " << node.name;
416-
return false;
417-
}
418-
413+
bool ok = buf_tmp_page_decrypt(slot->crypt_buf, dst_frame);
419414
slot->release();
420-
return true;
415+
return ok;
421416
}
422417

423418
/* Page is encrypted if encryption information is found from
424419
tablespace and page contains used key_version. This is true
425420
also for pages first compressed and then encrypted. */
426421

427-
buf_tmp_buffer_t* slot;
428422
uint key_version = buf_page_get_key_version(dst_frame, flags);
429423

430424
if (page_compressed && !key_version) {
@@ -441,13 +435,9 @@ static bool buf_page_decrypt_after_read(buf_page_t *bpage,
441435
slot->allocate();
442436

443437
decompress_with_slot:
444-
ut_d(fil_page_type_validate(node.space, dst_frame));
445-
446438
ulint write_size = fil_page_decompress(
447439
slot->crypt_buf, dst_frame, flags);
448440
slot->release();
449-
ut_ad(!write_size
450-
|| fil_page_type_validate(node.space, dst_frame));
451441
ut_ad(node.space->referenced());
452442
return write_size != 0;
453443
}
@@ -467,16 +457,13 @@ static bool buf_page_decrypt_after_read(buf_page_t *bpage,
467457
slot = buf_pool.io_buf_reserve();
468458
ut_a(slot);
469459
slot->allocate();
470-
ut_d(fil_page_type_validate(node.space, dst_frame));
471460

472461
/* decrypt using crypt_buf to dst_frame */
473462
if (!fil_space_decrypt(node.space, slot->crypt_buf, dst_frame)) {
474463
slot->release();
475464
goto decrypt_failed;
476465
}
477466

478-
ut_d(fil_page_type_validate(node.space, dst_frame));
479-
480467
if ((fil_space_t::full_crc32(flags) && page_compressed)
481468
|| fil_page_get_type(dst_frame)
482469
== FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED) {

storage/innobase/buf/buf0flu.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,6 @@ static byte *buf_page_encrypt(fil_space_t* space, buf_page_t* bpage, byte* s,
625625
ut_ad(space->id == bpage->id().space());
626626
ut_ad(!*slot);
627627

628-
ut_d(fil_page_type_validate(space, s));
629628
const uint32_t page_no= bpage->id().page_no();
630629

631630
switch (page_no) {
@@ -722,7 +721,6 @@ static byte *buf_page_encrypt(fil_space_t* space, buf_page_t* bpage, byte* s,
722721

723722
/* Workaround for MDEV-15527. */
724723
memset(tmp + len, 0 , srv_page_size - len);
725-
ut_d(fil_page_type_validate(space, tmp));
726724

727725
if (encrypted)
728726
tmp= fil_space_encrypt(space, page_no, tmp, d);
@@ -737,7 +735,6 @@ static byte *buf_page_encrypt(fil_space_t* space, buf_page_t* bpage, byte* s,
737735
d= tmp;
738736
}
739737

740-
ut_d(fil_page_type_validate(space, d));
741738
(*slot)->out_buf= d;
742739
return d;
743740
}

storage/innobase/fil/fil0crypt.cc

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,7 @@ static dberr_t fil_space_decrypt_full_crc32(
640640
lsn_t lsn = mach_read_from_8(src_frame + FIL_PAGE_LSN);
641641
uint offset = mach_read_from_4(src_frame + FIL_PAGE_OFFSET);
642642

643-
ut_a(key_version != ENCRYPTION_KEY_NOT_ENCRYPTED);
644-
645-
ut_ad(crypt_data);
646-
ut_ad(crypt_data->is_encrypted());
643+
ut_ad(key_version != ENCRYPTION_KEY_NOT_ENCRYPTED);
647644

648645
memcpy(tmp_frame, src_frame, FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION);
649646

@@ -699,8 +696,7 @@ static dberr_t fil_space_decrypt_for_non_full_checksum(
699696
src_frame + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID);
700697
ib_uint64_t lsn = mach_read_from_8(src_frame + FIL_PAGE_LSN);
701698

702-
ut_a(key_version != ENCRYPTION_KEY_NOT_ENCRYPTED);
703-
ut_a(crypt_data != NULL && crypt_data->is_encrypted());
699+
ut_ad(key_version != ENCRYPTION_KEY_NOT_ENCRYPTED);
704700

705701
/* read space & lsn */
706702
uint header_len = FIL_PAGE_DATA;
@@ -753,8 +749,8 @@ static dberr_t fil_space_decrypt_for_non_full_checksum(
753749
@param[in] physical_size page size
754750
@param[in] fsp_flags Tablespace flags
755751
@param[in,out] src_frame Page to decrypt
756-
@param[out] err DB_SUCCESS or DB_DECRYPTION_FAILED
757-
@return DB_SUCCESS or error */
752+
@retval DB_SUCCESS on success
753+
@retval DB_DECRYPTION_FAILED on error */
758754
dberr_t
759755
fil_space_decrypt(
760756
ulint space_id,
@@ -764,6 +760,10 @@ fil_space_decrypt(
764760
ulint fsp_flags,
765761
byte* src_frame)
766762
{
763+
if (!crypt_data || !crypt_data->is_encrypted()) {
764+
return DB_DECRYPTION_FAILED;
765+
}
766+
767767
if (fil_space_t::full_crc32(fsp_flags)) {
768768
return fil_space_decrypt_full_crc32(
769769
space_id, crypt_data, tmp_frame, src_frame);
@@ -780,7 +780,8 @@ Decrypt a page.
780780
@param[in] tmp_frame Temporary buffer used for decrypting
781781
@param[in,out] src_frame Page to decrypt
782782
@return decrypted page, or original not encrypted page if decryption is
783-
not needed.*/
783+
not needed.
784+
@retval nullptr on failure */
784785
byte*
785786
fil_space_decrypt(
786787
const fil_space_t* space,
@@ -789,7 +790,6 @@ fil_space_decrypt(
789790
{
790791
const ulint physical_size = space->physical_size();
791792

792-
ut_ad(space->crypt_data != NULL && space->crypt_data->is_encrypted());
793793
ut_ad(space->referenced());
794794

795795
if (DB_SUCCESS != fil_space_decrypt(space->id, space->crypt_data,
@@ -800,9 +800,7 @@ fil_space_decrypt(
800800

801801
/* Copy the decrypted page back to page buffer, not
802802
really any other options. */
803-
memcpy(src_frame, tmp_frame, physical_size);
804-
805-
return src_frame;
803+
return static_cast<byte*>(memcpy(src_frame, tmp_frame, physical_size));
806804
}
807805

808806
/***********************************************************************/

storage/innobase/include/fil0crypt.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ byte* fil_space_encrypt(
296296
@param[in] physical_size page size
297297
@param[in] fsp_flags Tablespace flags
298298
@param[in,out] src_frame Page to decrypt
299-
@return DB_SUCCESS or error */
299+
@retval DB_SUCCESS on success
300+
@retval DB_DECRYPTION_FAILED on error */
300301
dberr_t
301302
fil_space_decrypt(
302303
ulint space_id,
@@ -312,7 +313,8 @@ Decrypt a page
312313
@param[in] tmp_frame Temporary buffer used for decrypting
313314
@param[in,out] src_frame Page to decrypt
314315
@return decrypted page, or original not encrypted page if decryption is
315-
not needed.*/
316+
not needed.
317+
@retval nullptr on failure */
316318
byte*
317319
fil_space_decrypt(
318320
const fil_space_t* space,

storage/innobase/include/fil0fil.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ The low-level file system
2424
Created 10/25/1995 Heikki Tuuri
2525
*******************************************************/
2626

27-
#ifndef fil0fil_h
28-
#define fil0fil_h
27+
#pragma once
2928

3029
#include "fsp0types.h"
3130
#include "mach0data.h"
@@ -1902,7 +1901,4 @@ void test_make_filepath();
19021901
@return block size */
19031902
ulint fil_space_get_block_size(const fil_space_t* space, unsigned offset);
19041903

1905-
#include "fil0fil.inl"
19061904
#endif /* UNIV_INNOCHECKSUM */
1907-
1908-
#endif /* fil0fil_h */

storage/innobase/include/fil0fil.inl

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

0 commit comments

Comments
 (0)