Skip to content

Commit f83a4f2

Browse files
committed
Merge tag 'erofs-for-6.17-rc6-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs
Pull erofs fixes from Gao Xiang: - Fix invalid algorithm dereference in encoded extents - Add missing dax_break_layout_final(), since recent FSDAX fixes didn't cover EROFS - Arrange long xattr name prefixes more properly * tag 'erofs-for-6.17-rc6-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs: erofs: fix long xattr name prefix placement erofs: fix runtime warning on truncate_folio_batch_exceptionals() erofs: fix invalid algorithm for encoded extents
2 parents 5cd64d4 + 1fcf686 commit f83a4f2

File tree

5 files changed

+65
-36
lines changed

5 files changed

+65
-36
lines changed

fs/erofs/erofs_fs.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
/* to allow for x86 boot sectors and other oddities. */
1313
#define EROFS_SUPER_OFFSET 1024
1414

15-
#define EROFS_FEATURE_COMPAT_SB_CHKSUM 0x00000001
16-
#define EROFS_FEATURE_COMPAT_MTIME 0x00000002
17-
#define EROFS_FEATURE_COMPAT_XATTR_FILTER 0x00000004
15+
#define EROFS_FEATURE_COMPAT_SB_CHKSUM 0x00000001
16+
#define EROFS_FEATURE_COMPAT_MTIME 0x00000002
17+
#define EROFS_FEATURE_COMPAT_XATTR_FILTER 0x00000004
1818
#define EROFS_FEATURE_COMPAT_SHARED_EA_IN_METABOX 0x00000008
19+
#define EROFS_FEATURE_COMPAT_PLAIN_XATTR_PFX 0x00000010
20+
1921

2022
/*
2123
* Any bits that aren't in EROFS_ALL_FEATURE_INCOMPAT should

fs/erofs/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ EROFS_FEATURE_FUNCS(metabox, incompat, INCOMPAT_METABOX)
234234
EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM)
235235
EROFS_FEATURE_FUNCS(xattr_filter, compat, COMPAT_XATTR_FILTER)
236236
EROFS_FEATURE_FUNCS(shared_ea_in_metabox, compat, COMPAT_SHARED_EA_IN_METABOX)
237+
EROFS_FEATURE_FUNCS(plain_xattr_pfx, compat, COMPAT_PLAIN_XATTR_PFX)
237238

238239
static inline u64 erofs_nid_to_ino64(struct erofs_sb_info *sbi, erofs_nid_t nid)
239240
{

fs/erofs/super.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,10 +1018,22 @@ static int erofs_show_options(struct seq_file *seq, struct dentry *root)
10181018
return 0;
10191019
}
10201020

1021+
static void erofs_evict_inode(struct inode *inode)
1022+
{
1023+
#ifdef CONFIG_FS_DAX
1024+
if (IS_DAX(inode))
1025+
dax_break_layout_final(inode);
1026+
#endif
1027+
1028+
truncate_inode_pages_final(&inode->i_data);
1029+
clear_inode(inode);
1030+
}
1031+
10211032
const struct super_operations erofs_sops = {
10221033
.put_super = erofs_put_super,
10231034
.alloc_inode = erofs_alloc_inode,
10241035
.free_inode = erofs_free_inode,
1036+
.evict_inode = erofs_evict_inode,
10251037
.statfs = erofs_statfs,
10261038
.show_options = erofs_show_options,
10271039
};

fs/erofs/xattr.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ int erofs_xattr_prefixes_init(struct super_block *sb)
482482
erofs_off_t pos = (erofs_off_t)sbi->xattr_prefix_start << 2;
483483
struct erofs_xattr_prefix_item *pfs;
484484
int ret = 0, i, len;
485+
bool plain = erofs_sb_has_plain_xattr_pfx(sbi);
485486

486487
if (!sbi->xattr_prefix_count)
487488
return 0;
@@ -490,9 +491,15 @@ int erofs_xattr_prefixes_init(struct super_block *sb)
490491
if (!pfs)
491492
return -ENOMEM;
492493

493-
if (sbi->packed_inode)
494-
buf.mapping = sbi->packed_inode->i_mapping;
495-
else
494+
if (!plain) {
495+
if (erofs_sb_has_metabox(sbi))
496+
(void)erofs_init_metabuf(&buf, sb, true);
497+
else if (sbi->packed_inode)
498+
buf.mapping = sbi->packed_inode->i_mapping;
499+
else
500+
plain = true;
501+
}
502+
if (plain)
496503
(void)erofs_init_metabuf(&buf, sb, false);
497504

498505
for (i = 0; i < sbi->xattr_prefix_count; i++) {

fs/erofs/zmap.c

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,10 @@ static int z_erofs_map_blocks_fo(struct inode *inode,
394394
.map = map,
395395
.in_mbox = erofs_inode_in_metabox(inode),
396396
};
397-
int err = 0;
398-
unsigned int endoff, afmt;
397+
unsigned int endoff;
399398
unsigned long initial_lcn;
400399
unsigned long long ofs, end;
400+
int err;
401401

402402
ofs = flags & EROFS_GET_BLOCKS_FINDTAIL ? inode->i_size - 1 : map->m_la;
403403
if (fragment && !(flags & EROFS_GET_BLOCKS_FINDTAIL) &&
@@ -482,20 +482,15 @@ static int z_erofs_map_blocks_fo(struct inode *inode,
482482
err = -EFSCORRUPTED;
483483
goto unmap_out;
484484
}
485-
afmt = vi->z_advise & Z_EROFS_ADVISE_INTERLACED_PCLUSTER ?
486-
Z_EROFS_COMPRESSION_INTERLACED :
487-
Z_EROFS_COMPRESSION_SHIFTED;
485+
if (vi->z_advise & Z_EROFS_ADVISE_INTERLACED_PCLUSTER)
486+
map->m_algorithmformat = Z_EROFS_COMPRESSION_INTERLACED;
487+
else
488+
map->m_algorithmformat = Z_EROFS_COMPRESSION_SHIFTED;
489+
} else if (m.headtype == Z_EROFS_LCLUSTER_TYPE_HEAD2) {
490+
map->m_algorithmformat = vi->z_algorithmtype[1];
488491
} else {
489-
afmt = m.headtype == Z_EROFS_LCLUSTER_TYPE_HEAD2 ?
490-
vi->z_algorithmtype[1] : vi->z_algorithmtype[0];
491-
if (!(EROFS_I_SB(inode)->available_compr_algs & (1 << afmt))) {
492-
erofs_err(sb, "inconsistent algorithmtype %u for nid %llu",
493-
afmt, vi->nid);
494-
err = -EFSCORRUPTED;
495-
goto unmap_out;
496-
}
492+
map->m_algorithmformat = vi->z_algorithmtype[0];
497493
}
498-
map->m_algorithmformat = afmt;
499494

500495
if ((flags & EROFS_GET_BLOCKS_FIEMAP) ||
501496
((flags & EROFS_GET_BLOCKS_READMORE) &&
@@ -626,9 +621,9 @@ static int z_erofs_fill_inode(struct inode *inode, struct erofs_map_blocks *map)
626621
{
627622
struct erofs_inode *const vi = EROFS_I(inode);
628623
struct super_block *const sb = inode->i_sb;
629-
int err, headnr;
630-
erofs_off_t pos;
631624
struct z_erofs_map_header *h;
625+
erofs_off_t pos;
626+
int err = 0;
632627

633628
if (test_bit(EROFS_I_Z_INITED_BIT, &vi->flags)) {
634629
/*
@@ -642,7 +637,6 @@ static int z_erofs_fill_inode(struct inode *inode, struct erofs_map_blocks *map)
642637
if (wait_on_bit_lock(&vi->flags, EROFS_I_BL_Z_BIT, TASK_KILLABLE))
643638
return -ERESTARTSYS;
644639

645-
err = 0;
646640
if (test_bit(EROFS_I_Z_INITED_BIT, &vi->flags))
647641
goto out_unlock;
648642

@@ -679,15 +673,6 @@ static int z_erofs_fill_inode(struct inode *inode, struct erofs_map_blocks *map)
679673
else if (vi->z_advise & Z_EROFS_ADVISE_INLINE_PCLUSTER)
680674
vi->z_idata_size = le16_to_cpu(h->h_idata_size);
681675

682-
headnr = 0;
683-
if (vi->z_algorithmtype[0] >= Z_EROFS_COMPRESSION_MAX ||
684-
vi->z_algorithmtype[++headnr] >= Z_EROFS_COMPRESSION_MAX) {
685-
erofs_err(sb, "unknown HEAD%u format %u for nid %llu, please upgrade kernel",
686-
headnr + 1, vi->z_algorithmtype[headnr], vi->nid);
687-
err = -EOPNOTSUPP;
688-
goto out_unlock;
689-
}
690-
691676
if (!erofs_sb_has_big_pcluster(EROFS_SB(sb)) &&
692677
vi->z_advise & (Z_EROFS_ADVISE_BIG_PCLUSTER_1 |
693678
Z_EROFS_ADVISE_BIG_PCLUSTER_2)) {
@@ -726,6 +711,30 @@ static int z_erofs_fill_inode(struct inode *inode, struct erofs_map_blocks *map)
726711
return err;
727712
}
728713

714+
static int z_erofs_map_sanity_check(struct inode *inode,
715+
struct erofs_map_blocks *map)
716+
{
717+
struct erofs_sb_info *sbi = EROFS_I_SB(inode);
718+
719+
if (!(map->m_flags & EROFS_MAP_ENCODED))
720+
return 0;
721+
if (unlikely(map->m_algorithmformat >= Z_EROFS_COMPRESSION_RUNTIME_MAX)) {
722+
erofs_err(inode->i_sb, "unknown algorithm %d @ pos %llu for nid %llu, please upgrade kernel",
723+
map->m_algorithmformat, map->m_la, EROFS_I(inode)->nid);
724+
return -EOPNOTSUPP;
725+
}
726+
if (unlikely(map->m_algorithmformat < Z_EROFS_COMPRESSION_MAX &&
727+
!(sbi->available_compr_algs & (1 << map->m_algorithmformat)))) {
728+
erofs_err(inode->i_sb, "inconsistent algorithmtype %u for nid %llu",
729+
map->m_algorithmformat, EROFS_I(inode)->nid);
730+
return -EFSCORRUPTED;
731+
}
732+
if (unlikely(map->m_plen > Z_EROFS_PCLUSTER_MAX_SIZE ||
733+
map->m_llen > Z_EROFS_PCLUSTER_MAX_DSIZE))
734+
return -EOPNOTSUPP;
735+
return 0;
736+
}
737+
729738
int z_erofs_map_blocks_iter(struct inode *inode, struct erofs_map_blocks *map,
730739
int flags)
731740
{
@@ -746,10 +755,8 @@ int z_erofs_map_blocks_iter(struct inode *inode, struct erofs_map_blocks *map,
746755
else
747756
err = z_erofs_map_blocks_fo(inode, map, flags);
748757
}
749-
if (!err && (map->m_flags & EROFS_MAP_ENCODED) &&
750-
unlikely(map->m_plen > Z_EROFS_PCLUSTER_MAX_SIZE ||
751-
map->m_llen > Z_EROFS_PCLUSTER_MAX_DSIZE))
752-
err = -EOPNOTSUPP;
758+
if (!err)
759+
err = z_erofs_map_sanity_check(inode, map);
753760
if (err)
754761
map->m_llen = 0;
755762
}

0 commit comments

Comments
 (0)