Skip to content

Commit dcc09af

Browse files
committed
Follow-up fix to MDEV-15132 Avoid accessing the TRX_SYS page
trx_undo_mem_create_at_db_start(): Do not read TRX_UNDO_TRX_NO unless the field is known to be valid, that is, the transaction has been serialized and trx_purge_add_undo_to_history() has been invoked. Normally InnoDB pages would be zero-initialized on allocation (since MySQL 5.5 or so), but the undo log pages skip that mechanism. So, reused undo log pages can contain garbage. Undo log headers can start at any offset (there can be multiple undo log headers in the same undo log page). Therefore, because the TRX_UNDO_TRX_NO is never explicitly initialized on undo log header creation, its contents may be garbage.
1 parent 7eb084f commit dcc09af

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

storage/innobase/trx/trx0undo.cc

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,12 +1113,7 @@ trx_undo_mem_create_at_db_start(trx_rseg_t* rseg, ulint id, ulint page_no,
11131113
xid.null();
11141114
}
11151115

1116-
trx_id_t trx_id = mach_read_from_8(undo_header + TRX_UNDO_TRX_NO);
1117-
if (trx_id > max_trx_id) {
1118-
max_trx_id = trx_id;
1119-
}
1120-
1121-
trx_id = mach_read_from_8(undo_header + TRX_UNDO_TRX_ID);
1116+
trx_id_t trx_id = mach_read_from_8(undo_header + TRX_UNDO_TRX_ID);
11221117
if (trx_id > max_trx_id) {
11231118
max_trx_id = trx_id;
11241119
}
@@ -1139,6 +1134,15 @@ trx_undo_mem_create_at_db_start(trx_rseg_t* rseg, ulint id, ulint page_no,
11391134
ut_ad(type == TRX_UNDO_INSERT);
11401135
state = TRX_UNDO_TO_PURGE;
11411136
} else {
1137+
if (state == TRX_UNDO_TO_PURGE
1138+
|| state == TRX_UNDO_CACHED) {
1139+
trx_id_t id = mach_read_from_8(TRX_UNDO_TRX_NO
1140+
+ undo_header);
1141+
if (id > max_trx_id) {
1142+
max_trx_id = id;
1143+
}
1144+
}
1145+
11421146
fil_addr_tlast_addr = flst_get_last(
11431147
TRX_UNDO_SEG_HDR + TRX_UNDO_PAGE_LIST + undo_page,
11441148
&mtr);

0 commit comments

Comments
 (0)