From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64A322957C3; Wed, 30 Jul 2025 09:46:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753868818; cv=none; b=E+jjHS1z3xzHDrAbXRlRdicpAgBneHBNNkukfR58qUqggI5QSS8K2r3dMM9UEx5kNUF7rcMJX1AmbxevMdpg+HLUw1ynbYCvOVjS32UBbvFURoMlepGWy1yVM3UsKC4YkZB7TYCy49Hk1IdalvQiDBDRMvAknU7uepdY/wPLmRI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753868818; c=relaxed/simple; bh=Ul5QsNkigOYYBoYr51515AORrrRH/QecRUfRrQQ6b5U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GzA0HjhUwY0o+CjEcZU7jImW7LvIlqID/hekHx4DVNueuLx60MgkjqeiQWa3fNlAAwNK+Oc5x0mrFz/7do2wIPK3n0aszL40YAyq/qj+I2UlfUdKTjWUXjsuqsAR/Ni0rplh/D1IJDeML+dYmn2Q4lh0xcKScSN3KTeGjP6hlv8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ShAx/YDa; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ShAx/YDa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A1961C4CEF8; Wed, 30 Jul 2025 09:46:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1753868818; bh=Ul5QsNkigOYYBoYr51515AORrrRH/QecRUfRrQQ6b5U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ShAx/YDagqCXIpbU/72CiBZ/O7dxVPOw6JsCjiI5hkEcWXHHpbX7MJun55tgSC19K dVdqCGl5qJCfC36YSSJvYwi2pmvBTzh5Ih/enBa/I9yb/5MD5ae8ORhqSp2QNL17PK S0V/TuaEHR1fNa+iQihbYAbP4meZj4C50sCQuSNs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chao Yu , Gao Xiang , Sasha Levin Subject: [PATCH 6.12 083/117] erofs: clean up header parsing for ztailpacking and fragments Date: Wed, 30 Jul 2025 11:35:52 +0200 Message-ID: <20250730093236.990878280@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250730093233.592541778@linuxfoundation.org> References: <20250730093233.592541778@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Gao Xiang [ Upstream commit 540787d38b10dbc16a7d2bc2845752ab1605403a ] Simplify the logic in z_erofs_fill_inode_lazy() by combining the handling of ztailpacking and fragments, as they are mutually exclusive. Note that `h->h_clusterbits >> Z_EROFS_FRAGMENT_INODE_BIT` is handled above, so no need to duplicate the check. Reviewed-by: Chao Yu Signed-off-by: Gao Xiang Link: https://lore.kernel.org/r/20250224123747.1387122-2-hsiangkao@linux.alibaba.com Stable-dep-of: b44686c8391b ("erofs: fix large fragment handling") Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/erofs/zmap.c | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) --- a/fs/erofs/zmap.c +++ b/fs/erofs/zmap.c @@ -394,7 +394,8 @@ static int z_erofs_get_extent_decompress static int z_erofs_do_map_blocks(struct inode *inode, struct erofs_map_blocks *map, int flags) { - struct erofs_inode *const vi = EROFS_I(inode); + struct erofs_inode *vi = EROFS_I(inode); + struct super_block *sb = inode->i_sb; bool fragment = vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER; bool ztailpacking = vi->z_idata_size; struct z_erofs_maprecorder m = { @@ -438,7 +439,7 @@ static int z_erofs_do_map_blocks(struct } /* m.lcn should be >= 1 if endoff < m.clusterofs */ if (!m.lcn) { - erofs_err(inode->i_sb, "invalid logical cluster 0 at nid %llu", + erofs_err(sb, "invalid logical cluster 0 at nid %llu", vi->nid); err = -EFSCORRUPTED; goto unmap_out; @@ -454,7 +455,7 @@ static int z_erofs_do_map_blocks(struct goto unmap_out; break; default: - erofs_err(inode->i_sb, "unknown type %u @ offset %llu of nid %llu", + erofs_err(sb, "unknown type %u @ offset %llu of nid %llu", m.type, ofs, vi->nid); err = -EOPNOTSUPP; goto unmap_out; @@ -473,10 +474,16 @@ static int z_erofs_do_map_blocks(struct map->m_flags |= EROFS_MAP_META; map->m_pa = vi->z_fragmentoff; map->m_plen = vi->z_idata_size; + if (erofs_blkoff(sb, map->m_pa) + map->m_plen > sb->s_blocksize) { + erofs_err(sb, "invalid tail-packing pclustersize %llu", + map->m_plen); + err = -EFSCORRUPTED; + goto unmap_out; + } } else if (fragment && m.lcn == vi->z_tailextent_headlcn) { map->m_flags |= EROFS_MAP_FRAGMENT; } else { - map->m_pa = erofs_pos(inode->i_sb, m.pblk); + map->m_pa = erofs_pos(sb, m.pblk); err = z_erofs_get_extent_compressedlen(&m, initial_lcn); if (err) goto unmap_out; @@ -495,7 +502,7 @@ static int z_erofs_do_map_blocks(struct afmt = m.headtype == Z_EROFS_LCLUSTER_TYPE_HEAD2 ? vi->z_algorithmtype[1] : vi->z_algorithmtype[0]; if (!(EROFS_I_SB(inode)->available_compr_algs & (1 << afmt))) { - erofs_err(inode->i_sb, "inconsistent algorithmtype %u for nid %llu", + erofs_err(sb, "inconsistent algorithmtype %u for nid %llu", afmt, vi->nid); err = -EFSCORRUPTED; goto unmap_out; @@ -596,26 +603,8 @@ static int z_erofs_fill_inode_lazy(struc goto out_put_metabuf; } - if (vi->z_idata_size) { - struct erofs_map_blocks map = { - .buf = __EROFS_BUF_INITIALIZER - }; - - err = z_erofs_do_map_blocks(inode, &map, - EROFS_GET_BLOCKS_FINDTAIL); - erofs_put_metabuf(&map.buf); - - if (erofs_blkoff(sb, map.m_pa) + map.m_plen > sb->s_blocksize) { - erofs_err(sb, "invalid tail-packing pclustersize %llu", - map.m_plen); - err = -EFSCORRUPTED; - } - if (err < 0) - goto out_put_metabuf; - } - - if (vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER && - !(h->h_clusterbits >> Z_EROFS_FRAGMENT_INODE_BIT)) { + if (vi->z_idata_size || + (vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER)) { struct erofs_map_blocks map = { .buf = __EROFS_BUF_INITIALIZER };