From patchwork Thu Aug 20 09:20:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 265484 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BEF9FC433DF for ; Thu, 20 Aug 2020 12:16:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9229720738 for ; Thu, 20 Aug 2020 12:16:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597925771; bh=MKw2zkMoNR52NXZ05/K5N9/DFpLHpLYLSmvRfyKtOcU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=MeiLEG7L9MvCs8NhCvOxfeOBEs+hbXYxAbE86QpUH3jYuAEzslh0dy4JEBflXZVxn L0Cs9p++LtEG9drp8mkRTeoLpa5GsjBCuefyAzwh58u52ahnPBlrjpo0cvfiq/RTkO 0tNnE0vffi4Hc/igy+k5VOD2XAqFDesytD+27xhU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729388AbgHTMPp (ORCPT ); Thu, 20 Aug 2020 08:15:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:40800 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730277AbgHTJ5H (ORCPT ); Thu, 20 Aug 2020 05:57:07 -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 B68682067C; Thu, 20 Aug 2020 09:57:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597917427; bh=MKw2zkMoNR52NXZ05/K5N9/DFpLHpLYLSmvRfyKtOcU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S/iCbZxjVyJfkrkoOehky7EPzM810w/fpb5yV2WZURX+Y1IGi2NjN+h5kJu4jPUKf h3U5xIY+MbZjBPSrMSR1mR7hhMIls8r208Aoo2SrjsA5njpNa6DGuZcm7MrnhflVfZ CyW2KBW8HevhQg3UB1iq4qCwXdQOlWtAMikgXSPc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Woojung.Huh@microchip.com" , Johan Hovold , "David S. Miller" , Sasha Levin Subject: [PATCH 4.9 027/212] net: lan78xx: add missing endpoint sanity check Date: Thu, 20 Aug 2020 11:20:00 +0200 Message-Id: <20200820091603.715508712@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091602.251285210@linuxfoundation.org> References: <20200820091602.251285210@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Johan Hovold [ Upstream commit 8d8e95fd6d69d774013f51e5f2ee10c6e6d1fc14 ] Add the missing endpoint sanity check to prevent a NULL-pointer dereference should a malicious device lack the expected endpoints. Note that the driver has a broken endpoint-lookup helper, lan78xx_get_endpoints(), which can end up accepting interfaces in an altsetting without endpoints as long as *some* altsetting has a bulk-in and a bulk-out endpoint. Fixes: 55d7de9de6c3 ("Microchip's LAN7800 family USB 2/3 to 10/100/1000 Ethernet device driver") Cc: Woojung.Huh@microchip.com Signed-off-by: Johan Hovold Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/usb/lan78xx.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c index 65e94dffaabc9..fd144a513e1fe 100644 --- a/drivers/net/usb/lan78xx.c +++ b/drivers/net/usb/lan78xx.c @@ -3392,6 +3392,11 @@ static int lan78xx_probe(struct usb_interface *intf, netdev->mtu = dev->hard_mtu - netdev->hard_header_len; 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;