Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1853207pxu; Fri, 9 Oct 2020 01:07:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiYbBFTJJzIzISMb/lwZpQnLiuyb6wNtGN7Nz372ZnBLITQYaZxgNEjnZoEa44u3uWvDKZ X-Received: by 2002:a50:af21:: with SMTP id g30mr9662035edd.46.1602230852606; Fri, 09 Oct 2020 01:07:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602230852; cv=none; d=google.com; s=arc-20160816; b=O2qk752byQSqr3VfYEmpcgg+hkoey+RVAoVcB/V/Aml/1h6xQLfWpe1R+/aEIfCVoP KvxWgDC2YzG1JaTSOxQ1rSycFM5DTyn/HADVxt0xZOJwzTBoYaLuyJxwl9QkZje1vNR4 890XG2B9eQD6IzZ12jPIvzBATio4AEuHQOgkVh6V01VJcOOzfv8GgmCm+tjNGDbJIPsK 0B3O6ItDAgqJJJaY3zSWU/UP1Res0jzGN/jem0nOBREZQRmOhnHUeAtoZosBRWOOPKeC a2Tkx/ctBCP3whUx52dkbzE6DTSHLh6rH5E6nXNAbCsUWQQ/Ms8D3N1RBGTdG8KikPmz RKxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=9JCeZeWn4Of0bJCX3gdlDKHpy7VtJTz9mSPlNo6sUmM=; b=YppTI1NYpXFwIMkWlNDabWD6XZuPT6j4ClhAH8MDTQ0TJbQ5bFqr/XEkSwl6wFN9Db KC2RwpnHVCybH9TzGhqcd6VSxcTtoIxOFnj8264vpJTQiWLHk0HHDQLX00k4UzfqQ/pG 5Ew0lLyggrj3rygFgTROI9XMBLDai5+TkxYusLT89RqWqFVJrnl1yi0nGOTJ6Q8EyuSf wPJLH4ueWmDbXvJfq4pP5Js21vSrHG4ag5HVBUuBzlboipl9Ih+hZy2giZLlLsLCdFM6 x53Q2kcd1BkXNaPKxUbYGO3UsCRgKlsYkrHNUehIiH3iF1VdwqOSUGUHAmEZ2Ni/gTTu mv3Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p18si5512060ejd.537.2020.10.09.01.07.08; Fri, 09 Oct 2020 01:07:32 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732455AbgJIIGH (ORCPT + 99 others); Fri, 9 Oct 2020 04:06:07 -0400 Received: from mail-m1271.qiye.163.com ([115.236.127.1]:51276 "EHLO mail-m1271.qiye.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732337AbgJIIGG (ORCPT ); Fri, 9 Oct 2020 04:06:06 -0400 X-Greylist: delayed 307 seconds by postgrey-1.27 at vger.kernel.org; Fri, 09 Oct 2020 04:06:05 EDT Received: from ubuntu.localdomain (unknown [157.0.31.125]) by mail-m1271.qiye.163.com (Hmail) with ESMTPA id BF05D581FBE; Fri, 9 Oct 2020 16:00:56 +0800 (CST) From: Yang Yang To: Jens Axboe , Bart Van Assche , Hannes Reinecke , Ming Lei , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: onlyfever@icloud.com, yang.yang@vivo.com Subject: [PATCH] blk-mq: move cancel of hctx->run_work to the front of blk_exit_queue Date: Fri, 9 Oct 2020 01:00:14 -0700 Message-Id: <20201009080015.3217-1-yang.yang@vivo.com> X-Mailer: git-send-email 2.17.1 X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgYFAkeWUFZS1VLWVdZKFlBSE83V1ktWUFJV1kPCR oVCBIfWUFZGE1NSktDHkIYTkhMVkpNS0lJSEtPTk1CTUhVEwETFhoSFyQUDg9ZV1kWGg8SFR0UWU FZT0tIVUpKS09ISVVLWQY+ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6PD46Khw6IT8vAkxMDQ4xNQER Hh8wCj5VSlVKTUtJSUhLT05MSE1NVTMWGhIXVQIaFRxVAhoVHDsNEg0UVRgUFkVZV1kSC1lBWUpO TFVLVUhKVUpJTllXWQgBWUFJT0hINwY+ X-HM-Tid: 0a750c60924998b6kuuubf05d581fbe Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 062229395a50..7b52e7657b2d 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 7dda709f3ccb..8c6bafc801dd 100644 --- a/block/blk-sysfs.c +++ b/block/blk-sysfs.c @@ -934,9 +934,16 @@ static void blk_release_queue(struct kobject *kobj) 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.17.1