lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20191211091049.11080-1-keitasuzuki.park@sslab.ics.keio.ac.jp>
Date:   Wed, 11 Dec 2019 09:10:49 +0000
From:   Keita Suzuki <keitasuzuki.park@...ab.ics.keio.ac.jp>
To:     unlisted-recipients:; (no To-header on input)
Cc:     keitasuzuki.park@...ab.ics.keio.ac.jp,
        takafumi.kubota1012@...ab.ics.keio.ac.jp, naohiro.aota@....com,
        Jens Axboe <axboe@...nel.dk>, linux-block@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: [PATCH RESEND] block/genhd: Fix memory leak in error path of __alloc_disk_node()

'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

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

Signed-off-by: Keita Suzuki <keitasuzuki.park@...ab.ics.keio.ac.jp>
Reviewed-by: Naohiro Aota <naohiro.aota@....com>
---
 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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ