Skip to content

Commit 34bb50c

Browse files
jc2870akpm00
authored andcommitted
ocfs2: check el->l_next_free_rec in ocfs2_get_clusters_nocache
Recently syzbot reported a use-after-free issue[1]. The root cause of the problem is that the journal inode recorded in this file system image is corrupted. The value of "di->id2.i_list.l_next_free_rec" is 8193, which is greater than the value of "di->id2.i_list.l_count" (19). To solve this problem, an additional check should be added within ocfs2_get_clusters_nocache(). If the check fails, an error will be returned and the file system will be set to read-only. [1]: https://lore.kernel.org/all/[email protected]/T/ Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Julian Sun <[email protected]> Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=2313dda4dc4885c93578 Tested-by: [email protected] Reviewed-by: Joseph Qi <[email protected]> Cc: Changwei Ge <[email protected]> Cc: Joel Becker <[email protected]> Cc: Jun Piao <[email protected]> Cc: Junxiao Bi <[email protected]> Cc: Mark Fasheh <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent e420460 commit 34bb50c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

fs/ocfs2/extent_map.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,16 @@ static int ocfs2_get_clusters_nocache(struct inode *inode,
435435
}
436436
}
437437

438+
if (le16_to_cpu(el->l_next_free_rec) > le16_to_cpu(el->l_count)) {
439+
ocfs2_error(inode->i_sb,
440+
"Inode %lu has an invalid extent (next_free_rec %u, count %u)\n",
441+
inode->i_ino,
442+
le16_to_cpu(el->l_next_free_rec),
443+
le16_to_cpu(el->l_count));
444+
ret = -EROFS;
445+
goto out;
446+
}
447+
438448
i = ocfs2_search_extent_list(el, v_cluster);
439449
if (i == -1) {
440450
/*

0 commit comments

Comments
 (0)