From patchwork Thu Apr 12 01:58:52 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: 10337737 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 3D52D60153 for ; Thu, 12 Apr 2018 02:01:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 205DA28573 for ; Thu, 12 Apr 2018 02:01:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 135C32858D; Thu, 12 Apr 2018 02:01:19 +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.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 6A50328573 for ; Thu, 12 Apr 2018 02:01:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751960AbeDLCBR (ORCPT ); Wed, 11 Apr 2018 22:01:17 -0400 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:39050 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751777AbeDLCBP (ORCPT ); Wed, 11 Apr 2018 22:01:15 -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=1523498476; x=1555034476; h=from:to:cc:subject:date:message-id:mime-version; bh=Agd8ABl1dHdsozlBAg6Gc+3xsfQO6MH8Crhy9mNb0pU=; b=WG12/Sa4e4zsZUHCmIDbk2HM6mzZS9tLgrEDdiqkK+P6qBe9miPQnb8k ro1RFBQc4PrtJxGhv72XuVpkJpbVWCtObD3Py/ABPqzWcBA+5Dyji3hA4 Ome7tmKr1sAPgWmMFHhFEhNVbt9pmAqrP4qRkfnLNxoQ6LeC6QgQP3fpi 8URp58sFq1b1wtm71exBPm1urUEsJHtDrO+yzBK5GRkTMMtV9vpVIVTKo RMGDMC942RAbuQ/m2gIRqvLXsjKQ+rNA+o67R9h4bk64raPTgc/Sk2jY0 CCcr3NfeG287OyrTwpNzdLHBYwtPiPdntdlw8SEHibk92Dz6ieUqQ+IR5 Q==; X-IronPort-AV: E=Sophos;i="5.48,439,1517846400"; d="scan'208";a="76447940" Received: from mail-by2nam01lp0177.outbound.protection.outlook.com (HELO NAM01-BY2-obe.outbound.protection.outlook.com) ([216.32.181.177]) by ob1.hgst.iphmx.com with ESMTP; 12 Apr 2018 10:01:15 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector1-wdc-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=GpGt5Q3epZEdALssmEXA9AE42D1XL8LZ3mFMxZR3Z+w=; b=TmYCKbrQ5UKsm6Ap6Xtx4M5nrWOYwLX0rKlyh0G9GEJbs0FkNjDZrmgdoxdENYaJVDa4RdNbdqnDbqmJSfnDh3+QJfYWCA8n1L3UooSGI/CqvjMPP6yUn7CjrzHQSCsvPLqXGtuwObzCUo6h7a3QCtgxC1JOKbivkRMAYTm48QY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Bart.VanAssche@wdc.com; Received: from localhost.localdomain (50.225.201.71) by BN6PR04MB1186.namprd04.prod.outlook.com (2603:10b6:404:92::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.675.10; Thu, 12 Apr 2018 02:01:12 +0000 From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Alexandru Moise <00moses.alexander00@gmail.com>, Tejun Heo Subject: [PATCH] block: Ensure that a request queue is dissociated from the cgroup controller Date: Wed, 11 Apr 2018 19:58:52 -0600 Message-Id: <20180412015852.26014-1-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.16.2 MIME-Version: 1.0 X-Originating-IP: [50.225.201.71] X-ClientProxiedBy: SN4PR0501CA0110.namprd05.prod.outlook.com (2603:10b6:803:42::27) To BN6PR04MB1186.namprd04.prod.outlook.com (2603:10b6:404:92::10) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603328)(7153060)(7193020); SRVR:BN6PR04MB1186; X-Microsoft-Exchange-Diagnostics: 1; BN6PR04MB1186; 3:KYn453hR2+G7plwyoAzCkUIzdr+/JZyiK0foNzIYH2M9v22T36uc5hV0Ofw6Med1b1BHNRBJZERxvkd9ofL4iZJg5v2t3PdCKrgRVNKJgG/+AWKKCSQRv+zZAXr8kz/6heZqB1pPYoEpCgR5ot3g9GtazAc2lUqVowBo9T+35Lij2PuB4CCXM0+DJDP/5L1VkPG5f0TzoBHTUiVr6ciKlgfX+JK57Hn2BZCj1+WWPOSCkbslvbtVoYnuUmBBbFms; 25:KoBUlC1OfVzJYxh3xI4fg2UHdiOEjFRUn2tRXm+GuwXWgHyI0KqkG9KPOIOt3zRk/BM22ERs5VsXYioEHw92XbNvuAgkOLV86VcRzIa9pwjcycg0XvwgYauUG51aDoe/nthuaRgn39y1CaSNM3VIgb8cSD3YmDuX6LVKC+FtgoO2zmjLl6Y0hMNEzV+UXM5CarvCN8JczXSC4zyPK8UEwxfS6IP6Usoaae57yPHDt/7zsIFxBB/hmv5OVpFdCL6rdypIj/MwD2MfD2Hgx0JJTT4J211GDSCND1cSo/Pv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LdRSjNod6Tka8GW8Z4qAxXIZQYUxE0WH2nZQ3uT+2Xh5CIz+yoWCCcPtVva49B2Xdrkd1p6jRNaHHtmNA04Gy42ChHZbnTFd6tuG2w1IsIAJM2mFiJS51Abbu39GF1/F11zlNSV0QYP9Joo5g X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(85827821059158); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(3002001)(3231221)(944501327)(52105095)(6055026)(6041310)(20161123558120)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011); SRVR:BN6PR04MB1186; BCL:0; PCL:0; RULEID:; SRVR:BN6PR04MB1186; X-Forefront-PRVS: 06400060E1 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6069001)(346002)(396003)(39860400002)(376002)(39380400002)(366004)(189003)(199004)(1076002)(6116002)(7736002)(39060400002)(105586002)(16586007)(54906003)(305945005)(316002)(53936002)(6512007)(68736007)(478600001)(3846002)(5660300001)(6486002)(6916009)(6666003)(59450400001)(2906002)(8936002)(36756003)(72206003)(81156014)(81166006)(51416003)(4326008)(8676002)(106356001)(50226002)(1857600001)(97736004)(386003)(52116002)(6506007)(2616005)(50466002)(956004)(26005)(86362001)(16526019)(186003)(476003)(25786009)(47776003)(66066001)(486006)(48376002); DIR:OUT; SFP:1102; SCL:1; SRVR:BN6PR04MB1186; H:localhost.localdomain; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN6PR04MB1186; 23:RrWSANEfAqlQEs/Pn1+UcO6azIE6gh7x5xeF6HpAX?= =?us-ascii?Q?kbmpeg/9ZKAKDWZSdGo4X1Z1YMP9bBqZR0rKuAc4m/QMC9aILPljGvvQCzh2?= =?us-ascii?Q?yGgFVJuTh+BQj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?us-ascii?Q?StssZ8cXtDNtMLYFjOJZzmkQi8545gTlyYgFeAH96NpOPGW9qgN0uUIuh6Vz?= =?us-ascii?Q?MsipYdR3K06gaVsxqviFhC8Y7X18i5odzpyV6hFK8vBdIxHEucCfeb+GpYHe?= =?us-ascii?Q?WXJ4QkOZhLckJDo21e+E5w+mQaVh27pxqou6vIZ1rApW8g4pwU/Gsd1NYcCq?= =?us-ascii?Q?zlv/+bkMdGd4XkBp1osjuZuccf/cufnzUPHFnQioHmL50oNxUvjmtRERaKxK?= =?us-ascii?Q?xGyPLTUROe4gGll1YHXyMgbaHl/h9mzYKi/iVIq?= X-Microsoft-Antispam-Message-Info: uVb0xnVwv1txL3WbclrihANYmOMa7x7WlzWy70DuAW81uYAcqnEPHWAX9vc+lITbF8nAgIunzH6cVU9BtZNEO3wutJcpAjvCCO4iXoqlRSEj/2ZjFMhVG4oQlWRfCOc3N3iIa4ZlyxpLgW6VUl91J7IBye1A0DWGj2cFvpXZQo12C6Br13PXDvziMULgSu2H X-Microsoft-Exchange-Diagnostics: 1; BN6PR04MB1186; 6:KmbXl/AZyNqrCQMFgQdSDMviggTspclpSVl21tFrITessVJksXtthwyHZKKK4K57uoWM+7R0WBcyF5dwgREhdv3Pqx3ULrKkod8CrtpF4S4+CEJJYejA4seoLKYxcgjvb/DyThfjTCkwkYGVgOLsg9o0o6YRQVK4FNycdTDJkMN8UvDWwrz1QApCZsS8b2HHV/ARrRP8UAzng82mBxp/Hh6bEVTxkuW5e4Swg04yRg1+J0WmWUZfEcSJEUnKAbWaHvJvkARbAYn9k4KRujo0chNj8GgwjXoHYsHw4/4qRHu47T4MscK9G8952/CDPvJEsySbM+2/o7NY/Om1YJlzk12fGnO+iiyKOh3XrjMUhp/I7rlNme6ysvtvhuJIaU9Q2kGq4dFms/ki0GctwfGHvFQAJEE4u7izxNcv3LpKrNZ2hbgicHa0Xr5CTnrD0kslXHlLcjInvL/qwpp0Z/ZaHQ==; 5:Twj4K4cWqdcu5wt7DbzPE41VDbA67Yv97CPBdraVyg6pPDrMslPJvBga5PhZmm2vnLiS8y3BWHBCuqL89htAksM5D6QZWwhLdyNZUL2UsPGf+3wOppyFi1w0E1JaPwMIzVpVqq0EClYSWd2j0kjehB0CNxLQfEFYR+ZehL7YLhE=; 24:Srtgt7zlwrl13lSLDaN2Ii3gtoVZs9pPdqw6US4txKtR7UUeNt7Th0lhF8ELgPolWkhZBKOSvTYO2kCR8uIngHpaSBqB92Ccl5GSaVhkFcE= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR04MB1186; 7:mxoiCnPjru5YqiO9Bc6ZzCPSqa8Bsy0buKyLVO8V/6b9bJE+d570aNqnkIRlrOzqju+luG7UvYV/JwgfMpTKk5brH5+90LGk+l3CNM1YnmaDOp49NjuHctsJHZsBj9LZSsnVWwx5KkOJ6uj3OWZLNGx2urVPeplEl9vcxFbDqtituKfdvEPPPsDG34eLHKeQ9uGmSCYgP4wEsAmr2cRPu4+2lRJ3cKsXRcOC4EHDGQFlBZ7A7Dtpm3dZLiWAJMk+; 20:zYB0N1s+mgZiA5F3FpK3Az22vjxw0HCtcD0BYOSFnxXNew81Pg7ajxTlSH2iJ4MKX1DZ9Fanxc6SnD0gPQeygehqATHvi9XuJsD+yGdsG2Bgqq5kPleIfy0hq3l8BFXPF0vOBkKZqGouf0qs39AEOOTCBe8kTuls3sNPeCUdG/U= X-MS-Office365-Filtering-Correlation-Id: 3829a3cc-9b41-441f-82cd-08d5a01944ab X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2018 02:01:12.3885 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3829a3cc-9b41-441f-82cd-08d5a01944ab X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR04MB1186 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 Cc: Alexandru Moise <00moses.alexander00@gmail.com> Cc: Tejun Heo Tested-by: Alexandru Moise <00moses.alexander00@gmail.com> Tested-by: Alexandru Moise <00moses.alexander00@gmail.com> --- block/blk-sysfs.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index f8457d6f0190..2e134da78f82 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -788,11 +788,37 @@ static void blk_free_queue_rcu(struct rcu_head *rcu_head) static void __blk_release_queue(struct work_struct *work) { struct request_queue *q = container_of(work, typeof(*q), release_work); + struct blkcg_gq *gq; if (test_bit(QUEUE_FLAG_POLL_STATS, &q->queue_flags)) 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); + bdi_put(q->backing_dev_info); + blkcg_exit_queue(q); + + if (q->elevator) { + ioc_clear_queue(q); + elevator_exit(q, q->elevator); + } + } + + rcu_read_lock(); + gq = blkg_lookup(&blkcg_root, q); + rcu_read_unlock(); + + WARN(gq, + "request queue %p is being released but it has not yet been removed from the blkcg controller\n", + q); + blk_free_queue_stats(q->stats); blk_exit_rl(q, &q->root_rl);