Skip to content

Commit 9da3361

Browse files
committed
exfat: fix soft lockup in exfat_clear_bitmap
bitmap clear loop will take long time in __exfat_free_cluster() if data size of file/dir enty is invalid. If cluster bit in bitmap is already clear, stop clearing bitmap go to out of loop. Fixes: 3102386 ("exfat: add fat entry operations") Reported-by: Kun Hu <huk23@m.fudan.edu.cn>, Jiaji Qin <jjtan24@m.fudan.edu.cn> Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
1 parent 6697f81 commit 9da3361

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

fs/exfat/balloc.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ int exfat_set_bitmap(struct inode *inode, unsigned int clu, bool sync)
141141
return 0;
142142
}
143143

144-
void exfat_clear_bitmap(struct inode *inode, unsigned int clu, bool sync)
144+
int exfat_clear_bitmap(struct inode *inode, unsigned int clu, bool sync)
145145
{
146146
int i, b;
147147
unsigned int ent_idx;
@@ -150,13 +150,17 @@ void exfat_clear_bitmap(struct inode *inode, unsigned int clu, bool sync)
150150
struct exfat_mount_options *opts = &sbi->options;
151151

152152
if (!is_valid_cluster(sbi, clu))
153-
return;
153+
return -EIO;
154154

155155
ent_idx = CLUSTER_TO_BITMAP_ENT(clu);
156156
i = BITMAP_OFFSET_SECTOR_INDEX(sb, ent_idx);
157157
b = BITMAP_OFFSET_BIT_IN_SECTOR(sb, ent_idx);
158158

159+
if (!test_bit_le(b, sbi->vol_amap[i]->b_data))
160+
return -EIO;
161+
159162
clear_bit_le(b, sbi->vol_amap[i]->b_data);
163+
160164
exfat_update_bh(sbi->vol_amap[i], sync);
161165

162166
if (opts->discard) {
@@ -171,6 +175,8 @@ void exfat_clear_bitmap(struct inode *inode, unsigned int clu, bool sync)
171175
opts->discard = 0;
172176
}
173177
}
178+
179+
return 0;
174180
}
175181

176182
/*

fs/exfat/exfat_fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ int exfat_count_num_clusters(struct super_block *sb,
456456
int exfat_load_bitmap(struct super_block *sb);
457457
void exfat_free_bitmap(struct exfat_sb_info *sbi);
458458
int exfat_set_bitmap(struct inode *inode, unsigned int clu, bool sync);
459-
void exfat_clear_bitmap(struct inode *inode, unsigned int clu, bool sync);
459+
int exfat_clear_bitmap(struct inode *inode, unsigned int clu, bool sync);
460460
unsigned int exfat_find_free_bitmap(struct super_block *sb, unsigned int clu);
461461
int exfat_count_used_clusters(struct super_block *sb, unsigned int *ret_count);
462462
int exfat_trim_fs(struct inode *inode, struct fstrim_range *range);

fs/exfat/fatent.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ static int __exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain
175175
BITMAP_OFFSET_SECTOR_INDEX(sb, CLUSTER_TO_BITMAP_ENT(clu));
176176

177177
if (p_chain->flags == ALLOC_NO_FAT_CHAIN) {
178+
int err;
178179
unsigned int last_cluster = p_chain->dir + p_chain->size - 1;
179180
do {
180181
bool sync = false;
@@ -189,7 +190,9 @@ static int __exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain
189190
cur_cmap_i = next_cmap_i;
190191
}
191192

192-
exfat_clear_bitmap(inode, clu, (sync && IS_DIRSYNC(inode)));
193+
err = exfat_clear_bitmap(inode, clu, (sync && IS_DIRSYNC(inode)));
194+
if (err)
195+
break;
193196
clu++;
194197
num_clusters++;
195198
} while (num_clusters < p_chain->size);
@@ -210,12 +213,13 @@ static int __exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain
210213
cur_cmap_i = next_cmap_i;
211214
}
212215

213-
exfat_clear_bitmap(inode, clu, (sync && IS_DIRSYNC(inode)));
216+
if (exfat_clear_bitmap(inode, clu, (sync && IS_DIRSYNC(inode))))
217+
break;
214218
clu = n_clu;
215219
num_clusters++;
216220

217221
if (err)
218-
goto dec_used_clus;
222+
break;
219223

220224
if (num_clusters >= sbi->num_clusters - EXFAT_FIRST_CLUSTER) {
221225
/*
@@ -229,7 +233,6 @@ static int __exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain
229233
} while (clu != EXFAT_EOF_CLUSTER);
230234
}
231235

232-
dec_used_clus:
233236
sbi->used_clusters -= num_clusters;
234237
return 0;
235238
}

0 commit comments

Comments
 (0)