Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp217070pxx; Wed, 28 Oct 2020 03:07:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPDnINoYPVK2lwNZUErQYoeMaRRUjcgUfPM2Msw76QSHbp3FKJAkAMt+DcR8/EmP8SKgYO X-Received: by 2002:a05:6402:1691:: with SMTP id a17mr6697856edv.264.1603879644265; Wed, 28 Oct 2020 03:07:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603879644; cv=none; d=google.com; s=arc-20160816; b=r+7hctJ9QljTiWLd9x8Ru3tstRir6yx09ubEHarN62gzsirom39ZlSiloASD7YPmhC qIuNLDVpI3DkjvCKptjy25YA3p2bHsp8SVfAJ0nT6fv3pZq2pQUzBqtq+VuV0qa48uIL 9k9UtHrBOGh90s4DhOkpLo0/IXI9Qf3JjED58gVJu/mFPkIbwQ7uWhpAO+/5TM06NeJc pM1W1izpCoRnnOjIv2Lw8bpnS4iT1QuzN2Ckp8L+t4aCp5RzSMmN6ONTuetY4r6lZF/o BYHAFVMjOGKnJy7CG3tOdF+KRRMdGPKhNx829hyI8heh71WmfaVSEe5eX8KUiYEordum xY/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7mT5o8u42VFo+8w+frFqWhCMOmlFp1Jiphpm5Np0p9k=; b=uHQquTq98DW91Gzk4Bfx3I+0DsItIt3KCmhXG5VvYtIXeudwLrOTgnYpoFKuPokdNZ BFuipQ76Hfm0MErlJ+wNzjYoPDLV3xUME2cxxaZHS4DhkY4WwHzdNgY2Kh5EO+SHcYhA MvQp23kX2yl+vI2o3CTIg3IG8L3eayVpD26B7O+1SJ4azS3FKaJ/tHXk3PuJOZeGnhPR ddTvq3yfpNpxcctCgg6AfGOpp3R5+VexK87+DgFh4j6Octh9kPcxw5OX22HlqS9v1LRr dKPnzMVOlaxTa183pZDTWjdwqEVrr8UuUs3SUJXsE0gc1OLZ8yhfo7vJU3owjRZ+WeH4 SHag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=d6Y3WEoK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z8si2802677eju.267.2020.10.28.03.07.02; Wed, 28 Oct 2020 03:07:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=d6Y3WEoK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760262AbgJ0OeT (ORCPT + 99 others); Tue, 27 Oct 2020 10:34:19 -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