mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhihao Cheng <chengzhihao1@huawei.com>
To: Li Zetao <lizetao1@huawei.com>, <richard@nod.at>,
	<miquel.raynal@bootlin.com>, <vigneshr@ti.com>,
	<dedekind@linutronix.de>, <haver@vnet.ibm.com>,
	<bbrezillon@kernel.org>
Cc: <boris.brezillon@free-electrons.com>,
	<linux-mtd@lists.infradead.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] ubi: Fix unreferenced object reported by kmemleak in ubi_resize_volume()
Date: Fri, 21 Oct 2022 21:24:48 +0800	[thread overview]
Message-ID: <9e6e3ed0-6709-320f-49b2-3e1056699647@huawei.com> (raw)
In-Reply-To: <20221021102157.1341807-3-lizetao1@huawei.com>

在 2022/10/21 18:21, Li Zetao 写道:
> There is a memory leaks problem reported by kmemleak:
>
> unreferenced object 0xffff888102007a00 (size 128):
>    comm "ubirsvol", pid 32090, jiffies 4298464136 (age 2361.231s)
>    hex dump (first 32 bytes):
> ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff  ................
> ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff  ................
>    backtrace:
> [<ffffffff8176cecd>] __kmalloc+0x4d/0x150
> [<ffffffffa02a9a36>] ubi_eba_create_table+0x76/0x170 [ubi]
> [<ffffffffa029764e>] ubi_resize_volume+0x1be/0xbc0 [ubi]
> [<ffffffffa02a3321>] ubi_cdev_ioctl+0x701/0x1850 [ubi]
> [<ffffffff81975d2d>] __x64_sys_ioctl+0x11d/0x170
> [<ffffffff83c142a5>] do_syscall_64+0x35/0x80
> [<ffffffff83e0006a>] entry_SYSCALL_64_after_hwframe+0x46/0xb0
>
> This is due to a mismatch between create and destroy interfaces, and
> in detail that "new_eba_tbl" created by ubi_eba_create_table() but
> destroyed by kfree(), while will causing "new_eba_tbl->entries" not
> freed.
>
> Fix it by replacing kfree(new_eba_tbl) with
> ubi_eba_destroy_table(new_eba_tbl)
>
> Fixes: 799dca34ac54 ("UBI: hide EBA internals")
> Signed-off-by: Li Zetao <lizetao1@huawei.com>
> ---
>   drivers/mtd/ubi/vmt.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
> index 74637575346e..9fbc64b997ce 100644
> --- a/drivers/mtd/ubi/vmt.c
> +++ b/drivers/mtd/ubi/vmt.c
> @@ -515,7 +515,7 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
>   	return err;
>   
>   out_free:
> -	kfree(new_eba_tbl);
> +	ubi_eba_destroy_table(new_eba_tbl);
>   	return err;
>   }
>   

Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>


      reply	other threads:[~2022-10-21 13:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-21 10:21 [PATCH 0/2] Fix use-after-free and " Li Zetao
2022-10-21 10:21 ` [PATCH 1/2] ubi: Fix use-after-free when volume resizing failed Li Zetao
2022-10-21 13:24   ` Zhihao Cheng
2022-10-21 10:21 ` [PATCH 2/2] ubi: Fix unreferenced object reported by kmemleak in ubi_resize_volume() Li Zetao
2022-10-21 13:24   ` Zhihao Cheng [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9e6e3ed0-6709-320f-49b2-3e1056699647@huawei.com \
    --to=chengzhihao1@huawei.com \
    --cc=bbrezillon@kernel.org \
    --cc=boris.brezillon@free-electrons.com \
    --cc=dedekind@linutronix.de \
    --cc=haver@vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=lizetao1@huawei.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®