lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Thu,  7 Oct 2021 10:49:57 -0700
From:   Dexuan Cui <decui@...rosoft.com>
To:     kys@...rosoft.com, sthemmin@...rosoft.com, wei.liu@...nel.org,
        jejb@...ux.ibm.com, martin.petersen@...cle.com,
        haiyangz@...rosoft.com, ming.lei@...hat.com, bvanassche@....org,
        john.garry@...wei.com, linux-scsi@...r.kernel.org,
        linux-hyperv@...r.kernel.org, longli@...rosoft.com,
        mikelley@...rosoft.com
Cc:     linux-kernel@...r.kernel.org, Dexuan Cui <decui@...rosoft.com>,
        stable@...r.kernel.org
Subject: [PATCH v2] scsi: core: Fix shost->cmd_per_lun calculation in scsi_add_host_with_dma()

After commit ea2f0f77538c, a 416-CPU VM running on Hyper-V hangs during
boot because scsi_add_host_with_dma() sets shost->cmd_per_lun to a
negative number (the below numbers may differ in different kernel versions):
in drivers/scsi/storvsc_drv.c, 	storvsc_drv_init() sets
'max_outstanding_req_per_channel' to 352, and storvsc_probe() sets
'max_sub_channels' to (416 - 1) / 4 = 103 and sets scsi_driver.can_queue to
352 * (103 + 1) * (100 - 10) / 100 = 32947, which exceeds SHRT_MAX.

Use min_t(int, ...) to fix the issue.

Fixes: ea2f0f77538c ("scsi: core: Cap scsi_host cmd_per_lun at can_queue")
Cc: stable@...r.kernel.org
Signed-off-by: Dexuan Cui <decui@...rosoft.com>
---

v1 tried to fix the issue by changing the storvsc driver:
https://lwn.net/ml/linux-kernel/BYAPR21MB1270BBC14D5F1AE69FC31A16BFB09@BYAPR21MB1270.namprd21.prod.outlook.com/

v2 directly fixes the scsi core change instead as Michael Kelley and
John Garry suggested (refer to the above link).

 drivers/scsi/hosts.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 3f6f14f0cafb..24b72ee4246f 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -220,7 +220,8 @@ int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,
 		goto fail;
 	}
 
-	shost->cmd_per_lun = min_t(short, shost->cmd_per_lun,
+	/* Use min_t(int, ...) in case shost->can_queue exceeds SHRT_MAX */
+	shost->cmd_per_lun = min_t(int, shost->cmd_per_lun,
 				   shost->can_queue);
 
 	error = scsi_init_sense_cache(shost);
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ