Received: by 10.192.165.148 with SMTP id m20csp2426750imm; Sun, 22 Apr 2018 06:56:58 -0700 (PDT) X-Google-Smtp-Source: AIpwx48fR9A8GE8ax1t3yAbx8yMLydKFMLCl6Gn8LWQW9rb0nuIylRUwf6i3duZUS7YMfx1cPzV0 X-Received: by 10.99.127.3 with SMTP id a3mr14167543pgd.267.1524405418204; Sun, 22 Apr 2018 06:56:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524405418; cv=none; d=google.com; s=arc-20160816; b=idLREabh2gwm+2qq7XNkboKsFiq1d2Hf5GiMbmNg8w3Gx8sQyGggfHlXPWvn0OpcGZ kp8b0XHrAUWvVlUzQJkQAsRFIvkHpN67LPzOKqtaUBWGANANrSKkD30um1IOhaVQxZxk HXuvYuhKDHXXkn+aLAlPMYK3idBhsjtP+wHSKcyVxitr7fr5bbkE7tqgYWzA3u9dy7Eg hkrK3reoe5wY3SgPcrKYmXZutOnz3+HuMFbgK+JlnHtr2u9SWd3EK/jCkyhKaYtC3QKI 1IrUupLM+U0mX1heb2qEWV5VRCmRCZa0/WjWkizRTifBxYpnMWiTwzSqZY/rnl/IMPWU ioYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=0Xs9Ha41KJfg/uQmLt73ETfWcsszCXBQ/4QUnRcLe34=; b=ihK+tng3TI0V+2dt7GCflqsUl5lYMgSBrOvhSCoKw2qBkcYNIEoi35ED9astfmLjyr 0VV2aR16/c/9NYIT7sZYxbzLYHrYvAZZwi4EKJdJUT/W2gSEG5f/J0pNLWl1NtN1OOSA cpO6alEZLxUiMMUnYWXZ0UImnR+d29g+yzlG9yrKJGBpUB0B9sfnSjDL9iv5QsXrGznp 8dD1P9m9LCz6LkirEYdnUFtXsRZUYb81GGds/41qzQdH0XPagJ2W5NfKh404T+6wVAHm tnBLsrSUVu/cJShuq3N6HGuwRYsrdHve97YF2ft54jETEjfI2z3GBzuewMLxu3+I/YQb tBFQ== ARC-Authentication-Results: i=1; mx.google.com; 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 g127si8045283pgc.428.2018.04.22.06.56.43; Sun, 22 Apr 2018 06:56:58 -0700 (PDT) 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; 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 S1753454AbeDVNzK (ORCPT + 99 others); Sun, 22 Apr 2018 09:55:10 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:44414 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753399AbeDVNzC (ORCPT ); Sun, 22 Apr 2018 09:55:02 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 15E3A904; Sun, 22 Apr 2018 13:55:00 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Heinrich Schuchardt , Bin Liu Subject: [PATCH 4.16 017/196] usb: musb: gadget: misplaced out of bounds check Date: Sun, 22 Apr 2018 15:50:37 +0200 Message-Id: <20180422135105.010906060@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135104.278511750@linuxfoundation.org> References: <20180422135104.278511750@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Heinrich Schuchardt commit af6f8529098aeb0e56a68671b450cf74e7a64fcd upstream. musb->endpoints[] has array size MUSB_C_NUM_EPS. We must check array bounds before accessing the array and not afterwards. Signed-off-by: Heinrich Schuchardt Signed-off-by: Bin Liu Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/usb/musb/musb_gadget_ep0.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) --- a/drivers/usb/musb/musb_gadget_ep0.c +++ b/drivers/usb/musb/musb_gadget_ep0.c @@ -89,15 +89,19 @@ static int service_tx_status_request( } is_in = epnum & USB_DIR_IN; - if (is_in) { - epnum &= 0x0f; + epnum &= 0x0f; + if (epnum >= MUSB_C_NUM_EPS) { + handled = -EINVAL; + break; + } + + if (is_in) ep = &musb->endpoints[epnum].ep_in; - } else { + else ep = &musb->endpoints[epnum].ep_out; - } regs = musb->endpoints[epnum].regs; - if (epnum >= MUSB_C_NUM_EPS || !ep->desc) { + if (!ep->desc) { handled = -EINVAL; break; }