Linux-Block Archive on lore.kernel.org
 help / color / Atom feed
From: Naohiro Aota <naohiro.aota@wdc.com>
To: Keita Suzuki <keitasuzuki.park@sslab.ics.keio.ac.jp>
Cc: Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	takafumi.kubota1012@sslab.ics.keio.ac.jp
Subject: Re: [PATCH] block/genhd: Fix memory leak in error path of __alloc_disk_node()
Date: Wed, 4 Dec 2019 18:56:15 +0900
Message-ID: <20191204095615.m3bgg276re3qlzzm@naota> (raw)
In-Reply-To: <20191127024057.5827-1-keitasuzuki.park@sslab.ics.keio.ac.jp>

Looks good,
Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>

I think you can also add:

Fixes: 6c71013ecb7e ("block: partition: convert percpu ref")

On Wed, Nov 27, 2019 at 02:40:57AM +0000, Keita Suzuki wrote:
>'disk->part_tbl' is malloced in disk_expand_part_tbl() and should be
>freed before leaving from the error handling cases. However, current code
>does not free this, causing a memory leak. Add disk_replace_part_tbl()
>before freeing 'disk'.
>
>I have tested this by randomly causing failures to the target code,
>and verified on kmemleak that this memory leak does occur.
>
>unreferenced object 0xffff888006dad500 (size 64):
>  comm "systemd-udevd", pid 116, jiffies 4294895558 (age 121.716s)
>  hex dump (first 32 bytes):
>    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
>    01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
>  backtrace:
>    [<00000000eec79bf3>] disk_expand_part_tbl+0xab/0x170
>    [<00000000624e7d03>] __alloc_disk_node+0xb1/0x1c0
>    [<00000000ca3f4185>] 0xffffffffc01b8584
>    [<000000006f88a6ee>] do_one_initcall+0x8b/0x2a4
>    [<0000000016058199>] do_init_module+0xfd/0x380
>    [<00000000b6fde336>] load_module+0x3fae/0x4240
>    [<00000000c523d013>] __do_sys_finit_module+0x11a/0x1b0
>    [<00000000f07bba26>] do_syscall_64+0x6d/0x1e0
>    [<00000000979467fd>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
>
>Signed-off-by: Keita Suzuki <keitasuzuki.park@sslab.ics.keio.ac.jp>
>---
> block/genhd.c | 1 +
> 1 file changed, 1 insertion(+)
>
>diff --git a/block/genhd.c b/block/genhd.c
>index ff6268970ddc..8c4b63d7f507 100644
>--- a/block/genhd.c
>+++ b/block/genhd.c
>@@ -1504,6 +1504,7 @@ struct gendisk *__alloc_disk_node(int minors, int node_id)
> 		 */
> 		seqcount_init(&disk->part0.nr_sects_seq);
> 		if (hd_ref_init(&disk->part0)) {
>+			disk_replace_part_tbl(disk, NULL);
> 			hd_free_part(&disk->part0);
> 			kfree(disk);
> 			return NULL;
>-- 
>2.17.1
>

  reply index

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-27  2:40 Keita Suzuki
2019-12-04  9:56 ` Naohiro Aota [this message]
2019-12-11  9:10 ` [PATCH RESEND] " Keita Suzuki

Reply instructions:

You may reply publically 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=20191204095615.m3bgg276re3qlzzm@naota \
    --to=naohiro.aota@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=keitasuzuki.park@sslab.ics.keio.ac.jp \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=takafumi.kubota1012@sslab.ics.keio.ac.jp \
    /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

Linux-Block Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-block/0 linux-block/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-block linux-block/ https://lore.kernel.org/linux-block \
		linux-block@vger.kernel.org
	public-inbox-index linux-block

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-block


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git