Received: by 10.192.165.148 with SMTP id m20csp2473365imm; Sun, 22 Apr 2018 07:46:56 -0700 (PDT) X-Google-Smtp-Source: AIpwx486SvnRcFEaMxCazeKCs/63KMkwSkb0fjmo3nolGh+LOCO+HprhM6pUyHY7Qmjcp8mSjoZx X-Received: by 2002:a17:902:6909:: with SMTP id j9-v6mr17623177plk.313.1524408416275; Sun, 22 Apr 2018 07:46:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524408416; cv=none; d=google.com; s=arc-20160816; b=pkWLReHsfQm/9Fa7mZHE01h/dXjCQRkM/F4al8NZbh4PQcoRa/VCSHahEsJVkDIgrg e4DHvgewW0yBY2Aoz1pId83J7r1a/J5H2sQSvqiuVfR8VCKYct703rwwgZYsH37PqQvs 8guOsuxVZdHUQbC47hH3JYOXZJjlqu5BWHkwrlOnMcs9WpZ/Hz4/AOTv0aGW/xkpSqcf aO/X9crCKTh5O8hOX/Ky854D1cI5aDopRhxUe25rBGm3ktodszmdEcPSXhVeK053ukh+ H/XQmD3Y9KPcJJP50oTt6BNTS7Y3qX+8WQ89lpTpxYF5M1d1OvJ30UtU+JepMdP90JVc I6YA== 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=ly1JhrHYjsVngXpFKHhS3ITgFAnfaes7QKuFXp4eMnE=; b=nMDA7Yjpwan6UhEOQmcvWP75ALutw3nNrMFgrCeKs3C1yDFqSDJSgL3KD3VPiI9uYt JDHkT/a7oRCSE1SL8CveZJo2Bh1CY8apJcpUAj6U2TMC5DJW+AFtjm6peEeEsmWXY+PU e2s2jB56RIb6RsbebcoYQ72ZKsVMg+PWHdOTmPs5C8uKl+x7+c0ASYumipsaNrpguxpB X/Yc5buOWRKTyKwU06fs8v0MJuemE5WZbov+rpHed92Hloy+zAxOeJTsA0/9rQY7btKZ pHqrBCjV+8wW7K8OcNrLI7/S6LT5y3ng31qVsgwG2DArWbusbeJjUB61njs9UEH22x50 v8/g== 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 n81si9420759pfj.152.2018.04.22.07.46.42; Sun, 22 Apr 2018 07:46:56 -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 S932325AbeDVOQr (ORCPT + 99 others); Sun, 22 Apr 2018 10:16:47 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:57544 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932105AbeDVOQb (ORCPT ); Sun, 22 Apr 2018 10:16:31 -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 7F18EBA0; Sun, 22 Apr 2018 14:16:30 +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.4 30/97] usb: musb: gadget: misplaced out of bounds check Date: Sun, 22 Apr 2018 15:53:08 +0200 Message-Id: <20180422135306.960817026@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135304.577223025@linuxfoundation.org> References: <20180422135304.577223025@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.4-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 @@ -114,15 +114,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; }