From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D636C388F9 for ; Tue, 27 Oct 2020 14:34:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 30BA42222C for ; Tue, 27 Oct 2020 14:34:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809264; bh=YLXIVoUUsD7oLtHfedDeIn2EIULEmfZqsrfd4FKJ/4Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=kMFsftQOjh4yh1spihLPK+mWvbuPD7WD4uF0x8S+X6fiQsPyHEmzuLfChjB0isbF3 teLivna94F5m9gQvS1u/ORcOC+97uMHMkt0413E/N2e7BA+/urTHBo4aNywnfH3/ur rZytIdp1MKbIjJHSo79dKOel7MMuRDkV6jkBfp6g= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760270AbgJ0OeW (ORCPT ); Tue, 27 Oct 2020 10:34:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:59828 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2902367AbgJ0Ocy (ORCPT ); Tue, 27 Oct 2020 10:32:54 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BAA8420725; Tue, 27 Oct 2020 14:32:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809174; bh=YLXIVoUUsD7oLtHfedDeIn2EIULEmfZqsrfd4FKJ/4Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d6Y3WEoKMtGTL/+YAu6NwTKAMNwsijkJmEsSk0BazAJapAsS1QUCnpGEfi0TlYt25 rixayYK46rSS8/NKZs4noaQri4PDxUXcvZsV29i2a+gn9bAevIW5idXeYc/U3A5vqj 6HjCLhpvg++q6ATpN3WRQF8UfEjb1zSisw9DxRmU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yang Yang , Ming Lei , Jens Axboe , Sasha Levin Subject: [PATCH 5.4 102/408] blk-mq: move cancel of hctx->run_work to the front of blk_exit_queue Date: Tue, 27 Oct 2020 14:50:40 +0100 Message-Id: <20201027135459.829784146@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yang Yang [ Upstream commit 47ce030b7ac5a5259a9a5919f230b52497afc31a ] blk_exit_queue will free elevator_data, while blk_mq_run_work_fn will access it. Move cancel of hctx->run_work to the front of blk_exit_queue to avoid use-after-free. Fixes: 1b97871b501f ("blk-mq: move cancel of hctx->run_work into blk_mq_hw_sysfs_release") Signed-off-by: Yang Yang Reviewed-by: Ming Lei Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/blk-mq-sysfs.c | 2 -- block/blk-sysfs.c | 9 ++++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/block/blk-mq-sysfs.c b/block/blk-mq-sysfs.c index a09ab0c3d074d..5dafd7a8ec913 100644 --- a/block/blk-mq-sysfs.c +++ b/block/blk-mq-sysfs.c @@ -36,8 +36,6 @@ static void blk_mq_hw_sysfs_release(struct kobject *kobj) struct blk_mq_hw_ctx *hctx = container_of(kobj, struct blk_mq_hw_ctx, kobj); - cancel_delayed_work_sync(&hctx->run_work); - if (hctx->flags & BLK_MQ_F_BLOCKING) cleanup_srcu_struct(hctx->srcu); blk_free_flush_queue(hctx->fq); diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c index 46f5198be0173..bf33570da5ac7 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -891,9 +891,16 @@ static void __blk_release_queue(struct work_struct *work) blk_free_queue_stats(q->stats); - if (queue_is_mq(q)) + if (queue_is_mq(q)) { + struct blk_mq_hw_ctx *hctx; + int i; + cancel_delayed_work_sync(&q->requeue_work); + queue_for_each_hw_ctx(q, hctx, i) + cancel_delayed_work_sync(&hctx->run_work); + } + blk_exit_queue(q); blk_queue_free_zone_bitmaps(q); -- 2.25.1