Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4415019pxa; Mon, 10 Aug 2020 08:33:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyq5BGBRq2tPKAy/BymGmDLNqgKsdhmhwhm1yYbyhBJ8CGxYCB2CcIbH3jnaZlDu1AMCT3F X-Received: by 2002:a05:6402:c86:: with SMTP id cm6mr20942056edb.205.1597073598891; Mon, 10 Aug 2020 08:33:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597073598; cv=none; d=google.com; s=arc-20160816; b=B2ybUPpUWpE//NMDueK7y/7ZRNpbIv+5XOn/qfUbKD4Yn8pBDhPtDRADuniiFF9MTt +ldm6LuHpDDYXZ9WFagFUnj98xqltOwnBop8945XZYQZjGqYDZhhfqnwi93ao8n3a43f IbtRk83By0CWTnMtxumHbKV3Z5Pwv4ooDwbkIAaePkTPW9plWkaX1g+czOysxkI2fX+A QK3bSuIj4SRsRQakRkNJBQfu3BZssNP9m6+wkXd0aBho1+jFOrrn4WrlTwtBTCbPfJma iOfQqfJoOpQ+JgdGm9fBdPGhxhMYcOaWlTYfPKQQ9C8iLdXqHZHAL5HYKmpoQLd7fnL6 8ezg== 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=IEnngxbwCNfOZeO0G+04D9KuO7o4Z5OcgMTl016ZxIA=; b=mXoaEpdpjaeV0zxcTjcvLqTmMzhAvLW1Qzu0I0SBoJA8IPSNrcM4Gxr+MzRl0wLVDy e71sfM7HBNJ4vZvWEN0Bwjd8NxJmjXpu0mEFFVKCJYMuy5yzht+Pfy9HELlye1ruK5B6 WlEjU+bhYgUBFttz7lU2YbAwHZLbmrhE1po49WQrgLEw06nJXduqBrImRi1dXFnPPcUU Ka9/2StNqDN7Odz3KnBFY1+nko/jDh6vBPcvCgrMkgTOGT6jkOa38bzKc/j62NEtXysf C3j3qiRuMXVLoyOogGT+Bo39w0tMnZe4Z8+jkneKzkLmEFlPNU/krdsRUMaT8R27yV/B o2XA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=f9WTMfsY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cz6si11984903edb.254.2020.08.10.08.32.55; Mon, 10 Aug 2020 08:33:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=f9WTMfsY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729095AbgHJPab (ORCPT + 99 others); Mon, 10 Aug 2020 11:30:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:37342 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729087AbgHJPa2 (ORCPT ); Mon, 10 Aug 2020 11:30:28 -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 22A8B20774; Mon, 10 Aug 2020 15:30:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597073427; bh=svSMAr6v2ZQ6WmxVzTEmE9bCbZf8H/CeYCuzFEXsHmw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f9WTMfsYxPttpwshB6esbNBXpHb0iEOv2w+lz88PH2Euny28U7vU5zzGISgZAm5uh Of0of/sbKZmoioveoMsLllPctyIeWoHcTSw90L5vX/TI7tfI8pkbSQITLacajTBpIk bEAEe4QED9OhqCi/U6yj5BlcYFfU475M4MMrW3IA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johan Hovold , "David S. Miller" Subject: [PATCH 4.19 36/48] net: lan78xx: replace bogus endpoint lookup Date: Mon, 10 Aug 2020 17:21:58 +0200 Message-Id: <20200810151805.993740717@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200810151804.199494191@linuxfoundation.org> References: <20200810151804.199494191@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: Johan Hovold [ Upstream commit ea060b352654a8de1e070140d25fe1b7e4d50310 ] Drop the bogus endpoint-lookup helper which could end up accepting interfaces based on endpoints belonging to unrelated altsettings. Note that the returned bulk pipes and interrupt endpoint descriptor were never actually used. Instead the bulk-endpoint numbers are hardcoded to 1 and 2 (matching the specification), while the interrupt- endpoint descriptor was assumed to be the third descriptor created by USB core. Try to bring some order to this by dropping the bogus lookup helper and adding the missing endpoint sanity checks while keeping the interrupt- descriptor assumption for now. Signed-off-by: Johan Hovold Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/usb/lan78xx.c | 117 +++++++++++----------------------------------- 1 file changed, 30 insertions(+), 87 deletions(-) --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -388,10 +388,6 @@ struct lan78xx_net { struct tasklet_struct bh; struct delayed_work wq; - struct usb_host_endpoint *ep_blkin; - struct usb_host_endpoint *ep_blkout; - struct usb_host_endpoint *ep_intr; - int msg_enable; struct urb *urb_intr; @@ -2883,78 +2879,12 @@ lan78xx_start_xmit(struct sk_buff *skb, return NETDEV_TX_OK; } -static int -lan78xx_get_endpoints(struct lan78xx_net *dev, struct usb_interface *intf) -{ - int tmp; - struct usb_host_interface *alt = NULL; - struct usb_host_endpoint *in = NULL, *out = NULL; - struct usb_host_endpoint *status = NULL; - - for (tmp = 0; tmp < intf->num_altsetting; tmp++) { - unsigned ep; - - in = NULL; - out = NULL; - status = NULL; - alt = intf->altsetting + tmp; - - for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) { - struct usb_host_endpoint *e; - int intr = 0; - - e = alt->endpoint + ep; - switch (e->desc.bmAttributes) { - case USB_ENDPOINT_XFER_INT: - if (!usb_endpoint_dir_in(&e->desc)) - continue; - intr = 1; - /* FALLTHROUGH */ - case USB_ENDPOINT_XFER_BULK: - break; - default: - continue; - } - if (usb_endpoint_dir_in(&e->desc)) { - if (!intr && !in) - in = e; - else if (intr && !status) - status = e; - } else { - if (!out) - out = e; - } - } - if (in && out) - break; - } - if (!alt || !in || !out) - return -EINVAL; - - dev->pipe_in = usb_rcvbulkpipe(dev->udev, - in->desc.bEndpointAddress & - USB_ENDPOINT_NUMBER_MASK); - dev->pipe_out = usb_sndbulkpipe(dev->udev, - out->desc.bEndpointAddress & - USB_ENDPOINT_NUMBER_MASK); - dev->ep_intr = status; - - return 0; -} - static int lan78xx_bind(struct lan78xx_net *dev, struct usb_interface *intf) { struct lan78xx_priv *pdata = NULL; int ret; int i; - ret = lan78xx_get_endpoints(dev, intf); - if (ret) { - netdev_warn(dev->net, "lan78xx_get_endpoints failed: %d\n", - ret); - return ret; - } - dev->data[0] = (unsigned long)kzalloc(sizeof(*pdata), GFP_KERNEL); pdata = (struct lan78xx_priv *)(dev->data[0]); @@ -3726,6 +3656,7 @@ static void lan78xx_stat_monitor(struct static int lan78xx_probe(struct usb_interface *intf, const struct usb_device_id *id) { + struct usb_host_endpoint *ep_blkin, *ep_blkout, *ep_intr; struct lan78xx_net *dev; struct net_device *netdev; struct usb_device *udev; @@ -3774,6 +3705,34 @@ static int lan78xx_probe(struct usb_inte mutex_init(&dev->stats.access_lock); + if (intf->cur_altsetting->desc.bNumEndpoints < 3) { + ret = -ENODEV; + goto out2; + } + + dev->pipe_in = usb_rcvbulkpipe(udev, BULK_IN_PIPE); + ep_blkin = usb_pipe_endpoint(udev, dev->pipe_in); + if (!ep_blkin || !usb_endpoint_is_bulk_in(&ep_blkin->desc)) { + ret = -ENODEV; + goto out2; + } + + dev->pipe_out = usb_sndbulkpipe(udev, BULK_OUT_PIPE); + ep_blkout = usb_pipe_endpoint(udev, dev->pipe_out); + if (!ep_blkout || !usb_endpoint_is_bulk_out(&ep_blkout->desc)) { + ret = -ENODEV; + goto out2; + } + + ep_intr = &intf->cur_altsetting->endpoint[2]; + if (!usb_endpoint_is_int_in(&ep_intr->desc)) { + ret = -ENODEV; + goto out2; + } + + dev->pipe_intr = usb_rcvintpipe(dev->udev, + usb_endpoint_num(&ep_intr->desc)); + ret = lan78xx_bind(dev, intf); if (ret < 0) goto out2; @@ -3786,23 +3745,7 @@ static int lan78xx_probe(struct usb_inte netdev->max_mtu = MAX_SINGLE_PACKET_SIZE; netif_set_gso_max_size(netdev, MAX_SINGLE_PACKET_SIZE - MAX_HEADER); - if (intf->cur_altsetting->desc.bNumEndpoints < 3) { - ret = -ENODEV; - goto out3; - } - - dev->ep_blkin = (intf->cur_altsetting)->endpoint + 0; - dev->ep_blkout = (intf->cur_altsetting)->endpoint + 1; - dev->ep_intr = (intf->cur_altsetting)->endpoint + 2; - - dev->pipe_in = usb_rcvbulkpipe(udev, BULK_IN_PIPE); - dev->pipe_out = usb_sndbulkpipe(udev, BULK_OUT_PIPE); - - dev->pipe_intr = usb_rcvintpipe(dev->udev, - dev->ep_intr->desc.bEndpointAddress & - USB_ENDPOINT_NUMBER_MASK); - period = dev->ep_intr->desc.bInterval; - + period = ep_intr->desc.bInterval; maxp = usb_maxpacket(dev->udev, dev->pipe_intr, 0); buf = kmalloc(maxp, GFP_KERNEL); if (buf) {