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

+65 -36
+5 -3
fs/erofs/erofs_fs.h
··· 12 12 /* to allow for x86 boot sectors and other oddities. */ 13 13 #define EROFS_SUPER_OFFSET 1024 14 14 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 18 18 #define EROFS_FEATURE_COMPAT_SHARED_EA_IN_METABOX 0x00000008 19 + #define EROFS_FEATURE_COMPAT_PLAIN_XATTR_PFX 0x00000010 20 + 19 21 20 22 /* 21 23 * Any bits that aren't in EROFS_ALL_FEATURE_INCOMPAT should
+1
fs/erofs/internal.h
··· 234 234 EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM) 235 235 EROFS_FEATURE_FUNCS(xattr_filter, compat, COMPAT_XATTR_FILTER) 236 236 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) 237 238 238 239 static inline u64 erofs_nid_to_ino64(struct erofs_sb_info *sbi, erofs_nid_t nid) 239 240 {
+12
fs/erofs/super.c
··· 1018 1018 return 0; 1019 1019 } 1020 1020 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 + 1021 1032 const struct super_operations erofs_sops = { 1022 1033 .put_super = erofs_put_super, 1023 1034 .alloc_inode = erofs_alloc_inode, 1024 1035 .free_inode = erofs_free_inode, 1036 + .evict_inode = erofs_evict_inode, 1025 1037 .statfs = erofs_statfs, 1026 1038 .show_options = erofs_show_options, 1027 1039 };
+10 -3
fs/erofs/xattr.c
··· 482 482 erofs_off_t pos = (erofs_off_t)sbi->xattr_prefix_start << 2; 483 483 struct erofs_xattr_prefix_item *pfs; 484 484 int ret = 0, i, len; 485 + bool plain = erofs_sb_has_plain_xattr_pfx(sbi); 485 486 486 487 if (!sbi->xattr_prefix_count) 487 488 return 0; ··· 491 490 if (!pfs) 492 491 return -ENOMEM; 493 492 494 - if (sbi->packed_inode) 495 - buf.mapping = sbi->packed_inode->i_mapping; 496 - else 493 + if (!plain) { 494 + if (erofs_sb_has_metabox(sbi)) 495 + (void)erofs_init_metabuf(&buf, sb, true); 496 + else if (sbi->packed_inode) 497 + buf.mapping = sbi->packed_inode->i_mapping; 498 + else 499 + plain = true; 500 + } 501 + if (plain) 497 502 (void)erofs_init_metabuf(&buf, sb, false); 498 503 499 504 for (i = 0; i < sbi->xattr_prefix_count; i++) {
+37 -30
fs/erofs/zmap.c
··· 394 394 .map = map, 395 395 .in_mbox = erofs_inode_in_metabox(inode), 396 396 }; 397 - int err = 0; 398 - unsigned int endoff, afmt; 397 + unsigned int endoff; 399 398 unsigned long initial_lcn; 400 399 unsigned long long ofs, end; 400 + int err; 401 401 402 402 ofs = flags & EROFS_GET_BLOCKS_FINDTAIL ? inode->i_size - 1 : map->m_la; 403 403 if (fragment && !(flags & EROFS_GET_BLOCKS_FINDTAIL) && ··· 482 482 err = -EFSCORRUPTED; 483 483 goto unmap_out; 484 484 } 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]; 488 491 } 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]; 497 493 } 498 - map->m_algorithmformat = afmt; 499 494 500 495 if ((flags & EROFS_GET_BLOCKS_FIEMAP) || 501 496 ((flags & EROFS_GET_BLOCKS_READMORE) && ··· 621 626 { 622 627 struct erofs_inode *const vi = EROFS_I(inode); 623 628 struct super_block *const sb = inode->i_sb; 624 - int err, headnr; 625 - erofs_off_t pos; 626 629 struct z_erofs_map_header *h; 630 + erofs_off_t pos; 631 + int err = 0; 627 632 628 633 if (test_bit(EROFS_I_Z_INITED_BIT, &vi->flags)) { 629 634 /* ··· 637 642 if (wait_on_bit_lock(&vi->flags, EROFS_I_BL_Z_BIT, TASK_KILLABLE)) 638 643 return -ERESTARTSYS; 639 644 640 - err = 0; 641 645 if (test_bit(EROFS_I_Z_INITED_BIT, &vi->flags)) 642 646 goto out_unlock; 643 647 ··· 672 678 vi->z_fragmentoff = le32_to_cpu(h->h_fragmentoff); 673 679 else if (vi->z_advise & Z_EROFS_ADVISE_INLINE_PCLUSTER) 674 680 vi->z_idata_size = le16_to_cpu(h->h_idata_size); 675 - 676 - headnr = 0; 677 - if (vi->z_algorithmtype[0] >= Z_EROFS_COMPRESSION_MAX || 678 - vi->z_algorithmtype[++headnr] >= Z_EROFS_COMPRESSION_MAX) { 679 - erofs_err(sb, "unknown HEAD%u format %u for nid %llu, please upgrade kernel", 680 - headnr + 1, vi->z_algorithmtype[headnr], vi->nid); 681 - err = -EOPNOTSUPP; 682 - goto out_unlock; 683 - } 684 681 685 682 if (!erofs_sb_has_big_pcluster(EROFS_SB(sb)) && 686 683 vi->z_advise & (Z_EROFS_ADVISE_BIG_PCLUSTER_1 | ··· 711 726 return err; 712 727 } 713 728 729 + static int z_erofs_map_sanity_check(struct inode *inode, 730 + struct erofs_map_blocks *map) 731 + { 732 + struct erofs_sb_info *sbi = EROFS_I_SB(inode); 733 + 734 + if (!(map->m_flags & EROFS_MAP_ENCODED)) 735 + return 0; 736 + if (unlikely(map->m_algorithmformat >= Z_EROFS_COMPRESSION_RUNTIME_MAX)) { 737 + erofs_err(inode->i_sb, "unknown algorithm %d @ pos %llu for nid %llu, please upgrade kernel", 738 + map->m_algorithmformat, map->m_la, EROFS_I(inode)->nid); 739 + return -EOPNOTSUPP; 740 + } 741 + if (unlikely(map->m_algorithmformat < Z_EROFS_COMPRESSION_MAX && 742 + !(sbi->available_compr_algs & (1 << map->m_algorithmformat)))) { 743 + erofs_err(inode->i_sb, "inconsistent algorithmtype %u for nid %llu", 744 + map->m_algorithmformat, EROFS_I(inode)->nid); 745 + return -EFSCORRUPTED; 746 + } 747 + if (unlikely(map->m_plen > Z_EROFS_PCLUSTER_MAX_SIZE || 748 + map->m_llen > Z_EROFS_PCLUSTER_MAX_DSIZE)) 749 + return -EOPNOTSUPP; 750 + return 0; 751 + } 752 + 714 753 int z_erofs_map_blocks_iter(struct inode *inode, struct erofs_map_blocks *map, 715 754 int flags) 716 755 { ··· 755 746 else 756 747 err = z_erofs_map_blocks_fo(inode, map, flags); 757 748 } 758 - if (!err && (map->m_flags & EROFS_MAP_ENCODED) && 759 - unlikely(map->m_plen > Z_EROFS_PCLUSTER_MAX_SIZE || 760 - map->m_llen > Z_EROFS_PCLUSTER_MAX_DSIZE)) 761 - err = -EOPNOTSUPP; 749 + if (!err) 750 + err = z_erofs_map_sanity_check(inode, map); 762 751 if (err) 763 752 map->m_llen = 0; 764 753 }