Received: by 10.223.176.46 with SMTP id f43csp249474wra; Tue, 23 Jan 2018 20:15:58 -0800 (PST) X-Google-Smtp-Source: AH8x2268+GuLM0s9Ub7cRAniSUwYhcu16ZO4dV/izlUIn0BWhhjwvNUvk179MxUJEzwUCtE8WtiB X-Received: by 2002:a17:902:52cb:: with SMTP id a69-v6mr642834pli.143.1516767358745; Tue, 23 Jan 2018 20:15:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516767358; cv=none; d=google.com; s=arc-20160816; b=bopqBucJGEk5RcGiYd5TNPwRluMpfTi6jpTTBY4NTHCg96wKYWmKSLdXYNapob8qU8 G4YpeSbPTqNblG+Dlv+ig3wRo3Yxsv9JYdpD8UHOvOA+ZFRHzGRO4A1y6KZuheWljMA9 iFxJ5DbXnQX/KEKAS3LYLDeQARB28444omI3eYk3Y/F9DxLlLJ6+hE9NWP/fyv414YiY FYk/TT+31kG2bFOTWUE0rLMvtkyiGYY3yPEmY+9SekPUm4b2GrUgmeH9wvF6n0dFQNdJ POboPC9WwSTlvApsCuAY/V9+ZFS9T9Zo2MD2jyrEQ2Z9ZSZbA6Boir9dnR/WFRNydCr7 3Shw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticoutput:content-language:accept-language:in-reply-to :references:message-id:date:thread-index:thread-topic:subject:cc:to :from:dkim-signature:arc-authentication-results; bh=PH7oswZ0zp1jNSLAg3hKjkk8Q/nSG6eDKjyoDMslduA=; b=XmzVL37J7o/xdQ0yaUyphsemMG+AudQp9dhLR0pmlxrgNURwMud3Vtl+BxP2vlGNVg EWW+aXU3ay2NZa46bYNjH6PvWKNTE+emUjyFV2QpvnLHmiibcc2CJJ+1wXEzMcLg8Fo+ 8kAPxCy+dNEwLFQZzT698NsTvAPBIielHeTue87XQlalk3fdmBtzWK1pdXqhNwgaKw6q jlqc2iLV/y2o7C5JNtOg1n83rsDRvq5+JEhflBTE5f27sSQPFjnAlBZ3qYq8/etKI6M5 W1nNezXLjQGbMo1IQn90RoDUk0vNoPbd0NKVLZ82BhhYXyx1F4v8c05nwrRDyTyLnM7e wBDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=BMEGbe1w; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h3si7846449pgc.179.2018.01.23.20.15.44; Tue, 23 Jan 2018 20:15:58 -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=pass header.i=@microsoft.com header.s=selector1 header.b=BMEGbe1w; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752773AbeAXEOl (ORCPT + 99 others); Tue, 23 Jan 2018 23:14:41 -0500 Received: from mail-cys01nam02hn0220.outbound.protection.outlook.com ([104.47.37.220]:39506 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752726AbeAXEOj (ORCPT ); Tue, 23 Jan 2018 23:14:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=PH7oswZ0zp1jNSLAg3hKjkk8Q/nSG6eDKjyoDMslduA=; b=BMEGbe1wMEI7ptpcST1DvJTTd5ZhlVJ9TY/EKzoRG3vx4mKxwClJcTuXM41eUc1RqrYi5lIuZsOU8ANViV0WPdMmypyW9niMZe2zB2ia6QwQHC7JQOQXe2JHNGdsqSxHyWgeog9imPtCZxH0cvcUmJdD2+mUu7Y+Xd0R80drImo= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1080.namprd21.prod.outlook.com (52.132.130.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.464.1; Wed, 24 Jan 2018 04:14:36 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7%2]) with mapi id 15.20.0464.000; Wed, 24 Jan 2018 04:14:36 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: David Disseldorp , Jens Axboe , "Sasha Levin" Subject: [PATCH AUTOSEL for 4.14 027/100] null_blk: fix dev->badblocks leak Thread-Topic: [PATCH AUTOSEL for 4.14 027/100] null_blk: fix dev->badblocks leak Thread-Index: AQHTlMnYkYfLvystTUiE6ewwzM/HIA== Date: Wed, 24 Jan 2018 04:14:36 +0000 Message-ID: <20180124041414.32065-27-alexander.levin@microsoft.com> References: <20180124041414.32065-1-alexander.levin@microsoft.com> In-Reply-To: <20180124041414.32065-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1080;6:F5mQlsSVC/OKYprt2uFUTEQiQBRnubsSWYZp2PCYFircxHBZxeRCfUg/1mMtr/CzmAeK4qxwPqRiqNUY//AHtXKRIpz9qwP9avCAjZwVOCmNnn3/OtWRBTDsmcfbtQr9pr6An+Uhyj0EQBwMNNzaa+28t/DFPOoFnaqUt7+8+GA0YILlDtyqdcIxoENBRLk0+ZBXAn/ZTjWLSYT4dItoecPvEmfs6fxDtzVC8DQzHfbH/MskCaWduR8B5UMOsmuYFK+8zvfpubMHQlL1XjS20OGqOmE8Ukunwz9FbeQM8JqqDIsVyoeCqnv9GLui2mKbeeJQTVgjmmKQDHoWCvzoBnDh2JlXx82uNTaONHucHWaRL7f+GhkYCfXTvgED3WtH9FFoi1ATlChhcHEnRaSJhg==;5:jPhUsYC8fOUJzf46lQdUlZrrwCtSgyzzQRRVF5RnvCgwVR3e9kVe0TpdZdQiFnqQIgw6qUxRUilwFYndgPmWJG8eo5iAQDddPlUFnANA33miqEtv/xWKVIQvQtBQV83DLLbEx73QwPxDNNQTEfYsLCl1cBnflquCmeVQJ9s9bkA=;24:fgOpAkXAXEb4BL0E2rFYGVv5/u61lIoLx8ZxDT0VRrRSPNBriPhDtSHIX1/G/NUL30Kfb1nJR8sXnmYpex+XAA==;7:rT+PpwbAblolM1Yu71BfEjjHZKInQThHE4EwsZkvMUMSGI1jMUWa4Wrs2bKGXb8gBrKR4Iq810ziKHWv85qDiyriKApV3dr30azu52zMjZlUT8H1LOcq922+OG/6qzKSfX/7v8/m1ZlA0SNoO+WpamD55jCNV9RHW/W5jPYF2TZyRXdiV3+hKBc8LnRMMwIvK6cNK96SbVTqYGRQpCp7KWkQLudbNpLCop/FvbT3mQsAIiwpGNwVSX7Z+B99H/NJ x-ms-exchange-antispam-srfa-diagnostics: SSOS;SSOR; x-ms-office365-filtering-correlation-id: cfe8b81a-e52a-4783-d3e0-08d562e0fb14 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603307)(7193020);SRVR:DM5PR2101MB1080; x-ms-traffictypediagnostic: DM5PR2101MB1080: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(67672495146484); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(8121501046)(5005006)(3002001)(10201501046)(3231046)(2400081)(944501161)(93006095)(93001095)(6055026)(61426038)(61427038)(6041288)(20161123562045)(20161123558120)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1080;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1080; x-forefront-prvs: 056297E276 x-forefront-antispam-report: SFV:SPM;SFS:(10019020)(376002)(396003)(346002)(39860400002)(39380400002)(366004)(189003)(199004)(72206003)(110136005)(316002)(5250100002)(6346003)(2900100001)(54906003)(1076002)(6116002)(3846002)(22452003)(36756003)(53936002)(99286004)(6512007)(68736007)(2501003)(3660700001)(14454004)(3280700002)(86362001)(102836004)(7736002)(5660300001)(305945005)(107886003)(6486002)(6506007)(2906002)(81156014)(26005)(25786009)(4326008)(81166006)(105586002)(8936002)(59450400001)(106356001)(478600001)(10290500003)(6436002)(8676002)(2950100002)(86612001)(97736004)(76176011)(10090500001)(66066001)(22906009)(217873001)(505234006);DIR:OUT;SFP:1501;SCL:5;SRVR:DM5PR2101MB1080;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: ToKvogLNqiGqR8Dwi9RA/zavlidx45jop9WtEGMeHEJMKeipqMJrcJ6+J+NMQEumM0W5zIbmNS1I0pdXo5dsNg== spamdiagnosticoutput: 1:22 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: cfe8b81a-e52a-4783-d3e0-08d562e0fb14 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2018 04:14:36.5714 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1080 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Disseldorp [ Upstream commit 1addb798e93893d33c8dfab743cd44f09fd7719a ] null_alloc_dev() allocates memory for dev->badblocks, but cleanup currently only occurs in the configfs release codepath, missing a number of other places. This bug was found running the blktests block/010 test, alongside kmemleak: rapido1:/blktests# ./check block/010 ... rapido1:/blktests# echo scan > /sys/kernel/debug/kmemleak [ 306.966708] kmemleak: 32 new suspected memory leaks (see /sys/kernel/deb= ug/kmemleak) rapido1:/blktests# cat /sys/kernel/debug/kmemleak unreferenced object 0xffff88001f86d000 (size 4096): comm "modprobe", pid 231, jiffies 4294892415 (age 318.252s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ backtrace: [] kmemleak_alloc+0x49/0xa0 [] kmem_cache_alloc+0x9f/0xe0 [] badblocks_init+0x2f/0x60 [] 0xffffffffa0019fae [] nullb_device_badblocks_store+0x63/0x130 [null_blk] [] do_one_initcall+0x3d/0x170 [] do_init_module+0x56/0x1e9 [] load_module+0x1c47/0x26a0 [] SyS_finit_module+0xa9/0xd0 [] entry_SYSCALL_64_fastpath+0x13/0x94 Fixes: 2f54a613c942 ("nullb: badbblocks support") Reviewed-by: Shaohua Li Signed-off-by: David Disseldorp Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/null_blk.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c index 4d55af5c6e5b..69dfa1d3f453 100644 --- a/drivers/block/null_blk.c +++ b/drivers/block/null_blk.c @@ -467,7 +467,6 @@ static void nullb_device_release(struct config_item *it= em) { struct nullb_device *dev =3D to_nullb_device(item); =20 - badblocks_exit(&dev->badblocks); null_free_device_storage(dev, false); null_free_dev(dev); } @@ -578,6 +577,10 @@ static struct nullb_device *null_alloc_dev(void) =20 static void null_free_dev(struct nullb_device *dev) { + if (!dev) + return; + + badblocks_exit(&dev->badblocks); kfree(dev); } =20 --=20 2.11.0