Skip to contentSkip to conversation

erofs: ensure m_llen is reset to 0 if metadata is invalid

PATCH In review Gao Xiang 1 participant 2 messages Jun 29, 2024 – Jun 30, 2024 EROFS file system

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 erofs: ensure m_llen is reset to 0 if metadata is invalid

Sometimes, the on-disk metadata might be invalid due to storage failure or other unknown issues.

In that case, z_erofs_map_blocks_iter() may still return a valid m_llen while other fields remain invalid (e.g., m_plen can be 0).

Due to the return value of z_erofs_scan_folio() in some path will be ignored on purpose, the following z_erofs_scan_folio() could then use the invalid value by accident.

Let's reset m_llen to 0 to prevent this.

---
 fs/erofs/zmap.c | 2 ++
 1 file changed, 2 insertions(+)
fs/erofs/zmap.c +2 -0
index 9b248ee5fef2..74d3d7bffcf3 100644
@@ -711,6 +711,8 @@ int z_erofs_map_blocks_iter(struct inode *inode, struct erofs_map_blocks *map,
 
 	err = z_erofs_do_map_blocks(inode, map, flags);
 out:
+	if (err)
+		map->m_llen = 0;
 	trace_z_erofs_map_blocks_iter_exit(inode, map, flags, err);
 	return err;
 }
Signature · 1 line
2.43.5
author
#1 lore raw
Quoted 2 lines · Gao Xiang

Sometimes, the on-disk metadata might be invalid due to storage failure or other unknown issues.

user interrupts, storage failures, or other unknown causes.

Quoted 28 lines

In that case, z_erofs_map_blocks_iter() may still return a valid m_llen while other fields remain invalid (e.g., m_plen can be 0).

Due to the return value of z_erofs_scan_folio() in some path will be ignored on purpose, the following z_erofs_scan_folio() could then use the invalid value by accident.

Let's reset m_llen to 0 to prevent this.

---
  fs/erofs/zmap.c | 2 ++
  1 file changed, 2 insertions(+)
fs/erofs/zmap.c +2 -0
index 9b248ee5fef2..74d3d7bffcf3 100644
@@ -711,6 +711,8 @@ int z_erofs_map_blocks_iter(struct inode *inode, struct erofs_map_blocks *map,
 
  	err = z_erofs_do_map_blocks(inode, map, flags);
  out:
+	if (err)
+		map->m_llen = 0;
  	trace_z_erofs_map_blocks_iter_exit(inode, map, flags, err);
  	return err;
  }