Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1169521yba; Thu, 9 May 2019 11:54:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzAJHm7q3Wql19FfrDSxCUU9mfAXauNX8yQ3INYBmcgzWXe0JOErb04LLxKQTLwPxkBEF8s X-Received: by 2002:a62:4852:: with SMTP id v79mr7700392pfa.72.1557428087111; Thu, 09 May 2019 11:54:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557428087; cv=none; d=google.com; s=arc-20160816; b=bA1kmo3wxt4d5usF4INBhUHz8DTXm0Uz6bOE+SZmFikhSqZNtwj97YLnpZJCHIxaA0 +Izg27KRSNMLGqA9fyScaZd7JMrvuBRdGaiY/l6fBqgK0m1DAz6mHjkqVh1v1OUIVWRu 9S5DsTy83URW/ukPdLUYyNV6uz8uDLVIri5hq76VjafkqF+dHsq1zhPU3pH63q97yVcm 5SsRXRrIBw6UtVsg033ztiFKagNgQFipmy7kIw3z7WxSssa4vbXxj1wqfBnn0iGHcEk0 Rlld1pjjPWtH+LdtmKRbPW54h0+0WNGeZ2FDwNnwoG8wqAiftPopf9asdPVYqLnPxE8D Httw== 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=pvNZ20rFW0eRbXtLxcmH43AW9bpNilv8INObenp7A/w=; b=R1YCrgkebFrg5yL+vOODrHjbQSwrZgupwYOtZ2eitHiB2CjNTqb486T3w9CoOMClX7 ugWz8bWlMhKBrHhulgOGHF0DQFdXX9wlzrWM3vbFUpE9NdAoAbXkU5HZEP7oUNLr7UJR UOLBpDNE79blUY5DVpcUfoxATwCqziXo1TrYHYXT6XNnmrr8Wh/po7YzvSL7Q2MjdpKS rFPMXf1Vu4w4XJi0cpIFOd+zT+IoV5tcMD9IrIc6tADPg6m0oUNUk5pHttKDW7P/1yix TYVcw083QxHjA+7NpejCuyBNvaLx49fgAK/vSKQEXfAo7WgShiW22iIrGvbbRWavRGn3 Il3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="vaPPLxx/"; 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 j9si3954961plk.125.2019.05.09.11.54.30; Thu, 09 May 2019 11:54:47 -0700 (PDT) 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="vaPPLxx/"; 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 S1728638AbfEISxm (ORCPT + 99 others); Thu, 9 May 2019 14:53:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:48186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728915AbfEISxj (ORCPT ); Thu, 9 May 2019 14:53:39 -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 DCEF6217D7; Thu, 9 May 2019 18:53:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557428018; bh=DSgNyAu3218PTqN3ZNvpI+NYW6lqI+fUcvQx/HBEHVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vaPPLxx/MrCh1OSUoLXeyG+uN4+mIIDzryQo6u0yTI2fXr1v6G6lMFHMRfGZsfZXV L+WJ5l0I6X/8k6Q6yznu62XwJhJ730SB6fUzFIa4zwp5fRQdHgYsr7KQ+I2r/maKZr V5ckDwpo/TuPBYc5Kepn5M0G2A8TxuKWinNhcLjI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oliver Neukum Subject: [PATCH 5.0 91/95] UAS: fix alignment of scatter/gather segments Date: Thu, 9 May 2019 20:42:48 +0200 Message-Id: <20190509181315.584004736@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190509181309.180685671@linuxfoundation.org> References: <20190509181309.180685671@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: Oliver Neukum commit 3ae62a42090f1ed48e2313ed256a1182a85fb575 upstream. This is the UAS version of 747668dbc061b3e62bc1982767a3a1f9815fcf0e usb-storage: Set virt_boundary_mask to avoid SG overflows We are not as likely to be vulnerable as storage, as it is unlikelier that UAS is run over a controller without native support for SG, but the issue exists. The issue has been existing since the inception of the driver. Fixes: 115bb1ffa54c ("USB: Add UAS driver") Signed-off-by: Oliver Neukum Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/usb/storage/uas.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) --- a/drivers/usb/storage/uas.c +++ b/drivers/usb/storage/uas.c @@ -796,24 +796,33 @@ static int uas_slave_alloc(struct scsi_d { struct uas_dev_info *devinfo = (struct uas_dev_info *)sdev->host->hostdata; + int maxp; sdev->hostdata = devinfo; /* - * USB has unusual DMA-alignment requirements: Although the - * starting address of each scatter-gather element doesn't matter, - * the length of each element except the last must be divisible - * by the Bulk maxpacket value. There's currently no way to - * express this by block-layer constraints, so we'll cop out - * and simply require addresses to be aligned at 512-byte - * boundaries. This is okay since most block I/O involves - * hardware sectors that are multiples of 512 bytes in length, - * and since host controllers up through USB 2.0 have maxpacket - * values no larger than 512. + * We have two requirements here. We must satisfy the requirements + * of the physical HC and the demands of the protocol, as we + * definitely want no additional memory allocation in this path + * ruling out using bounce buffers. * - * But it doesn't suffice for Wireless USB, where Bulk maxpacket - * values can be as large as 2048. To make that work properly - * will require changes to the block layer. + * For a transmission on USB to continue we must never send + * a package that is smaller than maxpacket. Hence the length of each + * scatterlist element except the last must be divisible by the + * Bulk maxpacket value. + * If the HC does not ensure that through SG, + * the upper layer must do that. We must assume nothing + * about the capabilities off the HC, so we use the most + * pessimistic requirement. + */ + + maxp = usb_maxpacket(devinfo->udev, devinfo->data_in_pipe, 0); + blk_queue_virt_boundary(sdev->request_queue, maxp - 1); + + /* + * The protocol has no requirements on alignment in the strict sense. + * Controllers may or may not have alignment restrictions. + * As this is not exported, we use an extremely conservative guess. */ blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1));