Re: [syzbot] task hung in exfat_write_inode

From: syzbot
Date: Thu Nov 30 2023 - 02:28:13 EST


For archival purposes, forwarding an incoming command email to
linux-kernel@xxxxxxxxxxxxxxx.

***

Subject: task hung in exfat_write_inode
Author: lizhi.xu@xxxxxxxxxxxxx

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git f9ff5644bcc0

diff --git a/fs/exfat/file.c b/fs/exfat/file.c
index bfdfafe00993..a3ace4fc555c 100644
--- a/fs/exfat/file.c
+++ b/fs/exfat/file.c
@@ -116,6 +116,7 @@ int __exfat_truncate(struct inode *inode)

exfat_chain_set(&clu, ei->start_clu, num_clusters_phys, ei->flags);

+ mutex_unlock(&sbi->s_lock);
if (i_size_read(inode) > 0) {
/*
* Truncate FAT chain num_clusters after the first cluster
@@ -134,8 +135,10 @@ int __exfat_truncate(struct inode *inode)
} else {
while (num_clusters > 0) {
last_clu = clu.dir;
+ mutex_lock(&sbi->s_lock);
if (exfat_get_next_cluster(sb, &(clu.dir)))
return -EIO;
+ mutex_unlock(&sbi->s_lock);

num_clusters--;
clu.size--;
@@ -160,6 +163,7 @@ int __exfat_truncate(struct inode *inode)
* __exfat_write_inode() is called for directory entry, bitmap
* and FAT to be written in a same writeback.
*/
+ mutex_unlock(&sbi->s_lock);
if (__exfat_write_inode(inode, inode_needs_sync(inode)))
return -EIO;