All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] erofs: fix inline pcluster memory leak
@ 2022-12-02  3:33 ` Gao Xiang
  0 siblings, 0 replies; 3+ messages in thread
From: Gao Xiang @ 2022-12-02  3:33 UTC (permalink / raw)
  To: linux-erofs, Yue Hu, Chao Yu
  Cc: Gao Xiang, Yue Hu, LKML, syzbot+6f8cd9a0155b366d227f

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

Reported-by: syzbot+6f8cd9a0155b366d227f@syzkaller.appspotmail.com
Fixes: cecf864d3d76 ("erofs: support inline data decompression")
Cc: Yue Hu <huyue2@yulong.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
 fs/erofs/zdata.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
index ab22100be861..e14e6c32e70d 100644
--- a/fs/erofs/zdata.c
+++ b/fs/erofs/zdata.c
@@ -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;
 }
 
-- 
2.24.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] erofs: fix inline pcluster memory leak
@ 2022-12-02  3:33 ` Gao Xiang
  0 siblings, 0 replies; 3+ messages in thread
From: Gao Xiang @ 2022-12-02  3:33 UTC (permalink / raw)
  To: linux-erofs, Yue Hu, Chao Yu
  Cc: LKML, Gao Xiang, syzbot+6f8cd9a0155b366d227f, Yue Hu

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

Reported-by: syzbot+6f8cd9a0155b366d227f@syzkaller.appspotmail.com
Fixes: cecf864d3d76 ("erofs: support inline data decompression")
Cc: Yue Hu <huyue2@yulong.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
 fs/erofs/zdata.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
index ab22100be861..e14e6c32e70d 100644
--- a/fs/erofs/zdata.c
+++ b/fs/erofs/zdata.c
@@ -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;
 }
 
-- 
2.24.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] erofs: fix inline pcluster memory leak
  2022-12-02  3:33 ` Gao Xiang
  (?)
@ 2022-12-02  4:04 ` Yue Hu
  -1 siblings, 0 replies; 3+ messages in thread
From: Yue Hu @ 2022-12-02  4:04 UTC (permalink / raw)
  To: Gao Xiang
  Cc: syzbot+6f8cd9a0155b366d227f, LKML, zhangwen, Yue Hu, linux-erofs

[-- Attachment #1: Type: text/plain, Size: 1422 bytes --]

On Fri,  2 Dec 2022 11:33:27 +0800
Gao Xiang <hsiangkao@linux.alibaba.com> wrote:

> Inline pcluster should be freed right after it is decompressed.
> Otherwise inline pclusters will be leaked.
> 
> Reported-by: syzbot+6f8cd9a0155b366d227f@syzkaller.appspotmail.com
> Fixes: cecf864d3d76 ("erofs: support inline data decompression")
> Cc: Yue Hu <huyue2@yulong.com>
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Reviewed-by: Yue Hu <huyue2@coolpad.com>

Thanks.

> ---
>  fs/erofs/zdata.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
> index ab22100be861..e14e6c32e70d 100644
> --- a/fs/erofs/zdata.c
> +++ b/fs/erofs/zdata.c
> @@ -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;
>  }
>

[-- Attachment #2: Type: text/html, Size: 3122 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-12-02  4:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-02  3:33 [PATCH] erofs: fix inline pcluster memory leak Gao Xiang
2022-12-02  3:33 ` Gao Xiang
2022-12-02  4:04 ` Yue Hu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.