Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp4464420ybx; Mon, 4 Nov 2019 13:52:15 -0800 (PST) X-Google-Smtp-Source: APXvYqztzMUwEJakH8eB6RYm6gGzr0R4jD1Gz5s1lhqEeh2TK8D+ERFcID8f4UICfxF1CkTdwzQY X-Received: by 2002:a50:9850:: with SMTP id h16mr8845282edb.193.1572904335870; Mon, 04 Nov 2019 13:52:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572904335; cv=none; d=google.com; s=arc-20160816; b=O9g6gFBMqs1qYWrX3iAu+Q2UC6wxb2zt8wXYmM7rU2eVfbNHFhk/CIHAduMZkYwW+W gXytFxB8w0yPktdbaW8oyAnL8ljopHYejADIyN2801wIJYm80wiPksyrUr7KZ6nEjyyz 2qnkGNhJE/jvbptVB6aaxx0uGN0Hx9bL7TQXkdWnq2gIgYloBh/tKOxpokcGF27mZmVg m/Owb9PWfQ9xfV5hS3MD3827gqeYutEovRCDg/JIoSq6SONNXN8hGKr475P1dbijokYv muLBSgsKnrYnnuhHxln7Hec7Y1rtAx82bP5iq2fP/5eAQt6es5XB3JJcxBX2AvJAmHU2 qfAA== 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=zFLvsAZfclP4YD1Liv4dBxyGyyvwphPza6wzJBo3K+Q=; b=fc46T/l+2de3auvz/IL2svCqoTdGUhaCtpnnO2P2hqppK+V4tKYJjWyTb06Q/+xqMz 5zqu10ERz6RHZZlGA+M7Xq5BLAeDTvQChCzTP4qFxNQRlW9jRAvF0IpHIod/espiIrBl Z6S7iC3UUGSFnXqktMBV39CkTk8qP/sTid3CFfgb/LOgtxhFsCvaPDHvxKwUsl4L9DVn niYEXpIeox5NbwCa/l2Ba6vOBe7y2p87G23PhlnvyHolWOhd/bcfdsO4X9EjCxH8pWiS Xc6Dl/qOlBP0pXOtza0LR5XlV5enm6ftZjw37Vn1iHqekN8gkyTJBV5sShkqTvJpcmVc wxEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hVEZ0C3u; 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 h13si3584613ejq.54.2019.11.04.13.51.53; Mon, 04 Nov 2019 13:52:15 -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=hVEZ0C3u; 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 S1730095AbfKDVsk (ORCPT + 99 others); Mon, 4 Nov 2019 16:48:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:39244 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730085AbfKDVsi (ORCPT ); Mon, 4 Nov 2019 16:48:38 -0500 Received: from localhost (6.204-14-84.ripe.coltfrance.com [84.14.204.6]) (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 BFF8C20B7C; Mon, 4 Nov 2019 21:48:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572904118; bh=r7I7Ejrdfpo/PUppM//zRRCS8J4yVK7fBNePuGo0bGo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hVEZ0C3u2a39N2Bj9OcS99eEfUfhnXGgCG6EglaEP2OxXgd1LIgEryEBx/aRVUwnb WMzyqNoO26f5pUMf6DyYh0pK0AChz+RVtcxHqQwywljVBIFV0iLUh3jrWiQvPV/quX T/J7qOju5AcqApDLJRCKKWvJ3s70SoXp9L3rBVlU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alan Stern , Felipe Balbi , syzbot+8ab8bf161038a8768553@syzkaller.appspotmail.com Subject: [PATCH 4.4 29/46] USB: gadget: Reject endpoints with 0 maxpacket value Date: Mon, 4 Nov 2019 22:45:00 +0100 Message-Id: <20191104211902.213280126@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191104211830.912265604@linuxfoundation.org> References: <20191104211830.912265604@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: Alan Stern commit 54f83b8c8ea9b22082a496deadf90447a326954e upstream. Endpoints with a maxpacket length of 0 are probably useless. They can't transfer any data, and it's not at all unlikely that a UDC will crash or hang when trying to handle a non-zero-length usb_request for such an endpoint. Indeed, dummy-hcd gets a divide error when trying to calculate the remainder of a transfer length by the maxpacket value, as discovered by the syzbot fuzzer. Currently the gadget core does not check for endpoints having a maxpacket value of 0. This patch adds a check to usb_ep_enable(), preventing such endpoints from being used. As far as I know, none of the gadget drivers in the kernel tries to create an endpoint with maxpacket = 0, but until now there has been nothing to prevent userspace programs under gadgetfs or configfs from doing it. Signed-off-by: Alan Stern Reported-and-tested-by: syzbot+8ab8bf161038a8768553@syzkaller.appspotmail.com CC: Acked-by: Felipe Balbi Link: https://lore.kernel.org/r/Pine.LNX.4.44L0.1910281052370.1485-100000@iolanthe.rowland.org Signed-off-by: Greg Kroah-Hartman --- include/linux/usb/gadget.h | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -270,6 +270,16 @@ static inline int usb_ep_enable(struct u if (ep->enabled) return 0; + /* UDC drivers can't handle endpoints with maxpacket size 0 */ + if (usb_endpoint_maxp(ep->desc) == 0) { + /* + * We should log an error message here, but we can't call + * dev_err() because there's no way to find the gadget + * given only ep. + */ + return -EINVAL; + } + ret = ep->ops->enable(ep, ep->desc); if (ret) return ret;