Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp256501pxx; Wed, 28 Oct 2020 04:15:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAMixXyWIuGM/LihelTPKFXao1rixBBLAixJv51ddOXON+7e4Gqepey690uq8FP5FvluiO X-Received: by 2002:a17:906:804:: with SMTP id e4mr7191922ejd.379.1603883718711; Wed, 28 Oct 2020 04:15:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603883718; cv=none; d=google.com; s=arc-20160816; b=lf8k4+l5b+yeDLknQ4pEslZ9G9GOkHBmCpeE32h6kdHzJS0GZ+KAAP2hjxspk3xnmU Orr8siGDCgP+I42j6pk1aADSkg9TW3UD/PiWh3igl5ps75O63pad4fylw7Dh/Cyvl5V/ eZ27WuTHHhJglhm5UaqU0eZV+Llb8MIeieoSek6rTTP5P+yjHFpAwktVk+PELVFDCVWo p1GjjM3eAHjhknCoo4MMNaoy1IMi3hTjkObWXjm0t8ZzKqUMMH8dK/8iVvKMvR/8FX+D X3AJ7WeNd6OSZoWLZ0Jc61SmXQFeiwv8SD1F2DQtukMV0DwY6mU4/70Y4sENQBZBh7Pw wi7g== 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=O/SDuuY8vaLqc5COMmiP/TMowANBCve4kKDG3p+PeWA=; b=rv77CSEQT1utkNddcooSYYA7BE3yaSPYg8KnQ8nTT9MA/5EapXhdoJsZ6HZgJJICdK /GryriBj5TqTYrCk2s49QscmRf3zKcu0fn9N8cu8xLOSP8LtH0FZSS60v4DJJJhqGXa4 s3WLBUXU1zSDE8vR+AsZ15Sme+b3HUK0zJyXMeWNZ2RmrdWlneTKKHE2LpEDVoQluRrh DWb7xd825dVzsv5IB8m0tnJFyoLwv1LeiM+iqVxDAU+2bt57Tz+bz1OxaeF9mQHLXPVp JncTzGbiprTxF5TWuJJOtmhuejL4T4rcUpe866bHWaOC7A/Pe6eZnNT9NwvzriHJaXeC RiHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=krb48tCG; 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 d2si2953320edn.245.2020.10.28.04.14.56; Wed, 28 Oct 2020 04:15:18 -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=krb48tCG; 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 S1787636AbgJ0PAO (ORCPT + 99 others); Tue, 27 Oct 2020 11:00:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:55108 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1780327AbgJ0Oyh (ORCPT ); Tue, 27 Oct 2020 10:54:37 -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 56FE520679; Tue, 27 Oct 2020 14:54:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603810476; bh=JmjbyZPdrKRSgS4nauwMJd2YS0M2hqqZNL+Z1Lm6yzs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=krb48tCGfBcNDenIcy6vmNpPPLeKfD6eFyP5uMhyeSzPERs1lWmoFfH7nXL2p5JR7 NjuodqoYe86KBFk2LNVuw+FpJbbyatxRsLGIrM0lnf9pTCm9h6cbVs/VkoVTB7Jt2l JjKFTcEp/NKDPE0pEL/og/Q/lpwxZFznJ8TaA9cY= 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.8 153/633] blk-mq: move cancel of hctx->run_work to the front of blk_exit_queue Date: Tue, 27 Oct 2020 14:48:16 +0100 Message-Id: <20201027135529.868609739@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@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 062229395a507..7b52e7657b2d1 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 02643e149d5e1..95fea6c18baf7 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -896,9 +896,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