Skip to contentSkip to conversation

erofs: fix validation in z_erofs_do_map_blocks()

PATCH In review Noboru Asai 2 participants 2 messages Mar 3, 2023 EROFS file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs: fix validation in z_erofs_do_map_blocks()

In case of reading fragment data, map->m_plen is invalid.

Fixes c505feba4c0d ("erofs: validate the extent length for uncompressed pclusters")
---
 fs/erofs/zmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/erofs/zmap.c +1 -1
index 8bf6d30518b6..902b166a5a5e 100644
@@ -572,7 +572,7 @@ static int z_erofs_do_map_blocks(struct inode *inode,
 	}
 
 	if (m.headtype == Z_EROFS_VLE_CLUSTER_TYPE_PLAIN) {
-		if (map->m_llen > map->m_plen) {
+		if (!(map->m_flags & EROFS_MAP_FRAGMENT) && (map->m_llen > map->m_plen) {
 			DBG_BUGON(1);
 			err = -EFSCORRUPTED;
 			goto unmap_out;
Signature · 1 line
2.39.2
#1 lore raw

Hi Noboru,

Quoted 4 lines · Noboru Asai

In case of reading fragment data, map->m_plen is invalid.

Fixes c505feba4c0d ("erofs: validate the extent length for uncompressed pclusters")

Thanks for the report and patch!

I've already found this issue and I think it's actually a misuse to Z_EROFS_VLE_CLUSTER_TYPE_PLAIN for fragment pclusters in mkfs.erofs.

So I fixed in erofs-utils:
https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/commit/?id=ef74e215647e0d602d5e24039acbcfb18e55e516

Since erofs-utils v1.6 is not released yet, so it won't impact anything at all.

Thanks,
Gao Xiang

Quoted 17 lines
---
  fs/erofs/zmap.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/erofs/zmap.c +1 -1
index 8bf6d30518b6..902b166a5a5e 100644
@@ -572,7 +572,7 @@ static int z_erofs_do_map_blocks(struct inode *inode,
  	}
 
  	if (m.headtype == Z_EROFS_VLE_CLUSTER_TYPE_PLAIN) {
-		if (map->m_llen > map->m_plen) {
+		if (!(map->m_flags & EROFS_MAP_FRAGMENT) && (map->m_llen > map->m_plen) {
  			DBG_BUGON(1);
  			err = -EFSCORRUPTED;
  			goto unmap_out;