From mboxrd@z Thu Jan 1 00:00:00 1970 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=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,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 81F56C32792 for ; Thu, 3 Oct 2019 17:16:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3B67721A4C for ; Thu, 3 Oct 2019 17:16:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570122973; bh=2NQHd2QxdKNhEULOQ3m6pk/Bq8wN86OiE8oTa6a2Tsg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=TZzJlmAprI2ERGwAFVeJC5n9RIBEOWxfi5F5zDk+T0/K3ELRpxw7OhxXPycOvvqWd JfnPFvCQK/K3XhVlofGDLGrH5tgEJNeH4lwTZCewuUIH52uEGhv0xnj7z/xt7Xj5Gk LW3puWYMay0weCt6tveXmmxBXJW+zaJLKarig2EU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390816AbfJCQYw (ORCPT ); Thu, 3 Oct 2019 12:24:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:54750 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390019AbfJCQYv (ORCPT ); Thu, 3 Oct 2019 12:24:51 -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 64D012054F; Thu, 3 Oct 2019 16:24:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570119890; bh=2NQHd2QxdKNhEULOQ3m6pk/Bq8wN86OiE8oTa6a2Tsg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u+bDIERZnhgsZoN8eMQ8U7OmCszIvwX/UEqlesyLBUCUjqTQSNtk8kdZTFpZZMXMK +LpKfmnm1DOhOYl0++HCcEajSo/V8D8s1f2fGOboTFawh3/dXQFk6Fq5+nO2P/i5JA ckt7X8wpVDR5sEjxsz+J9NZRkuFNp7XKiblV9lBY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+ce366e2b8296e25d84f5@syzkaller.appspotmail.com, =?UTF-8?q?Bj=C3=B8rn=20Mork?= , Jakub Kicinski Subject: [PATCH 5.2 002/313] cdc_ncm: fix divide-by-zero caused by invalid wMaxPacketSize Date: Thu, 3 Oct 2019 17:49:40 +0200 Message-Id: <20191003154533.792457976@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154533.590915454@linuxfoundation.org> References: <20191003154533.590915454@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Bjørn Mork [ Upstream commit 3fe4b3351301660653a2bc73f2226da0ebd2b95e ] Endpoints with zero wMaxPacketSize are not usable for transferring data. Ignore such endpoints when looking for valid in, out and status pipes, to make the driver more robust against invalid and meaningless descriptors. The wMaxPacketSize of the out pipe is used as divisor. So this change fixes a divide-by-zero bug. Reported-by: syzbot+ce366e2b8296e25d84f5@syzkaller.appspotmail.com Signed-off-by: Bjørn Mork Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/usb/cdc_ncm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/drivers/net/usb/cdc_ncm.c +++ b/drivers/net/usb/cdc_ncm.c @@ -681,8 +681,12 @@ cdc_ncm_find_endpoints(struct usbnet *de u8 ep; for (ep = 0; ep < intf->cur_altsetting->desc.bNumEndpoints; ep++) { - e = intf->cur_altsetting->endpoint + ep; + + /* ignore endpoints which cannot transfer data */ + if (!usb_endpoint_maxp(&e->desc)) + continue; + switch (e->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { case USB_ENDPOINT_XFER_INT: if (usb_endpoint_dir_in(&e->desc)) {