Received: by 10.223.176.5 with SMTP id f5csp1012769wra; Fri, 2 Feb 2018 09:41:44 -0800 (PST) X-Google-Smtp-Source: AH8x226jvOvXJhFbnSAJdv0FAI8y7Pqn7TmalrbsvISB02BcS0po7x3YUM6XMyCNC7R0elMNNuIB X-Received: by 2002:a17:902:67c5:: with SMTP id g5-v6mr32019535pln.106.1517593304728; Fri, 02 Feb 2018 09:41:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517593304; cv=none; d=google.com; s=arc-20160816; b=07Zw4ovDwiPY6OxzLmY8x3yGmRHkmYvsZo1LAWu8mdJhJk9xW7tm0moifsE9f/CPxA wBCPJPKKjUR519RD4EkrKiq4Kt6uJMg+65WzESkydYD5Riv7xg+89roFKA/Zd2V3ZZBB Sa6SBiblNRVY56B3Xmpd3pgXDVXhZO/dPgvVVwF0KqarWwWJOp1Xym52lful5ULmzYqa /IueoOmkDjzH3af4NePAoLo//0XR23QaWZ/wQXeMfbZB2RhXkx2V+Bs7PuVvY532en9L ojtUL+NvrX7ZKAZq1vi5dRzGOCZlb8JbbBo0eyPmiYGyIqgVeg2LLI83isJkyWWaQnx6 ftpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Hqu6nuAf40fotSo4G23R4hM5uPONipEFmlJudIwSpqY=; b=F6zdwg2AU0QH9W0/ot1zfvBzSpYM57c18M8kQGxeHZVz4jqWm+c3HSbaq0wDvElc7/ S8XX2hiH5AI8veybgStZ4+APmBWbsqESgFuKdAa4XPH0ztc4lDGPhyO186cGJShlduma RQ5NtSYnO1goKUlpvcz1z+KieKsGJjgMQ3cQSM1pcBgNdAp+Owxd+rfJhw86r+f6qVIj 35FJ8N9btskLXDneLhBp5+pdSe4wQwpBuF0hn4aZYDbJpWvbwRVvbSsIaL4iWglOcRel ODMlEcZ3N/WYZYM9xHsrahr/oH+TBDkSVBxzg9hqTkpy48VelYkZPTDWnrCVJO9Nx3VH PIMw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b6-v6si605713plx.805.2018.02.02.09.41.29; Fri, 02 Feb 2018 09:41:44 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753788AbeBBRPm (ORCPT + 99 others); Fri, 2 Feb 2018 12:15:42 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:37976 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752669AbeBBRJb (ORCPT ); Fri, 2 Feb 2018 12:09:31 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 9D4E8D31; Fri, 2 Feb 2018 17:09:30 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shaohua Li , David Disseldorp , Jens Axboe , Sasha Levin Subject: [PATCH 4.14 056/156] null_blk: fix dev->badblocks leak Date: Fri, 2 Feb 2018 17:57:17 +0100 Message-Id: <20180202140842.829885141@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140840.242829545@linuxfoundation.org> References: <20180202140840.242829545@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ 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/debug/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 Signed-off-by: Greg Kroah-Hartman --- drivers/block/null_blk.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/drivers/block/null_blk.c +++ b/drivers/block/null_blk.c @@ -467,7 +467,6 @@ static void nullb_device_release(struct { struct nullb_device *dev = to_nullb_device(item); - badblocks_exit(&dev->badblocks); null_free_device_storage(dev, false); null_free_dev(dev); } @@ -578,6 +577,10 @@ static struct nullb_device *null_alloc_d static void null_free_dev(struct nullb_device *dev) { + if (!dev) + return; + + badblocks_exit(&dev->badblocks); kfree(dev); }