From patchwork Thu Aug 20 09:21:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 248013 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:522:0:0:0:0 with SMTP id h2csp1208762ils; Thu, 20 Aug 2020 03:03:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwM8T3BVlfO/AtqLoQJWHDyrzMbcsQ6+y9eJIIpK1fU4gjnIFAXPhYYuTp46M8JYE6jxqct X-Received: by 2002:a05:6402:6da:: with SMTP id n26mr2158580edy.262.1597917827224; Thu, 20 Aug 2020 03:03:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597917827; cv=none; d=google.com; s=arc-20160816; b=G+pCO3Sn+MmqwwTAW6PIYLpP6VcQlShT5lVypVx8+sB/kCjFMwRlErG2YZLqKATf++ d+YgIjx1Jyd4xEIUd8yDAFWRY7lX+G+SmBFr9qM/tkYReHEc0RMKlKf7UcUVDSNc9knI K31u6Nr3ljVGBBJUNGeBkE/f/KF3YBCeqtNFteNMV4x1DqAHDvsowowvpBf/FRSKwckf 44sV5sMJ0fhFlDL0sbcSnp/QpRVzwDGCHjPidOrxxVwXXMtNmlx9dCQIUZKPN9HXlX4P JgZkcZjOADf5kcljBKKGECG9QWZX0PVcFkkb3mdF2apm3UUA0rHN0feUxZ3SPDLs14vN NFFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CrHabGbg3lQwFEjZyEOYV+x+tv8HLuVSOOC+yX4fZQQ=; b=hplHUNrfxZJ1RmAFzQlzTGy3vyECpL1W/DYpkSnxejmLBhVGdGlUjlknk0iLhYU0mf Tit+UxzEZRAlHVZbT8VJhRnLvh2BB3oewP+yNJrJ+8EHTYTKb0y1Duc2CAx1Iz9x5YqN 5YrYwRDhrerTubWb4CoiugnjId/tUhAleAHLEuiawhej/4DsRuX0dbNaTPv8pf2QB0km 12d2yblLaHZHBlD/+Ixj7DQ2lpg9GlCd6Gn1scwOH+nyo1yBpeOtknOJ08PcS0pt71WW iDOAtj8iYpAsKRECjQNoQXnslMmQoTM0PtU31eltpeFnM8+MbeOZAKoxv2ONAuIsPXml kG3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aS9P44Ai; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 e9si1016754edq.67.2020.08.20.03.03.47; Thu, 20 Aug 2020 03:03:47 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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=aS9P44Ai; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S1730603AbgHTKDl (ORCPT + 15 others); Thu, 20 Aug 2020 06:03:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:51760 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730144AbgHTKBm (ORCPT ); Thu, 20 Aug 2020 06:01:42 -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 831DF22B43; Thu, 20 Aug 2020 10:01:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597917702; bh=zYYe/3XhZ9XbEWFkH7IQDGmhde0mizLRbj0rj1QQQms=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aS9P44AiprGHBO/ZDWVZ6/8RuxJ9LUqzinRMJFRRIz1R/b32OaK3RpD1Wt5RFl6GD UUSVBvLM8qE6AmJxbfmDk8yMhlfXRNjTYX1CnpZrVl7kVjrvhMrRfYiIzGvPKMfgPw dLVLDjxOB2IMHGvsB9ZHL1QXSsdNEVQU0PK3nzYE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ming Lei , Douglas Gilbert , John Garry , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.9 126/212] scsi: scsi_debug: Add check for sdebug_max_queue during module init Date: Thu, 20 Aug 2020 11:21:39 +0200 Message-Id: <20200820091608.713749824@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091602.251285210@linuxfoundation.org> References: <20200820091602.251285210@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: John Garry [ Upstream commit c87bf24cfb60bce27b4d2c7e56ebfd86fb9d16bb ] sdebug_max_queue should not exceed SDEBUG_CANQUEUE, otherwise crashes like this can be triggered by passing an out-of-range value: Hardware name: Huawei D06 /D06, BIOS Hisilicon D06 UEFI RC0 - V1.16.01 03/15/2019 pstate: 20400009 (nzCv daif +PAN -UAO BTYPE=--) pc : schedule_resp+0x2a4/0xa70 [scsi_debug] lr : schedule_resp+0x52c/0xa70 [scsi_debug] sp : ffff800022ab36f0 x29: ffff800022ab36f0 x28: ffff0023a935a610 x27: ffff800008e0a648 x26: 0000000000000003 x25: ffff0023e84f3200 x24: 00000000003d0900 x23: 0000000000000000 x22: 0000000000000000 x21: ffff0023be60a320 x20: ffff0023be60b538 x19: ffff800008e13000 x18: 0000000000000000 x17: 0000000000000000 x16: 0000000000000000 x15: 0000000000000000 x14: 0000000000000000 x13: 0000000000000000 x12: 0000000000000000 x11: 0000000000000000 x10: 0000000000000000 x9 : 0000000000000001 x8 : 0000000000000000 x7 : 0000000000000000 x6 : 00000000000000c1 x5 : 0000020000200000 x4 : dead0000000000ff x3 : 0000000000000200 x2 : 0000000000000200 x1 : ffff800008e13d88 x0 : 0000000000000000 Call trace: schedule_resp+0x2a4/0xa70 [scsi_debug] scsi_debug_queuecommand+0x2c4/0x9e0 [scsi_debug] scsi_queue_rq+0x698/0x840 __blk_mq_try_issue_directly+0x108/0x228 blk_mq_request_issue_directly+0x58/0x98 blk_mq_try_issue_list_directly+0x5c/0xf0 blk_mq_sched_insert_requests+0x18c/0x200 blk_mq_flush_plug_list+0x11c/0x190 blk_flush_plug_list+0xdc/0x110 blk_finish_plug+0x38/0x210 blkdev_direct_IO+0x450/0x4d8 generic_file_read_iter+0x84/0x180 blkdev_read_iter+0x3c/0x50 aio_read+0xc0/0x170 io_submit_one+0x5c8/0xc98 __arm64_sys_io_submit+0x1b0/0x258 el0_svc_common.constprop.3+0x68/0x170 do_el0_svc+0x24/0x90 el0_sync_handler+0x13c/0x1a8 el0_sync+0x158/0x180 Code: 528847e0 72a001e0 6b00003f 540018cd (3941c340) In addition, it should not be less than 1. So add checks for these, and fail the module init for those cases. [mkp: changed if condition to match error message] Link: https://lore.kernel.org/r/1594297400-24756-2-git-send-email-john.garry@huawei.com Fixes: c483739430f1 ("scsi_debug: add multiple queue support") Reviewed-by: Ming Lei Acked-by: Douglas Gilbert Signed-off-by: John Garry Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/scsi_debug.c | 6 ++++++ 1 file changed, 6 insertions(+) -- 2.25.1 diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index d7118d3767c35..99bfb003be3fc 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -4986,6 +4986,12 @@ static int __init scsi_debug_init(void) pr_err("submit_queues must be 1 or more\n"); return -EINVAL; } + + if ((sdebug_max_queue > SDEBUG_CANQUEUE) || (sdebug_max_queue < 1)) { + pr_err("max_queue must be in range [1, %d]\n", SDEBUG_CANQUEUE); + return -EINVAL; + } + sdebug_q_arr = kcalloc(submit_queues, sizeof(struct sdebug_queue), GFP_KERNEL); if (sdebug_q_arr == NULL)