]> www.infradead.org Git - users/willy/pagecache.git/commitdiff
exfat: fix the infinite loop in exfat_readdir()
authorYuezhang Mo <Yuezhang.Mo@sony.com>
Fri, 13 Dec 2024 05:08:37 +0000 (13:08 +0800)
committerNamjae Jeon <linkinjeon@kernel.org>
Tue, 31 Dec 2024 08:49:40 +0000 (17:49 +0900)
If the file system is corrupted so that a cluster is linked to
itself in the cluster chain, and there is an unused directory
entry in the cluster, 'dentry' will not be incremented, causing
condition 'dentry < max_dentries' unable to prevent an infinite
loop.

This infinite loop causes s_lock not to be released, and other
tasks will hang, such as exfat_sync_fs().

This commit stops traversing the cluster chain when there is unused
directory entry in the cluster to avoid this infinite loop.

Reported-by: syzbot+205c2644abdff9d3f9fc@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=205c2644abdff9d3f9fc
Tested-by: syzbot+205c2644abdff9d3f9fc@syzkaller.appspotmail.com
Fixes: ca06197382bd ("exfat: add directory 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>
fs/exfat/dir.c

index fe0a9b8a0cd079f5bf76eb9c5cc814ec43a17216..3103b932b674619adc168cf26f24d3e1f7a3b8ff 100644 (file)
@@ -122,7 +122,7 @@ static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_ent
                        type = exfat_get_entry_type(ep);
                        if (type == TYPE_UNUSED) {
                                brelse(bh);
-                               break;
+                               goto out;
                        }
 
                        if (type != TYPE_FILE && type != TYPE_DIR) {
@@ -170,6 +170,7 @@ static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_ent
                }
        }
 
+out:
        dir_entry->namebuf.lfn[0] = '\0';
        *cpos = EXFAT_DEN_TO_B(dentry);
        return 0;