Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp243611ybl; Wed, 4 Dec 2019 01:57:04 -0800 (PST) X-Google-Smtp-Source: APXvYqw2LW22eOlSQ5yLhLiWrihxCGHpjhKjlYRL4rYCbaYdV3qzIhZteZ++k+m3xpJb558tbBeX X-Received: by 2002:aca:494b:: with SMTP id w72mr1907328oia.58.1575453424817; Wed, 04 Dec 2019 01:57:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575453424; cv=none; d=google.com; s=arc-20160816; b=vg3C4+KLSG9rjHiaNM5RfgqkQ/ab+bYSQ5TbrjfAp7pnluPs8/LCA9YYO0vXGmHLDh QbutcURiXEJwfRBSn8rxSVcdU4lZ/2AFSCIYcm1IoOdSjja3XKs2C+AUe9c3CMSIVZ/n VElR5HeAqo4fFqnXMeuo/Mt9rqlKg3YBc98v1ZfdNdTAWCDKV/ouYW1CuhUDgQstBWe5 W8HDwzbt7vqq789fK8kjGKAC9OdfwgtUXLTnhlEMoOn5L2xQhXrOWgXt61+S3DUijdli 4PPNs/S0VFiJV6oAjvlhNIW9wFQ9+XLrlqx7Qf/fGDUFqMXqYyjALagzJ6Sr+jiI4tfB p4mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :wdcironportexception:ironport-sdr:ironport-sdr:ironport-sdr :dkim-signature; bh=ZzpTuXIhi7IyYS7PfY44Y8IZ5KnHdN+vq2Phm2+yP9Y=; b=qDqYlH0eCds/jBz0D1lEqaWWGa9W3PXmy98okWsq4MRXvloh7ji2cof5Aza6DW1iZN p/yukfR3ZbsOTmqx2B5nH/OWuAJAWi/1cr2R/RENCh1vPHQxbMreOu71MdYkdh+kj0C5 lxyn9Llb7IkajJqhL92xDjToHJS3jPUvrwwLIhBXSCZneZMPpXrN/HfQeyfmef5P7G2B gz7C57UddKi4g3qXiN9aRbTT1vn8meehaoTScCBvPkKHY9uA3F5KNh94WGQdnQ669zPJ hvXx4UpWkBHD0oydhA1f6SJsv8L8B0JguY58fq9YQjn/gVYWr38/NUsGFKqR359c/jQd kCQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=gucdqSjo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w131si2912603oif.240.2019.12.04.01.56.51; Wed, 04 Dec 2019 01:57:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=gucdqSjo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727331AbfLDJ4T (ORCPT + 99 others); Wed, 4 Dec 2019 04:56:19 -0500 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:20593 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726166AbfLDJ4S (ORCPT ); Wed, 4 Dec 2019 04:56:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575453378; x=1606989378; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=MMrvsNDMLWAbO9MEILS+TGm8he4BEQEN8YqOwckuQ28=; b=gucdqSjonYHQmMsCEWVSWqqYZ60hnejCFCtCMs42PjMRTscBaQ2PskhT 6v6OztecqDdn+PPbbSRUite9MFB0MiKPM36887bCXfOnastvJqwykabVz pnIqktXz30ocPRLHAJ1HwsMzeK31M3YtUwd5f8sC5uSeoN8oynSub0fzj FnTs0bKLah8DBCtByL9U57AphoeNpbdOC900opNIMYn6/3G4nhInt+W6H nZIhbO/EMSH8WwiBkZ3nodCtD62zeu4GvXrklYJR0LsjV/eNDuE6DATni b7dp3yHjy3whOKxbgPQhYy4lPXsboTRWM11WArGEGSjdlWLMkvka5XjYr A==; IronPort-SDR: aKXmKjVRUkKE8iwJNshlIPLRqo6g+AtE8o9yo0fAmaj0VEFHYz1u3hRJoPhJTRPwBavB8x+1Fe kVdQCqU6xfBXK+CJxcWXtmkZ15SZaDd8qWm+HnA7JtuFFhnXnTrS9arEn8VlfzO4fghjj151T7 beLltUwUNXhgNhskCYgRRkr7RCIBOFVwaqNUPDIZBuB14MsuSe3C9/tRKlFcqPADKwm/supzFY dIPS+wguCW6Q7Y716qLtuoI6/osLlmdu8EOAacseQ1mor0EJLhoIXJQbkumQGzzxWaIvSgSayN BaM= X-IronPort-AV: E=Sophos;i="5.69,277,1571673600"; d="scan'208";a="125363481" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 04 Dec 2019 17:56:18 +0800 IronPort-SDR: WEUnwhIVQYIKrP2/Kxc7b0dvSWUALKTptRDdbg6PgBcjfKm+SHNhakENdN+ZMCfHp8M9M5K9Qm 0u/F+5ot23YO9s7ewqEUcyOv9VojB+zTASL7LGRqluIBv4hdZJ+RNFRjEh4agVJSJYC7E38qOQ 8CiuMNqFHztXRJHvGhgxGE4mVnB9A2Wjv74fvWS/r4+SjjenGr9Qw6luSuoPNCwMN31NnospxN Omv8PdcZEIa6lYlN1pyrx8/OeXAK8PKcDI7zrkG9DpudOgh87aOWpOi8Er0NQ9Q+uTgVkH57ah My2mqd3hjg9qtKINaqL698UX Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 01:51:05 -0800 IronPort-SDR: 2+0hE7nYdSw2DI7ET7vzyzVgDLnT6I53JDmEJH5Nsy1KZSawtvq8njkWFl9HdZra7trNIVvI9+ +C3jml8b1i7kk66snO1rJW0Yl6flU2QlI60KsHSx9tad1F7Ls6eiIwTonTvkZFRABdIm7iXkCT P4qkpuriPOl+U1UUmICciYWBWYGIFFp7jwfuppSvxWFB86hsMWVYpUlBX0QhqvxfmBZexH07Vb AtXjBp9ii+mFLhHRWztk6f9NNxjx5ozr6XIrvjCdyH49tnHx9XC7LLjcEviRXPwCZTpiYRQJoW DC4= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.53.115]) by uls-op-cesaip02.wdc.com with SMTP; 04 Dec 2019 01:56:16 -0800 Received: (nullmailer pid 1154193 invoked by uid 1000); Wed, 04 Dec 2019 09:56:15 -0000 Date: Wed, 4 Dec 2019 18:56:15 +0900 From: Naohiro Aota To: Keita Suzuki Cc: Jens Axboe , 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() Message-ID: <20191204095615.m3bgg276re3qlzzm@naota> References: <20191127024057.5827-1-keitasuzuki.park@sslab.ics.keio.ac.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20191127024057.5827-1-keitasuzuki.park@sslab.ics.keio.ac.jp> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Looks good, Reviewed-by: Naohiro Aota 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 >--- > 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 >