linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ubifs: fix memory leak from c->sup_node
@ 2020-01-14  5:43 quanyang.wang
  2020-01-14  9:20 ` Sascha Hauer
  0 siblings, 1 reply; 3+ messages in thread
From: quanyang.wang @ 2020-01-14  5:43 UTC (permalink / raw)
  To: richard, s.hauer; +Cc: linux-mtd, linux-kernel, quanyang.wang

From: Quanyang Wang <quanyang.wang@windriver.com>

The c->sup_node is allocated in function ubifs_read_sb_node but
is not freed. This will cause memory leak as below:

unreferenced object 0xbc9ce000 (size 4096):
  comm "mount", pid 500, jiffies 4294952946 (age 315.820s)
  hex dump (first 32 bytes):
    31 18 10 06 06 7b f1 11 02 00 00 00 00 00 00 00  1....{..........
    00 10 00 00 06 00 00 00 00 00 00 00 08 00 00 00  ................
  backtrace:
    [<d1c503cd>] ubifs_read_superblock+0x48/0xebc
    [<a20e14bd>] ubifs_mount+0x974/0x1420
    [<8589ecc3>] legacy_get_tree+0x2c/0x50
    [<5f1fb889>] vfs_get_tree+0x28/0xfc
    [<bbfc7939>] do_mount+0x4f8/0x748
    [<4151f538>] ksys_mount+0x78/0xa0
    [<d59910a9>] ret_fast_syscall+0x0/0x54
    [<1cc40005>] 0x7ea02790

Free it in ubifs_umount and in the error path of mount_ubifs.

Fixes: fd6150051bec ("ubifs: Store read superblock node")
Signed-off-by: Quanyang Wang <quanyang.wang@windriver.com>
---
 fs/ubifs/super.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
index 7d4547e5202d..a4412c259bb3 100644
--- a/fs/ubifs/super.c
+++ b/fs/ubifs/super.c
@@ -1599,6 +1599,7 @@ static int mount_ubifs(struct ubifs_info *c)
 	vfree(c->ileb_buf);
 	vfree(c->sbuf);
 	kfree(c->bottom_up_buf);
+	kfree(c->sup_node);
 	ubifs_debugging_exit(c);
 	return err;
 }
@@ -1641,6 +1642,7 @@ static void ubifs_umount(struct ubifs_info *c)
 	vfree(c->ileb_buf);
 	vfree(c->sbuf);
 	kfree(c->bottom_up_buf);
+	kfree(c->sup_node);
 	ubifs_debugging_exit(c);
 }
 
-- 
2.17.1


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

* Re: [PATCH] ubifs: fix memory leak from c->sup_node
  2020-01-14  5:43 [PATCH] ubifs: fix memory leak from c->sup_node quanyang.wang
@ 2020-01-14  9:20 ` Sascha Hauer
  2020-01-16 23:54   ` Richard Weinberger
  0 siblings, 1 reply; 3+ messages in thread
From: Sascha Hauer @ 2020-01-14  9:20 UTC (permalink / raw)
  To: quanyang.wang; +Cc: richard, linux-mtd, linux-kernel

On Tue, Jan 14, 2020 at 01:43:11PM +0800, quanyang.wang@windriver.com wrote:
> From: Quanyang Wang <quanyang.wang@windriver.com>
> 
> The c->sup_node is allocated in function ubifs_read_sb_node but
> is not freed. This will cause memory leak as below:
> 
> unreferenced object 0xbc9ce000 (size 4096):
>   comm "mount", pid 500, jiffies 4294952946 (age 315.820s)
>   hex dump (first 32 bytes):
>     31 18 10 06 06 7b f1 11 02 00 00 00 00 00 00 00  1....{..........
>     00 10 00 00 06 00 00 00 00 00 00 00 08 00 00 00  ................
>   backtrace:
>     [<d1c503cd>] ubifs_read_superblock+0x48/0xebc
>     [<a20e14bd>] ubifs_mount+0x974/0x1420
>     [<8589ecc3>] legacy_get_tree+0x2c/0x50
>     [<5f1fb889>] vfs_get_tree+0x28/0xfc
>     [<bbfc7939>] do_mount+0x4f8/0x748
>     [<4151f538>] ksys_mount+0x78/0xa0
>     [<d59910a9>] ret_fast_syscall+0x0/0x54
>     [<1cc40005>] 0x7ea02790
> 
> Free it in ubifs_umount and in the error path of mount_ubifs.
> 
> Fixes: fd6150051bec ("ubifs: Store read superblock node")
> Signed-off-by: Quanyang Wang <quanyang.wang@windriver.com>

Looks good.

Reviewed-by: Sascha Hauer <s.hauer@pengutronix.de>

Sascha

> ---
>  fs/ubifs/super.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
> index 7d4547e5202d..a4412c259bb3 100644
> --- a/fs/ubifs/super.c
> +++ b/fs/ubifs/super.c
> @@ -1599,6 +1599,7 @@ static int mount_ubifs(struct ubifs_info *c)
>  	vfree(c->ileb_buf);
>  	vfree(c->sbuf);
>  	kfree(c->bottom_up_buf);
> +	kfree(c->sup_node);
>  	ubifs_debugging_exit(c);
>  	return err;
>  }
> @@ -1641,6 +1642,7 @@ static void ubifs_umount(struct ubifs_info *c)
>  	vfree(c->ileb_buf);
>  	vfree(c->sbuf);
>  	kfree(c->bottom_up_buf);
> +	kfree(c->sup_node);
>  	ubifs_debugging_exit(c);
>  }
>  
> -- 
> 2.17.1
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

* Re: [PATCH] ubifs: fix memory leak from c->sup_node
  2020-01-14  9:20 ` Sascha Hauer
@ 2020-01-16 23:54   ` Richard Weinberger
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Weinberger @ 2020-01-16 23:54 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: quanyang.wang, Richard Weinberger, linux-mtd, LKML

On Tue, Jan 14, 2020 at 10:21 AM Sascha Hauer <s.hauer@pengutronix.de> wrote:
>
> On Tue, Jan 14, 2020 at 01:43:11PM +0800, quanyang.wang@windriver.com wrote:
> > From: Quanyang Wang <quanyang.wang@windriver.com>
> >
> > The c->sup_node is allocated in function ubifs_read_sb_node but
> > is not freed. This will cause memory leak as below:
> >
> > unreferenced object 0xbc9ce000 (size 4096):
> >   comm "mount", pid 500, jiffies 4294952946 (age 315.820s)
> >   hex dump (first 32 bytes):
> >     31 18 10 06 06 7b f1 11 02 00 00 00 00 00 00 00  1....{..........
> >     00 10 00 00 06 00 00 00 00 00 00 00 08 00 00 00  ................
> >   backtrace:
> >     [<d1c503cd>] ubifs_read_superblock+0x48/0xebc
> >     [<a20e14bd>] ubifs_mount+0x974/0x1420
> >     [<8589ecc3>] legacy_get_tree+0x2c/0x50
> >     [<5f1fb889>] vfs_get_tree+0x28/0xfc
> >     [<bbfc7939>] do_mount+0x4f8/0x748
> >     [<4151f538>] ksys_mount+0x78/0xa0
> >     [<d59910a9>] ret_fast_syscall+0x0/0x54
> >     [<1cc40005>] 0x7ea02790
> >
> > Free it in ubifs_umount and in the error path of mount_ubifs.
> >
> > Fixes: fd6150051bec ("ubifs: Store read superblock node")
> > Signed-off-by: Quanyang Wang <quanyang.wang@windriver.com>
>
> Looks good.
>
> Reviewed-by: Sascha Hauer <s.hauer@pengutronix.de>

Hm, this one is not in patchwork.
Anyway, applied. Thanks for fixing!

-- 
Thanks,
//richard

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

end of thread, other threads:[~2020-01-16 23:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-14  5:43 [PATCH] ubifs: fix memory leak from c->sup_node quanyang.wang
2020-01-14  9:20 ` Sascha Hauer
2020-01-16 23:54   ` Richard Weinberger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).