]> Git Repo - J-linux.git/commitdiff
exfat: fix the infinite loop in __exfat_free_cluster()
authorYuezhang Mo <[email protected]>
Mon, 16 Dec 2024 05:39:42 +0000 (13:39 +0800)
committerNamjae Jeon <[email protected]>
Tue, 31 Dec 2024 08:51:21 +0000 (17:51 +0900)
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: [email protected]
Closes: https://syzkaller.appspot.com/bug?extid=1de5a37cb85a2d536330
Tested-by: [email protected]
Fixes: 31023864e67a ("exfat: add fat entry operations")
Signed-off-by: Yuezhang Mo <[email protected]>
Reviewed-by: Sungjong Seo <[email protected]>
Signed-off-by: Namjae Jeon <[email protected]>
fs/exfat/fatent.c

index 773c320d68f3f2bb2d0de9a051cdbb3de9e132eb..9e5492ac409b07485e276a99ddcd98afc2dd5639 100644 (file)
@@ -216,6 +216,16 @@ static int __exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain
 
                        if (err)
                                goto dec_used_clus;
+
+                       if (num_clusters >= sbi->num_clusters - EXFAT_FIRST_CLUSTER) {
+                               /*
+                                * The cluster chain includes a loop, scan the
+                                * bitmap to get the number of used clusters.
+                                */
+                               exfat_count_used_clusters(sb, &sbi->used_clusters);
+
+                               return 0;
+                       }
                } while (clu != EXFAT_EOF_CLUSTER);
        }
 
This page took 0.076573 seconds and 4 git commands to generate.