Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp611656pxu; Thu, 26 Nov 2020 07:06:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJxxgwzAbKcmrxbVNdPV9iJUilSLDpUyZA9nyfl71htL4cxUs3qAcYRiOXUNezDscEzgdb4R X-Received: by 2002:a50:8f06:: with SMTP id 6mr2937454edy.39.1606403218795; Thu, 26 Nov 2020 07:06:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606403218; cv=none; d=google.com; s=arc-20160816; b=YugJm1QJlbL37hQihPS0QMw7QbSHVDhgCdMVTwAs3+5YZVd5COVk5dVT/ri2FTJmT0 UevWq9Mi/vVERBTwb7vynj7wgB+e0RZ918k3v+sN79PzPb1uTShDoqFHx9EXnHgMKLQi dVyvIutotbXHEabnZwLeFA2Nv6u68nsTqrwrOJelq0tql8PW88jlH5FIEp2nJWl2sEbD EdPxbUtKBSzLsDPh8KEco6PS8h2J3amTUt4jAjUHspDunRQsHOXJU1GyHIoB/8i8vKBq E/dd8LzNM56RrjWbwkXO0vtW0KK8tvx/DP5h1P5NgQbxe5u/klsrpUvaWle3hIdcnGyw TMgA== 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=0o7aPpnheDTbCV+kt1XI/RmNIY9yTLbKkoYhGKOFo7o=; b=MqMDbpYcbR7pdWOpCD/CJfBaXUMRtgZganRUG0GEY4XRkqx4PGaqaw3LVVJhKGX6Bd 5LrmaZ6VbGaqhMh9ikfYPKU5xhFHGYCyHoeaarZGfwrA9GxH6EYraXX/493no25BjGPX Rf2t/5CZEFxlpz9K2dFTGaQrOc2Sbp0nuW2vDeAi8cO7G5z+e36FrlZGjUb6MaNWnIVC RUjz58N+II4gPQ0ZkI60rsDoEXbdtfKkOGec76vMt1A3R//oODMoKJLVsWOCoU5nMtYV tLmGqTJ8W3tfnawOfyc2k0lJcWGVo/OirlSxqblkZ/RMNEZKqD7QxoslUMs1ZzKMa0/t an7Q== 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 b10si3243929edu.535.2020.11.26.07.06.35; Thu, 26 Nov 2020 07:06:58 -0800 (PST) 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 S2391301AbgKZPCX (ORCPT + 99 others); Thu, 26 Nov 2020 10:02:23 -0500 Received: from alexa-out.qualcomm.com ([129.46.98.28]:56776 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390811AbgKZPCW (ORCPT ); Thu, 26 Nov 2020 10:02:22 -0500 Received: from ironmsg09-lv.qualcomm.com ([10.47.202.153]) by alexa-out.qualcomm.com with ESMTP; 26 Nov 2020 07:02:22 -0800 X-QCInternal: smtphost Received: from ironmsg01-blr.qualcomm.com ([10.86.208.130]) by ironmsg09-lv.qualcomm.com with ESMTP/TLS/AES256-SHA; 26 Nov 2020 07:02:20 -0800 X-QCInternal: smtphost Received: from hydcbspbld03.qualcomm.com ([10.242.221.48]) by ironmsg01-blr.qualcomm.com with ESMTP; 26 Nov 2020 20:32:09 +0530 Received: by hydcbspbld03.qualcomm.com (Postfix, from userid 2304101) id EE1C021110; Thu, 26 Nov 2020 20:32:07 +0530 (IST) From: Pradeep P V K To: axboe@kernel.dk, linux-block@vger.kernel.org Cc: stummala@codeaurora.org, linux-kernel@vger.kernel.org, Pradeep P V K Subject: [PATCH V1] block: Fix use-after-free while iterating over requests Date: Thu, 26 Nov 2020 20:32:05 +0530 Message-Id: <1606402925-24420-1-git-send-email-ppvk@codeaurora.org> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Observes below crash while accessing (use-after-free) request queue member of struct request. 191.784789: <2> Unable to handle kernel paging request at virtual address ffffff81429a4440 ... 191.786174: <2> CPU: 3 PID: 213 Comm: kworker/3:1H Tainted: G S O 5.4.61-qgki-debug-ge45de39 #1 ... 191.786226: <2> Workqueue: kblockd blk_mq_timeout_work 191.786242: <2> pstate: 20c00005 (nzCv daif +PAN +UAO) 191.786261: <2> pc : bt_for_each+0x114/0x1a4 191.786274: <2> lr : bt_for_each+0xe0/0x1a4 ... 191.786494: <2> Call trace: 191.786507: <2> bt_for_each+0x114/0x1a4 191.786519: <2> blk_mq_queue_tag_busy_iter+0x60/0xd4 191.786532: <2> blk_mq_timeout_work+0x54/0xe8 191.786549: <2> process_one_work+0x2cc/0x568 191.786562: <2> worker_thread+0x28c/0x518 191.786577: <2> kthread+0x160/0x170 191.786594: <2> ret_from_fork+0x10/0x18 191.786615: <2> Code: 0b080148 f9404929 f8685921 b4fffe01 (f9400028) 191.786630: <2> ---[ end trace 0f1f51d79ab3f955 ]--- 191.786643: <2> Kernel panic - not syncing: Fatal exception Fix this by updating the freed request with NULL. This could avoid accessing the already free request from other contexts while iterating over the requests. Signed-off-by: Pradeep P V K --- block/blk-mq.c | 1 + block/blk-mq.h | 1 + 2 files changed, 2 insertions(+) diff --git a/block/blk-mq.c b/block/blk-mq.c index 55bcee5..9996cb1 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -492,6 +492,7 @@ static void __blk_mq_free_request(struct request *rq) blk_crypto_free_request(rq); blk_pm_mark_last_busy(rq); + hctx->tags->rqs[rq->tag] = NULL; rq->mq_hctx = NULL; if (rq->tag != BLK_MQ_NO_TAG) blk_mq_put_tag(hctx->tags, ctx, rq->tag); diff --git a/block/blk-mq.h b/block/blk-mq.h index a52703c..8747bf1 100644 --- a/block/blk-mq.h +++ b/block/blk-mq.h @@ -224,6 +224,7 @@ static inline int __blk_mq_active_requests(struct blk_mq_hw_ctx *hctx) static inline void __blk_mq_put_driver_tag(struct blk_mq_hw_ctx *hctx, struct request *rq) { + hctx->tags->rqs[rq->tag] = NULL; blk_mq_put_tag(hctx->tags, rq->mq_ctx, rq->tag); rq->tag = BLK_MQ_NO_TAG; -- 2.7.4