fs/ntfs3: fix check_log_rec() redo/undo region bounds
Subsystems (2)
PATCH 1/1 fs/ntfs3: fix check_log_rec() redo/undo region bounds
check_log_rec() validates that redo_off and undo_off are 8-byte aligned and that bytes >= lrh_length(lr), but lrh_length() only covers the LOG_REC_HDR header plus the embedded page_lcns array. It does not check that redo_off + redo_len or undo_off + undo_len fall within the bounds of the log record buffer.
A crafted $LogFile can set client_data_len to a small value (e.g. 40), redo_off to that same value, and redo_len to 0xFFF0. The kernel allocates a 40-byte buffer via kmalloc() in find_log_rec(), computes a pointer one byte past the end of that buffer, and iterates 4,095 times reading 16 bytes of adjacent kernel heap per iteration (65,520 bytes of OOB reads total) in the DeleteDirtyClusters handler of log_replay().
KASAN report:
BUG: KASAN: slab-out-of-bounds in log_replay+0xb0b3/0xe8c0 Read of size 8 at addr ffff888009117228 by task mount/85 The buggy address is located 0 bytes to the right of allocated 40-byte region [ffff888009117200, ffff888009117228)
Fix by adding bounds checks for the redo and undo data regions in check_log_rec(): verify that redo_off + redo_len and undo_off + undo_len each fit within the log record buffer.
--- fs/ntfs3/fslog.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
fs/ntfs3/fslog.c +14 -0
@@ -733,6 +733,20 @@ static bool check_log_rec(const struct LOG_REC_HDR *lr, u32 bytes, u32 tr,if (bytes <lrh_length (lr))return false; +if (lr->redo_len) { +u32 rend =le16_to_cpu (lr->redo_off) + +le16_to_cpu (lr->redo_len); +if (rend > bytes) +return false; + } + +if (lr->undo_len) { +u32 uend =le16_to_cpu (lr->undo_off) + +le16_to_cpu (lr->undo_len); +if (uend > bytes) +return false; + } +return true; }
Signature · 1 line
2.56.0