Skip to content

Commit ecfbd57

Browse files
Yin Xiujiangaalexandrovich
authored andcommitted
fs/ntfs3: Fix slab-out-of-bounds in r_page
When PAGE_SIZE is 64K, if read_log_page is called by log_read_rst for the first time, the size of *buffer would be equal to DefaultLogPageSize(4K).But for *buffer operations like memcpy, if the memory area size(n) which being assigned to buffer is larger than 4K (log->page_size(64K) or bytes(64K-page_off)), it will cause an out of boundary error. Call trace: [...] kasan_report+0x44/0x130 check_memory_region+0xf8/0x1a0 memcpy+0xc8/0x100 ntfs_read_run_nb+0x20c/0x460 read_log_page+0xd0/0x1f4 log_read_rst+0x110/0x75c log_replay+0x1e8/0x4aa0 ntfs_loadlog_and_replay+0x290/0x2d0 ntfs_fill_super+0x508/0xec0 get_tree_bdev+0x1fc/0x34c [...] Fix this by setting variable r_page to NULL in log_read_rst. Signed-off-by: Yin Xiujiang <[email protected]> Signed-off-by: Konstantin Komarov <[email protected]>
1 parent 6580151 commit ecfbd57

File tree

1 file changed

+2
-24
lines changed

1 file changed

+2
-24
lines changed

fs/ntfs3/fslog.c

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ static int read_log_page(struct ntfs_log *log, u32 vbo,
11321132
return -EINVAL;
11331133

11341134
if (!*buffer) {
1135-
to_free = kmalloc(bytes, GFP_NOFS);
1135+
to_free = kmalloc(log->page_size, GFP_NOFS);
11361136
if (!to_free)
11371137
return -ENOMEM;
11381138
*buffer = to_free;
@@ -1180,10 +1180,7 @@ static int log_read_rst(struct ntfs_log *log, u32 l_size, bool first,
11801180
struct restart_info *info)
11811181
{
11821182
u32 skip, vbo;
1183-
struct RESTART_HDR *r_page = kmalloc(DefaultLogPageSize, GFP_NOFS);
1184-
1185-
if (!r_page)
1186-
return -ENOMEM;
1183+
struct RESTART_HDR *r_page = NULL;
11871184

11881185
/* Determine which restart area we are looking for. */
11891186
if (first) {
@@ -1197,7 +1194,6 @@ static int log_read_rst(struct ntfs_log *log, u32 l_size, bool first,
11971194
/* Loop continuously until we succeed. */
11981195
for (; vbo < l_size; vbo = 2 * vbo + skip, skip = 0) {
11991196
bool usa_error;
1200-
u32 sys_page_size;
12011197
bool brst, bchk;
12021198
struct RESTART_AREA *ra;
12031199

@@ -1251,24 +1247,6 @@ static int log_read_rst(struct ntfs_log *log, u32 l_size, bool first,
12511247
goto check_result;
12521248
}
12531249

1254-
/* Read the entire restart area. */
1255-
sys_page_size = le32_to_cpu(r_page->sys_page_size);
1256-
if (DefaultLogPageSize != sys_page_size) {
1257-
kfree(r_page);
1258-
r_page = kzalloc(sys_page_size, GFP_NOFS);
1259-
if (!r_page)
1260-
return -ENOMEM;
1261-
1262-
if (read_log_page(log, vbo,
1263-
(struct RECORD_PAGE_HDR **)&r_page,
1264-
&usa_error)) {
1265-
/* Ignore any errors. */
1266-
kfree(r_page);
1267-
r_page = NULL;
1268-
continue;
1269-
}
1270-
}
1271-
12721250
if (is_client_area_valid(r_page, usa_error)) {
12731251
info->valid_page = true;
12741252
ra = Add2Ptr(r_page, le16_to_cpu(r_page->ra_off));

0 commit comments

Comments
 (0)