Skip to content

Commit 7c3ca18

Browse files
committed
erofs: restrict pcluster size limitations
Error out if {en,de}encoded size of a pcluster is unsupported: Maximum supported encoded size (of a pcluster): 1 MiB Maximum supported decoded size (of a pcluster): 12 MiB Users can still choose to use supported large configurations (e.g., for archival purposes), but there may be performance penalties in low-memory scenarios compared to smaller pclusters. Reviewed-by: Chao Yu <chao@kernel.org> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com> Link: https://lore.kernel.org/r/20240912074156.2925394-1-hsiangkao@linux.alibaba.com
1 parent 79f504a commit 7c3ca18

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

fs/erofs/erofs_fs.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,12 @@ struct erofs_dirent {
288288

289289
#define EROFS_NAME_LEN 255
290290

291-
/* maximum supported size of a physical compression cluster */
291+
/* maximum supported encoded size of a physical compressed cluster */
292292
#define Z_EROFS_PCLUSTER_MAX_SIZE (1024 * 1024)
293293

294+
/* maximum supported decoded size of a physical compressed cluster */
295+
#define Z_EROFS_PCLUSTER_MAX_DSIZE (12 * 1024 * 1024)
296+
294297
/* available compression algorithm types (for h_algorithmtype) */
295298
enum {
296299
Z_EROFS_COMPRESSION_LZ4 = 0,

fs/erofs/zmap.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -687,32 +687,30 @@ int z_erofs_map_blocks_iter(struct inode *inode, struct erofs_map_blocks *map,
687687
int err = 0;
688688

689689
trace_erofs_map_blocks_enter(inode, map, flags);
690-
691-
/* when trying to read beyond EOF, leave it unmapped */
692-
if (map->m_la >= inode->i_size) {
690+
if (map->m_la >= inode->i_size) { /* post-EOF unmapped extent */
693691
map->m_llen = map->m_la + 1 - inode->i_size;
694692
map->m_la = inode->i_size;
695693
map->m_flags = 0;
696-
goto out;
697-
}
698-
699-
err = z_erofs_fill_inode_lazy(inode);
700-
if (err)
701-
goto out;
702-
703-
if ((vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER) &&
704-
!vi->z_tailextent_headlcn) {
705-
map->m_la = 0;
706-
map->m_llen = inode->i_size;
707-
map->m_flags = EROFS_MAP_MAPPED | EROFS_MAP_FULL_MAPPED |
708-
EROFS_MAP_FRAGMENT;
709-
goto out;
694+
} else {
695+
err = z_erofs_fill_inode_lazy(inode);
696+
if (!err) {
697+
if ((vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER) &&
698+
!vi->z_tailextent_headlcn) {
699+
map->m_la = 0;
700+
map->m_llen = inode->i_size;
701+
map->m_flags = EROFS_MAP_MAPPED |
702+
EROFS_MAP_FULL_MAPPED | EROFS_MAP_FRAGMENT;
703+
} else {
704+
err = z_erofs_do_map_blocks(inode, map, flags);
705+
}
706+
}
707+
if (!err && (map->m_flags & EROFS_MAP_ENCODED) &&
708+
unlikely(map->m_plen > Z_EROFS_PCLUSTER_MAX_SIZE ||
709+
map->m_llen > Z_EROFS_PCLUSTER_MAX_DSIZE))
710+
err = -EOPNOTSUPP;
711+
if (err)
712+
map->m_llen = 0;
710713
}
711-
712-
err = z_erofs_do_map_blocks(inode, map, flags);
713-
out:
714-
if (err)
715-
map->m_llen = 0;
716714
trace_erofs_map_blocks_exit(inode, map, flags, err);
717715
return err;
718716
}

0 commit comments

Comments
 (0)