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=-9.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 BE47CC43387 for ; Wed, 26 Dec 2018 22:59:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8D7B7214D8 for ; Wed, 26 Dec 2018 22:59:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1545865197; bh=yfVSh56HZ4jBav5/maJoY5uyUIBeIPOGkM60ILBksOc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=iwF39PJyCh7BPINddCUfQ39FjMz86qwFuqnW1+LCJ+UvZoVm0KaSR7o59DUY3w/Y6 581C6/fqegPV/7saNlr/YqZ3W/qWUqNqS5uCkRubXFuijA2BZD23jfe02lLUsvcHn/ fH4yu8SGp/XRS8NheIczZe04bplLxw+Z53Yej1Lo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730039AbeLZWyJ (ORCPT ); Wed, 26 Dec 2018 17:54:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:55460 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727935AbeLZWyG (ORCPT ); Wed, 26 Dec 2018 17:54:06 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 852BA21741; Wed, 26 Dec 2018 22:54:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1545864845; bh=yfVSh56HZ4jBav5/maJoY5uyUIBeIPOGkM60ILBksOc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M6h4/S0W04J4abt3acAAbguL/pdRNhPXEIXOa0VUdYmtKZgoZm3Fo4dRH0FzeYf53 kdQgf/VC427XQF+TYNngM9mV7oZUVexMN30dbLw+lfc6zx9MGFg+GcwNsTsae0WA/j h318rULs7+LTRHwsfP6/ZzToZhfdc0lvB5F3x8Bc= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Hui Peng , Mathias Payer , Greg Kroah-Hartman , "David S . Miller" , Sasha Levin , linux-usb@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 4.9 11/35] USB: hso: Fix OOB memory access in hso_probe/hso_get_config_data Date: Wed, 26 Dec 2018 17:41:18 -0500 Message-Id: <20181226224142.150866-11-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181226224142.150866-1-sashal@kernel.org> References: <20181226224142.150866-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hui Peng [ Upstream commit 5146f95df782b0ac61abde36567e718692725c89 ] The function hso_probe reads if_num from the USB device (as an u8) and uses it without a length check to index an array, resulting in an OOB memory read in hso_probe or hso_get_config_data. Add a length check for both locations and updated hso_probe to bail on error. This issue has been assigned CVE-2018-19985. Reported-by: Hui Peng Reported-by: Mathias Payer Signed-off-by: Hui Peng Signed-off-by: Mathias Payer Reviewed-by: Sebastian Andrzej Siewior Signed-off-by: Greg Kroah-Hartman Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/usb/hso.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c index e7b516342678..66ae647b712e 100644 --- a/drivers/net/usb/hso.c +++ b/drivers/net/usb/hso.c @@ -2808,6 +2808,12 @@ static int hso_get_config_data(struct usb_interface *interface) return -EIO; } + /* check if we have a valid interface */ + if (if_num > 16) { + kfree(config_data); + return -EINVAL; + } + switch (config_data[if_num]) { case 0x0: result = 0; @@ -2878,10 +2884,18 @@ static int hso_probe(struct usb_interface *interface, /* Get the interface/port specification from either driver_info or from * the device itself */ - if (id->driver_info) + if (id->driver_info) { + /* if_num is controlled by the device, driver_info is a 0 terminated + * array. Make sure, the access is in bounds! */ + for (i = 0; i <= if_num; ++i) + if (((u32 *)(id->driver_info))[i] == 0) + goto exit; port_spec = ((u32 *)(id->driver_info))[if_num]; - else + } else { port_spec = hso_get_config_data(interface); + if (port_spec < 0) + goto exit; + } /* Check if we need to switch to alt interfaces prior to port * configuration */ -- 2.19.1