mbox series

[-next,v3,0/2] jffs2: fix two memory leak when mount jffs2

Message ID 20220114102854.3399585-1-libaokun1@huawei.com
Headers show
Series jffs2: fix two memory leak when mount jffs2 | expand

Message

Baokun Li Jan. 14, 2022, 10:28 a.m. UTC
V1->V2:
	In jffs2_scan_medium,
	if s = kzalloc(sizeof(struct jffs2_summary), GFP_KERNEL);
	returns error, go to "out" to do clear. Null pointer dereference
	occurs when if (s->sum_list_head) is executed in "out".

V2->V3:
	Sorry for the noise, but there seems to be a more elegant way to
	fix the memory leak in jffs2_scan_medium. When memory allocation
	fails or CONFIG_JFFS2_SUMMARY is N, s is NULL.For the former case,
	add the new tag "out_buf" to avoid it.In the latter case,
	jffs2_sum_reset_collected is also an empty function and does nothing.

Baokun Li (2):
  jffs2: fix memory leak in jffs2_do_mount_fs
  jffs2: fix memory leak in jffs2_scan_medium

 fs/jffs2/build.c | 4 +++-
 fs/jffs2/scan.c  | 6 ++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

Comments

Baokun Li Feb. 18, 2022, 6:14 a.m. UTC | #1
在 2022/1/14 18:28, Baokun Li 写道:

ping

> V1->V2:
> 	In jffs2_scan_medium,
> 	if s = kzalloc(sizeof(struct jffs2_summary), GFP_KERNEL);
> 	returns error, go to "out" to do clear. Null pointer dereference
> 	occurs when if (s->sum_list_head) is executed in "out".
>
> V2->V3:
> 	Sorry for the noise, but there seems to be a more elegant way to
> 	fix the memory leak in jffs2_scan_medium. When memory allocation
> 	fails or CONFIG_JFFS2_SUMMARY is N, s is NULL.For the former case,
> 	add the new tag "out_buf" to avoid it.In the latter case,
> 	jffs2_sum_reset_collected is also an empty function and does nothing.
>
> Baokun Li (2):
>    jffs2: fix memory leak in jffs2_do_mount_fs
>    jffs2: fix memory leak in jffs2_scan_medium
>
>   fs/jffs2/build.c | 4 +++-
>   fs/jffs2/scan.c  | 6 ++++--
>   2 files changed, 7 insertions(+), 3 deletions(-)
>
Baokun Li March 10, 2022, 8:34 a.m. UTC | #2
A gentle ping, sorry for the noise.

在 2022/1/14 18:28, Baokun Li 写道:
> V1->V2:
> 	In jffs2_scan_medium,
> 	if s = kzalloc(sizeof(struct jffs2_summary), GFP_KERNEL);
> 	returns error, go to "out" to do clear. Null pointer dereference
> 	occurs when if (s->sum_list_head) is executed in "out".
>
> V2->V3:
> 	Sorry for the noise, but there seems to be a more elegant way to
> 	fix the memory leak in jffs2_scan_medium. When memory allocation
> 	fails or CONFIG_JFFS2_SUMMARY is N, s is NULL.For the former case,
> 	add the new tag "out_buf" to avoid it.In the latter case,
> 	jffs2_sum_reset_collected is also an empty function and does nothing.
>
> Baokun Li (2):
>    jffs2: fix memory leak in jffs2_do_mount_fs
>    jffs2: fix memory leak in jffs2_scan_medium
>
>   fs/jffs2/build.c | 4 +++-
>   fs/jffs2/scan.c  | 6 ++++--
>   2 files changed, 7 insertions(+), 3 deletions(-)
>
Richard Weinberger March 16, 2022, 10 p.m. UTC | #3
----- Ursprüngliche Mail -----
> Von: "libaokun" <libaokun1@huawei.com>
> An: "richard" <richard@nod.at>, "David Woodhouse" <dwmw2@infradead.org>, "linux-mtd" <linux-mtd@lists.infradead.org>,
> "linux-kernel" <linux-kernel@vger.kernel.org>
> CC: "yukuai3" <yukuai3@huawei.com>, "libaokun" <libaokun1@huawei.com>
> Gesendet: Donnerstag, 10. März 2022 09:34:35
> Betreff: Re: [PATCH -next v3 0/2] jffs2: fix two memory leak when mount jffs2

> A gentle ping, sorry for the noise.

Patches applied.
Thanks for fixing!

Thanks,
//richard
Baokun Li March 17, 2022, 1:39 a.m. UTC | #4
在 2022/3/17 6:00, Richard Weinberger 写道:
> ----- Ursprüngliche Mail -----
>> Von: "libaokun" <libaokun1@huawei.com>
>> An: "richard" <richard@nod.at>, "David Woodhouse" <dwmw2@infradead.org>, "linux-mtd" <linux-mtd@lists.infradead.org>,
>> "linux-kernel" <linux-kernel@vger.kernel.org>
>> CC: "yukuai3" <yukuai3@huawei.com>, "libaokun" <libaokun1@huawei.com>
>> Gesendet: Donnerstag, 10. März 2022 09:34:35
>> Betreff: Re: [PATCH -next v3 0/2] jffs2: fix two memory leak when mount jffs2
>> A gentle ping, sorry for the noise.
> Patches applied.
> Thanks for fixing!
>
> Thanks,
> //richard
> .


Thank you for your review!