From patchwork Fri May 18 18:40:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10411867 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D1158601F9 for ; Fri, 18 May 2018 18:40:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BFB3628707 for ; Fri, 18 May 2018 18:40:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B469828A8D; Fri, 18 May 2018 18:40:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5848328707 for ; Fri, 18 May 2018 18:40:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751531AbeERSkF (ORCPT ); Fri, 18 May 2018 14:40:05 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:38072 "EHLO esa4.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751117AbeERSkE (ORCPT ); Fri, 18 May 2018 14:40:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1526668805; x=1558204805; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=3Cc+EWTLxIQz+L2HzX3QVuGY5CU3/AYCqZplPTRjjf4=; b=bZvlPv/kkihphLeRkwq6hsGdzZbgfG5DkxuVozE/9xYca/4aEsGpqs3a oLKXQuo/NxImj0+p5p4kP0QskVYH7kIV6Z1zlMlnBRtMVVIH1eXRfezNK 91CJcdgRW/5Xg95JZE13LNqHKvFDCX9amDE+Mb3SM4XYO4JMjvAfUENyp dV1Ca8CsVCPI4AeOxZ3bZQSxC9rnyUKIluxUFGMOWzeoaDLPS+nD2cVjb IC0XhPyqtDm98UuAYKWeQ6uq8fp7+/pL63Sw50eTDsHlQhJ7NSEHdhKpE Y8X15k5z0dUBHje2jl12gnW2shA+j7bS7bnVzS5JvrDDDNejd5obPImev g==; X-IronPort-AV: E=Sophos;i="5.49,415,1520870400"; d="scan'208";a="78309428" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 19 May 2018 02:40:04 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP; 18 May 2018 11:30:37 -0700 Received: from thinkpad-bart.sdcorp.global.sandisk.com ([10.111.70.1]) by uls-op-cesaip01.wdc.com with ESMTP; 18 May 2018 11:40:04 -0700 From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Tejun Heo , Alexandru Moise <00moses.alexander00@gmail.com>, Joseph Qi Subject: [PATCH v3 2/2] block: Ensure that a request queue is dissociated from the cgroup controller Date: Fri, 18 May 2018 11:40:03 -0700 Message-Id: <20180518184003.29738-3-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180518184003.29738-1-bart.vanassche@wdc.com> References: <20180518184003.29738-1-bart.vanassche@wdc.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Several block drivers call alloc_disk() followed by put_disk() if something fails before device_add_disk() is called without calling blk_cleanup_queue(). Make sure that also for this scenario a request queue is dissociated from the cgroup controller. This patch avoids that loading the parport_pc, paride and pf drivers triggers the following kernel crash: BUG: KASAN: null-ptr-deref in pi_init+0x42e/0x580 [paride] Read of size 4 at addr 0000000000000008 by task modprobe/744 Call Trace: dump_stack+0x9a/0xeb kasan_report+0x139/0x350 pi_init+0x42e/0x580 [paride] pf_init+0x2bb/0x1000 [pf] do_one_initcall+0x8e/0x405 do_init_module+0xd9/0x2f2 load_module+0x3ab4/0x4700 SYSC_finit_module+0x176/0x1a0 do_syscall_64+0xee/0x2b0 entry_SYSCALL_64_after_hwframe+0x42/0xb7 Reported-by: Alexandru Moise <00moses.alexander00@gmail.com> Fixes: a063057d7c73 ("block: Fix a race between request queue removal and the block cgroup controller") Signed-off-by: Bart Van Assche Tested-by: Alexandru Moise <00moses.alexander00@gmail.com> Cc: Tejun Heo Cc: Alexandru Moise <00moses.alexander00@gmail.com> Cc: Joseph Qi --- block/blk-sysfs.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 9cf41fee3790..a239c73fa20f 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -804,6 +804,31 @@ static void __blk_release_queue(struct work_struct *work) blk_stat_remove_callback(q, q->poll_cb); blk_stat_free_callback(q->poll_cb); + if (!blk_queue_dead(q)) { + /* + * Last reference was dropped without having called + * blk_cleanup_queue(). + */ + WARN_ONCE(blk_queue_init_done(q), + "request queue %p has been registered but blk_cleanup_queue() has not been called for that queue\n", + q); + blk_exit_queue(q); + } + +#ifdef CONFIG_BLK_CGROUP + { + struct blkcg_gq *blkg; + + rcu_read_lock(); + blkg = blkg_lookup(&blkcg_root, q); + rcu_read_unlock(); + + WARN(blkg, + "request queue %p is being released but it has not yet been removed from the blkcg controller\n", + q); + } +#endif + blk_free_queue_stats(q->stats); blk_exit_rl(q, &q->root_rl);