Skip to contentSkip to conversation

erofs: fix inline pcluster memory leak

PATCH In review Gao Xiang 2 participants 2 messages Dec 2, 2022 EROFS file system

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 erofs: fix inline pcluster memory leak

Inline pcluster should be freed right after it is decompressed. Otherwise inline pclusters will be leaked.

Reported-by [email protected]
Fixes cecf864d3d76 ("erofs: support inline data decompression")
Cc Yue Hu <[email protected]>
---
 fs/erofs/zdata.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/erofs/zdata.c +4 -1
index ab22100be861..e14e6c32e70d 100644
@@ -496,7 +496,8 @@ static int z_erofs_register_pcluster(struct z_erofs_decompress_frontend *fe)
 	struct erofs_workgroup *grp;
 	int err;
 
-	if (!(map->m_flags & EROFS_MAP_ENCODED)) {
+	if (!(map->m_flags & EROFS_MAP_ENCODED) ||
+	    !(map->m_pa >> PAGE_SHIFT)) {
 		DBG_BUGON(1);
 		return -EFSCORRUPTED;
 	}
@@ -1114,6 +1115,8 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
 	/* pcluster lock MUST be taken before the following line */
 	WRITE_ONCE(pcl->next, Z_EROFS_PCLUSTER_NIL);
 	mutex_unlock(&pcl->lock);
+	if (z_erofs_is_inline_pcluster(pcl))
+		z_erofs_free_pcluster(pcl);
 	return err;
 }
 
Signature · 1 line
2.24.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · On Fri, 2 Dec 2022 11:33:27 +0800 Gao Xiang <[email protected]>…

Inline pcluster should be freed right after it is decompressed. Otherwise inline pclusters will be leaked.

Reported-by [email protected]
Fixes cecf864d3d76 ("erofs: support inline data decompression")
Cc Yue Hu <[email protected]>

Thanks.

Quoted 27 lines
---
 fs/erofs/zdata.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/erofs/zdata.c +4 -1
index ab22100be861..e14e6c32e70d 100644
@@ -496,7 +496,8 @@ static int z_erofs_register_pcluster(struct z_erofs_decompress_frontend *fe)
 	struct erofs_workgroup *grp;
 	int err;
 
-	if (!(map->m_flags & EROFS_MAP_ENCODED)) {
+	if (!(map->m_flags & EROFS_MAP_ENCODED) ||
+	    !(map->m_pa >> PAGE_SHIFT)) {
 		DBG_BUGON(1);
 		return -EFSCORRUPTED;
 	}
@@ -1114,6 +1115,8 @@ static int z_erofs_decompress_pcluster(struct z_erofs_decompress_backend *be,
 	/* pcluster lock MUST be taken before the following line */
 	WRITE_ONCE(pcl->next, Z_EROFS_PCLUSTER_NIL);
 	mutex_unlock(&pcl->lock);
+	if (z_erofs_is_inline_pcluster(pcl))
+		z_erofs_free_pcluster(pcl);
 	return err;
 }