Skip to content

Commit f26967b

Browse files
namjaejeonaalexandrovich
authored andcommitted
fs/ntfs3: Fix invalid free in log_replay
log_read_rst() returns ENOMEM error when there is not enough memory. In this case, if info is returned without initialization, it attempts to kfree the uninitialized info->r_page pointer. This patch moves the memset initialization code to before log_read_rst() is called. Reported-by: Gerald Lee <[email protected]> Signed-off-by: Namjae Jeon <[email protected]> Signed-off-by: Konstantin Komarov <[email protected]>
1 parent 03ab8e6 commit f26967b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

fs/ntfs3/fslog.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,8 +1185,6 @@ static int log_read_rst(struct ntfs_log *log, u32 l_size, bool first,
11851185
if (!r_page)
11861186
return -ENOMEM;
11871187

1188-
memset(info, 0, sizeof(struct restart_info));
1189-
11901188
/* Determine which restart area we are looking for. */
11911189
if (first) {
11921190
vbo = 0;
@@ -3791,10 +3789,11 @@ int log_replay(struct ntfs_inode *ni, bool *initialized)
37913789
if (!log)
37923790
return -ENOMEM;
37933791

3792+
memset(&rst_info, 0, sizeof(struct restart_info));
3793+
37943794
log->ni = ni;
37953795
log->l_size = l_size;
37963796
log->one_page_buf = kmalloc(page_size, GFP_NOFS);
3797-
37983797
if (!log->one_page_buf) {
37993798
err = -ENOMEM;
38003799
goto out;
@@ -3842,6 +3841,7 @@ int log_replay(struct ntfs_inode *ni, bool *initialized)
38423841
if (rst_info.vbo)
38433842
goto check_restart_area;
38443843

3844+
memset(&rst_info2, 0, sizeof(struct restart_info));
38453845
err = log_read_rst(log, l_size, false, &rst_info2);
38463846

38473847
/* Determine which restart area to use. */

0 commit comments

Comments
 (0)