From patchwork Thu Jul 9 12:23:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 235144 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp1363947ilg; Thu, 9 Jul 2020 05:27:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySPiCrzzeBuwSCWqz+QV8M2WomewJA2A3vSkw23VkE0NXMPtacJBhMlYfEjdOUT4wDFvo2 X-Received: by 2002:a50:f413:: with SMTP id r19mr75076701edm.17.1594297631212; Thu, 09 Jul 2020 05:27:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594297631; cv=none; d=google.com; s=arc-20160816; b=hptYYX850IiDIDdphAO3bf1yqRfdd58mEyYvsumj7ww2D91GQaN3Dn3yXMRBItn3xf kdGObsWCqHd7p/XdsVSl0Zv4+Q/+Y3MC+XQ3+U93xRZXMiFHjZfwRbJYwp9OdumZnpoX +lxKihp+3Oufk94OTUnFDlJ0o84xLFtyBeZudpk6i7J2AchYhwiQBUoibpTlMGXUUuV9 6BrgjmKO0WH6UByZRG6sXKcbQYEc6Vhdn0qhH1CgnofPAKf9TNHDD8FzJTN9Z9wOKYjx qc5RXjcFeqRBlVKVnG0Angp3gaODuFEcSieIl8Dy6bZ5lHjZ4cZ+MqSRelXEinKhTlFL hACA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=Y9wmpDNlLFKy53k2Bf8zuxzAVR4JVCrUbDhwJxY6+xw=; b=0/VC7Z1XqUG4aONesSpA6DhV9OwqrouPfH6ShkAeuBN9TYvWd+rdOqU09xSA39z8ir ftsePsegN3LdJql6sPCmwxjK0JBMopie2p3sxerNMRxcuwxPJsSOiUSCb86yQGG+97LC u/PP+EpLg5NE1AnIITMQH44sJOYHQsBNqu3Z0EUD6BcZ99ekt+1q7z1Z4DczZbum/Q/P R6A0UUqizBu4DOJC2i/Uffwbkr1hQ9xHfGElAKmwpP0ngnAtdXoTTMoF/qLAjNen5xVi riRJ68zUWWVvszbVrcUxcWURDm6KdzTWGnFYD3PUhdDdBJGDFyDjIMndV30uZQWS7x8i ZY+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-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 h13si1796491eji.459.2020.07.09.05.27.11 for ; Thu, 09 Jul 2020 05:27:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-scsi-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-scsi-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-scsi-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727038AbgGIM1K (ORCPT ); Thu, 9 Jul 2020 08:27:10 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:7281 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726605AbgGIM1K (ORCPT ); Thu, 9 Jul 2020 08:27:10 -0400 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 5E7787BD46B0B1BA9D1E; Thu, 9 Jul 2020 20:27:06 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.487.0; Thu, 9 Jul 2020 20:26:59 +0800 From: John Garry To: , CC: , , , , , John Garry Subject: [PATCH v2 1/2] scsi: scsi_debug: Add check for sdebug_max_queue during module init Date: Thu, 9 Jul 2020 20:23:19 +0800 Message-ID: <1594297400-24756-2-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1594297400-24756-1-git-send-email-john.garry@huawei.com> References: <1594297400-24756-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org 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. Fixes: c483739430f10 ("scsi_debug: add multiple queue support") Acked-by: Douglas Gilbert Signed-off-by: John Garry --- drivers/scsi/scsi_debug.c | 6 ++++++ 1 file changed, 6 insertions(+) -- 2.26.2 Reviewed-by: Ming Lei diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index 4692f5b6ad13..68534a23866e 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -6613,6 +6613,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 <= 0)) { + 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)