Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp799349imu; Tue, 11 Dec 2018 07:46:53 -0800 (PST) X-Google-Smtp-Source: AFSGD/UIhMgcaBl6Xlnseiq+STQDkoa99UVt7aDqp40RD0atEX3VoHUaKkqwmfQP3LZwjsoojobQ X-Received: by 2002:a17:902:6b09:: with SMTP id o9mr16467429plk.208.1544543213452; Tue, 11 Dec 2018 07:46:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544543213; cv=none; d=google.com; s=arc-20160816; b=ckzbOAMFhNU66Un4dQ0ahRfkBiLZ4kPAA2Zq7Iw3m39rqCKHB7oB/V876QelMJvHfi ve/G2berkw2ewRC+Wmpq/hXJyHg5kj2PXpjrsogK5Wp3rUxOrkwt8HkSGXBkiNwYdp6t jdAUw1kfEU3JVofMamRCDljxDpECfPW2r1/J3S/LiiKoKPhSRiatj43CHRIOT41mCc5g PLSIHGTIRgyBQwFj4mNAuAbUwbcDFjIOBVM2/FDePrOx6TY6uWbdniGZb5UvXEvBPm5n Yyp4i3e0hH6UGqMv2e8SE0Z3e3oo+OHF92KDhk7x98+Q94X/IH9UyfQO3AAnT87mhzDf YnLQ== 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=V6zb8HcgpfqYLUWcces2qFoAcmfsEkJs3xxAaIGg+cE=; b=QZUtFP0lHaUbHlFBpI/U6KLzdYj1ch52g6nCT1KzK1JCGuFO/XlBSHaWM7esqgSL6z q+n9/22fBFwDn1IeSABOObFXBajq2rwYk/tsdberrW+2Uvu7cEsVmpNW3vqwgLs+FhOo RIkEhJS1VipQ36gOhIZfhpUrTPVPW3BFYnIfHhioBIw/ScT6O986zhFHZTTfsN0VHObR lR4EjqTKpb3DneekNgEQbkMbhHmmaxTyPJ47zGG1k2DiK0sBipVUrIS1s1LrqVYWJjAU lz8RF+wjEeyDhQ/XXyRTV0P0WSVgHypIZLC0yGXCw7GdJk/rpGfkkVkWK7PC4SYYhDA6 Hu5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PNpzpwi9; 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 k30si12190604pgb.113.2018.12.11.07.46.39; Tue, 11 Dec 2018 07:46:53 -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=PNpzpwi9; 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 S1727711AbeLKPoD (ORCPT + 99 others); Tue, 11 Dec 2018 10:44:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:60580 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727659AbeLKPoB (ORCPT ); Tue, 11 Dec 2018 10:44:01 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 7CDEE20870; Tue, 11 Dec 2018 15:44:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544543041; bh=bEeiCWTS8J9RleeqNSReoFZAr0WtFEaHBvIrwWhkAZg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PNpzpwi9MsnG/IqGQk+1c+uxoL13FQ82goZAj+LBQpbEu8B4fIvBPVdWDH3O3D4XP Nh50izPJ8GqDdv7OpDnH9fqkhQzITOy/IPx/+/kU7QxLsnogzILnDTZhLl+pZMTp5O 63e4GQ+osqglwWlbtV5/IkVGeflyTSNgt2PYTG6s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hui Peng , Mathias Payer , Linus Torvalds , stable Subject: [PATCH 3.18 43/54] USB: check usb_get_extra_descriptor for proper size Date: Tue, 11 Dec 2018 16:41:31 +0100 Message-Id: <20181211151548.477954117@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181211151546.010073210@linuxfoundation.org> References: <20181211151546.010073210@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Mathias Payer commit 704620afc70cf47abb9d6a1a57f3825d2bca49cf upstream. When reading an extra descriptor, we need to properly check the minimum and maximum size allowed, to prevent from invalid data being sent by a device. Reported-by: Hui Peng Reported-by: Mathias Payer Co-developed-by: Linus Torvalds Signed-off-by: Hui Peng Signed-off-by: Mathias Payer Signed-off-by: Linus Torvalds Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/hub.c | 3 ++- drivers/usb/core/usb.c | 6 +++--- drivers/usb/host/hwa-hc.c | 2 +- include/linux/usb.h | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -2236,7 +2236,8 @@ static int usb_enumerate_device_otg(stru /* descriptor may appear anywhere in config */ if (__usb_get_extra_descriptor (udev->rawdescriptors[0], le16_to_cpu(udev->config[0].desc.wTotalLength), - USB_DT_OTG, (void **) &desc) == 0) { + USB_DT_OTG, (void **) &desc, + sizeof(*desc)) == 0) { if (desc->bmAttributes & USB_OTG_HNP) { unsigned port1 = udev->portnum; --- a/drivers/usb/core/usb.c +++ b/drivers/usb/core/usb.c @@ -664,14 +664,14 @@ EXPORT_SYMBOL_GPL(usb_get_current_frame_ */ int __usb_get_extra_descriptor(char *buffer, unsigned size, - unsigned char type, void **ptr) + unsigned char type, void **ptr, size_t minsize) { struct usb_descriptor_header *header; while (size >= sizeof(struct usb_descriptor_header)) { header = (struct usb_descriptor_header *)buffer; - if (header->bLength < 2) { + if (header->bLength < 2 || header->bLength > size) { printk(KERN_ERR "%s: bogus descriptor, type %d length %d\n", usbcore_name, @@ -680,7 +680,7 @@ int __usb_get_extra_descriptor(char *buf return -1; } - if (header->bDescriptorType == type) { + if (header->bDescriptorType == type && header->bLength >= minsize) { *ptr = header; return 0; } --- a/drivers/usb/host/hwa-hc.c +++ b/drivers/usb/host/hwa-hc.c @@ -654,7 +654,7 @@ static int hwahc_security_create(struct top = itr + itr_size; result = __usb_get_extra_descriptor(usb_dev->rawdescriptors[index], le16_to_cpu(usb_dev->actconfig->desc.wTotalLength), - USB_DT_SECURITY, (void **) &secd); + USB_DT_SECURITY, (void **) &secd, sizeof(*secd)); if (result == -1) { dev_warn(dev, "BUG? WUSB host has no security descriptors\n"); return 0; --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -329,11 +329,11 @@ struct usb_host_bos { }; int __usb_get_extra_descriptor(char *buffer, unsigned size, - unsigned char type, void **ptr); + unsigned char type, void **ptr, size_t min); #define usb_get_extra_descriptor(ifpoint, type, ptr) \ __usb_get_extra_descriptor((ifpoint)->extra, \ (ifpoint)->extralen, \ - type, (void **)ptr) + type, (void **)ptr, sizeof(**(ptr))) /* ----------------------------------------------------------------------- */