Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1172548yba; Thu, 9 May 2019 11:58:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqyGylBZ6hYh5OnckZmyEk06W5cV0pt/R1unLzHqfUnmCqxKXYUstOgPxvrRmxTvaZV7bcGf X-Received: by 2002:a65:5682:: with SMTP id v2mr7918125pgs.100.1557428313625; Thu, 09 May 2019 11:58:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557428313; cv=none; d=google.com; s=arc-20160816; b=m+O7j6GxsqZAnG32DGiyZIVJbm4DrRzvI3e1Rs2CMtY5iSANFUGPegYK39IqzUbNYl 3Gyvx0DQaMcmlc+j7YoC1giX20wvKmgAeUR8KX7zH7WYWMS838+KC2p0H0HpkWxKfQlx 8OP5m7qKDNQlaYqjeqFVrKHpVmAqtFVpouL960t9dgcd/bNuRdatLNlwBP2SYd6QRWlE QC9w3qH1K46Ob4N9AuuBOYWfoehzrOLiCDU08QCK69hUGvD6eMHwJofttruuXPO9VrtM 6Y4mGfhTNns0Joq+YUJlJKxOvUbDv4lgXiyZNmYKKduk2vLL6l1pKZd/OejS5c6WckZX DRLA== 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=pNzg+Qxi+5O0Dx0YOgn4+l2JusfyrtF1htFA8s5XuVM=; b=atXpQB6EbPaADP26JXHSCWckMxoGbVw4ZgT9Br+f9IWkGVH+Pk+mvnZMb3MctIauaG 5IppIyNlqrsoRDZF0GtYqzD9JKwsuOMYstMwDv7YOD2wjMfYCnm/xzbcUHKCJmLwIiiO Dzz7ZvVNpONgnVsGKtONUBlLnttIZdPUWCRdwNYNsAG927VNObIYGO2gpOCnv7UqKQ1a YXp3l5GUZSNYnJ+yCfYsLzEpcDT15h7AlbQbt+oIzrCGC4Zp9uY436X26gowpRCJjH6+ z+4gtmlraipKL44zZ2fZk73wULak2YFvsmfzCY8NdGgtvkjQDSazBQJSrFbRUUbzqNf1 3EyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1ouUgs92; 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 l61si4255001plb.194.2019.05.09.11.58.17; Thu, 09 May 2019 11:58:33 -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=1ouUgs92; 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 S1729011AbfEIS4A (ORCPT + 99 others); Thu, 9 May 2019 14:56:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:50446 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729226AbfEISzY (ORCPT ); Thu, 9 May 2019 14:55:24 -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 C6E522177E; Thu, 9 May 2019 18:55:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557428123; bh=hFGAcTGN8+exjIpw3elz3HCRPqeJPoKx3U8wzUVaBrI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1ouUgs92g2DcbmRMaD2T8Bp88WJVS7rnIyc5roVrYyH+GIwwCaXA50fDj9WwZcEYg SiUM+dwLdU6NJDk0dD25zDqZVPbLuSv1q40xjkelDxdODDwrcCEbc83V8f9IU7TCXE +gojYpNRDB5O/c0YHU2AmVf5X6ZkVwmniEskn0nE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oliver Neukum Subject: [PATCH 5.1 26/30] UAS: fix alignment of scatter/gather segments Date: Thu, 9 May 2019 20:42:58 +0200 Message-Id: <20190509181256.628727841@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190509181250.417203112@linuxfoundation.org> References: <20190509181250.417203112@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 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 @@ -789,24 +789,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));