Skip to content

Commit a5324b3

Browse files
YuezhangMonamjaejeon
authored andcommitted
exfat: fix the infinite loop in __exfat_free_cluster()
In __exfat_free_cluster(), the cluster chain is traversed until the EOF cluster. If the cluster chain includes a loop due to file system corruption, the EOF cluster cannot be traversed, resulting in an infinite loop. This commit uses the total number of clusters to prevent this infinite loop. Reported-by: syzbot+1de5a37cb85a2d536330@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=1de5a37cb85a2d536330 Tested-by: syzbot+1de5a37cb85a2d536330@syzkaller.appspotmail.com Fixes: 3102386 ("exfat: add fat entry operations") Signed-off-by: Yuezhang Mo <Yuezhang.Mo@sony.com> Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
1 parent 98e2fb2 commit a5324b3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

fs/exfat/fatent.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ static int __exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain
216216

217217
if (err)
218218
goto dec_used_clus;
219+
220+
if (num_clusters >= sbi->num_clusters - EXFAT_FIRST_CLUSTER) {
221+
/*
222+
* The cluster chain includes a loop, scan the
223+
* bitmap to get the number of used clusters.
224+
*/
225+
exfat_count_used_clusters(sb, &sbi->used_clusters);
226+
227+
return 0;
228+
}
219229
} while (clu != EXFAT_EOF_CLUSTER);
220230
}
221231

0 commit comments

Comments
 (0)