1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00

Description for this pull request:

- Optimize new cluster allocation by correctly find empty entry slot.
  - Add the check to prevent excessive bitmap clearing due to invalid
    data size of file/dir entry.
  - Fix incorrect error return for zero-byte writes.
 -----BEGIN PGP SIGNATURE-----
 
 iQJKBAABCgA0FiEE6NzKS6Uv/XAAGHgyZwv7A1FEIQgFAmfISf4WHGxpbmtpbmpl
 b25Aa2VybmVsLm9yZwAKCRBnC/sDUUQhCKd9EACSQdLgmeW12CLw55pEB75yoVwc
 Y4UMzJzS+JT/G+HFeepUi7uXO95TgydZwJ77Zrm5OWRrjhe3l22SXJnhAlPthUeB
 HR9B+igbDV4nbbNr1IyPLc9GUKWU7IxcFa1aEa4gNKScGgZgGMnnbNZfPYrI82Mo
 QNB/OAtgB30I8SOnMYAEsluzZzJIA5QgoD/5tzhxAfhu5+yPws/zC62TB8mSpOnm
 swlkl7e6onp4UBhhzEJs+1gprRwOWGqn24D9bL7jsb/zzK8i6iwLZ9J4+VyDoEIw
 AofbG0qDa7p7jowhliuUyAzoX0SFDp/jMCqvX914yCtqZrl8wezj0o5ScTDxPz5L
 q8ggCryjjNcPKvwSxNxgZv8bE+fxgV5Fln4S/TKM9A6sXLc4rHvfatdCtD9xLLPY
 mo3FzN0FYXgmbQtpJTF8gj5jtS1zBiFAUKzXHFbobSdn8eQ+k79GXA83TfgbS9zV
 x/qO3PlK4X4Ogu4OC8H110i5OfDtx3lOIPWLpdyhJfzU9aUrZ/QVPLDuLdcpkLMl
 DrBR4RzqCLrLHKx3PEy3jioM+gLhngOfitDt/x/pChHu1NeNCFMr9u75EnBbBYQ0
 YiJn6/PfSK9B8LNcUw6796YFxcbPuu5RZtUreUJSHXXNTUyENNGDNsTWY/BYTzZQ
 9dOPyBVR9O9/R7hZqg==
 =aa/n
 -----END PGP SIGNATURE-----

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
This commit is contained in:
Linus Torvalds 2025-03-06 08:18:48 -10:00
commit 5872cca23a
5 changed files with 23 additions and 9 deletions

View file

@ -141,7 +141,7 @@ int exfat_set_bitmap(struct inode *inode, unsigned int clu, bool sync)
return 0;
}
void exfat_clear_bitmap(struct inode *inode, unsigned int clu, bool sync)
int exfat_clear_bitmap(struct inode *inode, unsigned int clu, bool sync)
{
int i, b;
unsigned int ent_idx;
@ -150,13 +150,17 @@ void exfat_clear_bitmap(struct inode *inode, unsigned int clu, bool sync)
struct exfat_mount_options *opts = &sbi->options;
if (!is_valid_cluster(sbi, clu))
return;
return -EIO;
ent_idx = CLUSTER_TO_BITMAP_ENT(clu);
i = BITMAP_OFFSET_SECTOR_INDEX(sb, ent_idx);
b = BITMAP_OFFSET_BIT_IN_SECTOR(sb, ent_idx);
if (!test_bit_le(b, sbi->vol_amap[i]->b_data))
return -EIO;
clear_bit_le(b, sbi->vol_amap[i]->b_data);
exfat_update_bh(sbi->vol_amap[i], sync);
if (opts->discard) {
@ -171,6 +175,8 @@ void exfat_clear_bitmap(struct inode *inode, unsigned int clu, bool sync)
opts->discard = 0;
}
}
return 0;
}
/*

View file

@ -456,7 +456,7 @@ int exfat_count_num_clusters(struct super_block *sb,
int exfat_load_bitmap(struct super_block *sb);
void exfat_free_bitmap(struct exfat_sb_info *sbi);
int exfat_set_bitmap(struct inode *inode, unsigned int clu, bool sync);
void exfat_clear_bitmap(struct inode *inode, unsigned int clu, bool sync);
int exfat_clear_bitmap(struct inode *inode, unsigned int clu, bool sync);
unsigned int exfat_find_free_bitmap(struct super_block *sb, unsigned int clu);
int exfat_count_used_clusters(struct super_block *sb, unsigned int *ret_count);
int exfat_trim_fs(struct inode *inode, struct fstrim_range *range);

View file

@ -175,6 +175,7 @@ static int __exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain
BITMAP_OFFSET_SECTOR_INDEX(sb, CLUSTER_TO_BITMAP_ENT(clu));
if (p_chain->flags == ALLOC_NO_FAT_CHAIN) {
int err;
unsigned int last_cluster = p_chain->dir + p_chain->size - 1;
do {
bool sync = false;
@ -189,7 +190,9 @@ static int __exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain
cur_cmap_i = next_cmap_i;
}
exfat_clear_bitmap(inode, clu, (sync && IS_DIRSYNC(inode)));
err = exfat_clear_bitmap(inode, clu, (sync && IS_DIRSYNC(inode)));
if (err)
break;
clu++;
num_clusters++;
} while (num_clusters < p_chain->size);
@ -210,12 +213,13 @@ static int __exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain
cur_cmap_i = next_cmap_i;
}
exfat_clear_bitmap(inode, clu, (sync && IS_DIRSYNC(inode)));
if (exfat_clear_bitmap(inode, clu, (sync && IS_DIRSYNC(inode))))
break;
clu = n_clu;
num_clusters++;
if (err)
goto dec_used_clus;
break;
if (num_clusters >= sbi->num_clusters - EXFAT_FIRST_CLUSTER) {
/*
@ -229,7 +233,6 @@ static int __exfat_free_cluster(struct inode *inode, struct exfat_chain *p_chain
} while (clu != EXFAT_EOF_CLUSTER);
}
dec_used_clus:
sbi->used_clusters -= num_clusters;
return 0;
}

View file

@ -587,7 +587,7 @@ static ssize_t exfat_file_write_iter(struct kiocb *iocb, struct iov_iter *iter)
valid_size = ei->valid_size;
ret = generic_write_checks(iocb, iter);
if (ret < 0)
if (ret <= 0)
goto unlock;
if (iocb->ki_flags & IOCB_DIRECT) {

View file

@ -232,7 +232,7 @@ static int exfat_search_empty_slot(struct super_block *sb,
dentry = 0;
}
while (dentry + num_entries < total_entries &&
while (dentry + num_entries <= total_entries &&
clu.dir != EXFAT_EOF_CLUSTER) {
i = dentry & (dentries_per_clu - 1);
@ -646,6 +646,11 @@ static int exfat_find(struct inode *dir, struct qstr *qname,
info->valid_size = le64_to_cpu(ep2->dentry.stream.valid_size);
info->size = le64_to_cpu(ep2->dentry.stream.size);
if (unlikely(EXFAT_B_TO_CLU_ROUND_UP(info->size, sbi) > sbi->used_clusters)) {
exfat_fs_error(sb, "data size is invalid(%lld)", info->size);
return -EIO;
}
info->start_clu = le32_to_cpu(ep2->dentry.stream.start_clu);
if (!is_valid_cluster(sbi, info->start_clu) && info->size) {
exfat_warn(sb, "start_clu is invalid cluster(0x%x)",