Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4919911imc; Mon, 25 Feb 2019 13:39:11 -0800 (PST) X-Google-Smtp-Source: AHgI3IbvnyGEpp9RPNmTeVc25Vh1HSn9Aa3H/laQg/KG3FnvOIIQPKPG+70I+jjp3f+s50Esw3pj X-Received: by 2002:a62:388a:: with SMTP id f132mr22338415pfa.150.1551130751356; Mon, 25 Feb 2019 13:39:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551130751; cv=none; d=google.com; s=arc-20160816; b=tSJZN4+ZeGTMkU/NSnuiarch2cGcQ9EKzrdqyCEoB2i683tIsRxwDxka2jk+g6q4SH UHTK2m/ndwl7G3w4APBf2RVf16TXXB14SrtjFkiZ8knZKweWjPSVZtiqVIxTrhnJxp3v tyfnfijYFbY7+jyQi/iD6u0QeJc9DLgcaZ0k5RqDybiWA6yPgU6V02gieZMaZ4OCO30I XAcvl54JZOzFSSc/vF16wubzryWkPF10mDPjpEGAc6g6GREMQ/Yue8E+c1LBHggcBdAK SyqJkcHtouWRwsnNtrwGh9jmNmxjrOBL2hTBwKE6jWOEk49NNz5PZf0kKtTl6kgaCh0X k9lg== 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=1i18Uzv3FgWYZnvh42+cnPI4oEnLnpQ7V5EeM7zt4QE=; b=u8QRQA60soZAb5kel+ZVpJWB+mXC2xkCuqK8xUC1dK7itin54mIL0Q7zHYbIhnmK0c GQhgfdhQX/rOEkhZ6wDJMcq+/endDaxFLz/VCa4+EG24A7aXUsfzk57d89daM311qKhh 8F+8+z8D4Eb4SP47nVAGK6Dd7EuRsqqmKbYncRGA/fONh2lemexUj75lWVgzqiee50Lw lSdG+HDQqHsGQmBsTH3j76ZNqOXlyO/ThKss71b9/cbSZySmlz0YBknzRLjQ0TE546wy RF73pI6u4GpsifIOZyRiUr3cJGnO3WtDGAfrP80bJw3eb3D9p3GH+2bM2We49e5wODD9 JZlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aDZ755YO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z7si9990889pgv.205.2019.02.25.13.38.56; Mon, 25 Feb 2019 13:39:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aDZ755YO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732220AbfBYVhN (ORCPT + 99 others); Mon, 25 Feb 2019 16:37:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:44324 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731280AbfBYVhL (ORCPT ); Mon, 25 Feb 2019 16:37:11 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 850ED20578; Mon, 25 Feb 2019 21:37:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551130631; bh=fMB1TRwHQTi8rdkIn6i1myVE8hUE7moblHeTr8be//4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aDZ755YOpdOv+zZq7N8xZsqOnQArm64lHzlNzwDBXG3zRm+Sh0YRcYHYYfuBmorjV Ll/oaF9TcRc+OazVcv1iZeYeba7gJ4L7IEpWQujyws6TzaJ/ZZgARcR5zkV4OiwXqv 5s0ztNlMuog5R+0DVsdJa6B0OFqY7GjkweIPXqmY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Masato Suzuki , Damien Le Moal , "Martin K. Petersen" Subject: [PATCH 4.20 145/183] scsi: sd_zbc: Fix sd_zbc_report_zones() buffer allocation Date: Mon, 25 Feb 2019 22:11:58 +0100 Message-Id: <20190225195119.364160442@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190225195054.748060397@linuxfoundation.org> References: <20190225195054.748060397@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Masato Suzuki commit 515ce60613128be7a176a8b82b20c7624f3b440d upstream. The function sd_zbc_do_report_zones() issues a REPORT ZONES command with a buffer size calculated based on the number of zones requested by the caller. This value should however not exceed the capabilities of the hardware maximum command size, that is, should not exceed the max_hw_sectors limit of the device. This problem leads to failures of report zones commands when re-validating disks with some SAS HBAs. Fix this by limiting a report zone command buffer size to the minimum of the device max_hw_sectors and calculated value based on the requested number of zones. This does not change the semantic of the report_zones file operation as report zones can always return less zone reports than requested. Short reports are handled using a loop execution of the report_zones file operation in the function blk_report_zones(). [Damien] Before patch 'e76239a3748c ("block: add a report_zones method")', report zones buffer allocation was limited to max_sectors when allocated in blk_report_zones(). This however does not consider the actual format of the device reply which is interface dependent. Limiting the allocation based on the size of the expected reply format rather than the size of the array of generic sturct blkzone passed by blk_report_zones() makes more sense. Fixes: e76239a3748c ("block: add a report_zones method") Cc: stable@vger.kernel.org Signed-off-by: Masato Suzuki Signed-off-by: Damien Le Moal Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/sd_zbc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/drivers/scsi/sd_zbc.c +++ b/drivers/scsi/sd_zbc.c @@ -142,10 +142,12 @@ int sd_zbc_report_zones(struct gendisk * return -EOPNOTSUPP; /* - * Get a reply buffer for the number of requested zones plus a header. - * For ATA, buffers must be aligned to 512B. + * Get a reply buffer for the number of requested zones plus a header, + * without exceeding the device maximum command size. For ATA disks, + * buffers must be aligned to 512B. */ - buflen = roundup((nrz + 1) * 64, 512); + buflen = min(queue_max_hw_sectors(disk->queue) << 9, + roundup((nrz + 1) * 64, 512)); buf = kmalloc(buflen, gfp_mask); if (!buf) return -ENOMEM;