Skip to content

Commit 5872cca

Browse files
committed
Merge tag 'exfat-for-6.14-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/exfat
Pull exfat fixes from Namjae Jeon: - Optimize new cluster allocation by correctly find empty entry slot - Add a check to prevent excessive bitmap clearing due to invalid data size of file/dir entry - Fix incorrect error return for zero-byte writes * tag 'exfat-for-6.14-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/exfat: exfat: add a check for invalid data size exfat: short-circuit zero-byte writes in exfat_file_write_iter exfat: fix soft lockup in exfat_clear_bitmap exfat: fix just enough dentries but allocate a new cluster to dir
2 parents 7f0e9ee + 13940ce commit 5872cca

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
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
}

fs/exfat/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ static ssize_t exfat_file_write_iter(struct kiocb *iocb, struct iov_iter *iter)
587587
valid_size = ei->valid_size;
588588

589589
ret = generic_write_checks(iocb, iter);
590-
if (ret < 0)
590+
if (ret <= 0)
591591
goto unlock;
592592

593593
if (iocb->ki_flags & IOCB_DIRECT) {

fs/exfat/namei.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ static int exfat_search_empty_slot(struct super_block *sb,
232232
dentry = 0;
233233
}
234234

235-
while (dentry + num_entries < total_entries &&
235+
while (dentry + num_entries <= total_entries &&
236236
clu.dir != EXFAT_EOF_CLUSTER) {
237237
i = dentry & (dentries_per_clu - 1);
238238

@@ -646,6 +646,11 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
646646
info->valid_size = le64_to_cpu(ep2->dentry.stream.valid_size);
647647
info->size = le64_to_cpu(ep2->dentry.stream.size);
648648

649+
if (unlikely(EXFAT_B_TO_CLU_ROUND_UP(info->size, sbi) > sbi->used_clusters)) {
650+
exfat_fs_error(sb, "data size is invalid(%lld)", info->size);
651+
return -EIO;
652+
}
653+
649654
info->start_clu = le32_to_cpu(ep2->dentry.stream.start_clu);
650655
if (!is_valid_cluster(sbi, info->start_clu) && info->size) {
651656
exfat_warn(sb, "start_clu is invalid cluster(0x%x)",

0 commit comments

Comments
 (0)