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=-9.8 required=3.0 tests=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=ham 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 E801BC2BB55 for ; Thu, 16 Apr 2020 15:45:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C6952214AF for ; Thu, 16 Apr 2020 15:45:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587051953; bh=DqaW5hpBioxSIRdYkknffzdq1MpTSMcyf9IlDzmc9h8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=1afkm4bbXMuNSm+lz8XzCMM6ty6yCV+TsNZ6hCJKgB8G5ah/HoF/EzMQ/cLdNHSsI DQEnbHKgu5l1U12KsssHPGS+r2DssjKfHrqc+G/NOkTyJOvDDnLlBBwDt1Wf9zFkxY uvb8C7+D0fMoyvZdnE4Tfs3ay9ahv7JpcEXVxpFo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2895405AbgDPPpw (ORCPT ); Thu, 16 Apr 2020 11:45:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:46628 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2897013AbgDPNey (ORCPT ); Thu, 16 Apr 2020 09:34:54 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 A1D8920732; Thu, 16 Apr 2020 13:34:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587044094; bh=DqaW5hpBioxSIRdYkknffzdq1MpTSMcyf9IlDzmc9h8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TTKyNs2oJU2QTyZmTcp5hTN7Xg2KFHOCbndif3uP0z39fh4iYZsZAj8UQd5Uyy3a9 kY1BKQs7XwypRMYMec1PNOlPBBzser99gIw5xs34Zh7pkdNdqh5dRX33j8Z/NHg9XG 0za3jcdQ6/IXtelULZhkAcgqJRI1lt+OvVKeuSjE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bart Van Assche , Ming Lei , Keith Busch , Johannes Thumshirn , Hannes Reinecke , Christoph Hellwig , Jens Axboe , Sasha Levin Subject: [PATCH 5.5 037/257] blk-mq: Fix a recently introduced regression in blk_mq_realloc_hw_ctxs() Date: Thu, 16 Apr 2020 15:21:28 +0200 Message-Id: <20200416131330.581319948@linuxfoundation.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200416131325.891903893@linuxfoundation.org> References: <20200416131325.891903893@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bart Van Assche [ Upstream commit d0930bb8f46b8fb4a7d429c0bf1c91b3ed00a7cf ] q->nr_hw_queues must only be updated once it is known that blk_mq_realloc_hw_ctxs() has succeeded. Otherwise it can happen that reallocation fails and that q->nr_hw_queues is larger than the number of allocated hardware queues. This patch fixes the following crash if increasing the number of hardware queues fails: BUG: KASAN: null-ptr-deref in blk_mq_map_swqueue+0x775/0x810 Write of size 8 at addr 0000000000000118 by task check/977 CPU: 3 PID: 977 Comm: check Not tainted 5.6.0-rc1-dbg+ #8 Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011 Call Trace: dump_stack+0xa5/0xe6 __kasan_report.cold+0x65/0x99 kasan_report+0x16/0x20 check_memory_region+0x140/0x1b0 memset+0x28/0x40 blk_mq_map_swqueue+0x775/0x810 blk_mq_update_nr_hw_queues+0x468/0x710 nullb_device_submit_queues_store+0xf7/0x1a0 [null_blk] configfs_write_file+0x1c4/0x250 [configfs] __vfs_write+0x4c/0x90 vfs_write+0x145/0x2c0 ksys_write+0xd7/0x180 __x64_sys_write+0x47/0x50 do_syscall_64+0x6f/0x2f0 entry_SYSCALL_64_after_hwframe+0x49/0xbe Fixes: ac0d6b926e74 ("block: Reduce the amount of memory required per request queue") Signed-off-by: Bart Van Assche Reviewed-by: Ming Lei Cc: Keith Busch Cc: Johannes Thumshirn Cc: Hannes Reinecke Cc: Christoph Hellwig Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/blk-mq.c | 1 - 1 file changed, 1 deletion(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 7d7800e958952..8391e8e2a5044 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2766,7 +2766,6 @@ static void blk_mq_realloc_hw_ctxs(struct blk_mq_tag_set *set, memcpy(new_hctxs, hctxs, q->nr_hw_queues * sizeof(*hctxs)); q->queue_hw_ctx = new_hctxs; - q->nr_hw_queues = set->nr_hw_queues; kfree(hctxs); hctxs = new_hctxs; } -- 2.20.1