Received: by 10.192.165.148 with SMTP id m20csp2444473imm; Sun, 22 Apr 2018 07:12:43 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/Gw9BMC9qP9MOGP5wfqhO1Pu6zwq14cG7SBujY5YGafvbIDt2YBx3Ly7onzrLJYb+4fxd6 X-Received: by 10.101.82.70 with SMTP id q6mr5641216pgp.45.1524406362938; Sun, 22 Apr 2018 07:12:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524406362; cv=none; d=google.com; s=arc-20160816; b=XnF88mEwsAPF6kYrNTKAFQz95P8OsqJ0A+H1GsPaGy/Snsm3NhVMGoOA9bFNDmpVK6 775bVZ/xj28GSi4SUrxAHr4pZQUsF813HIDflOcLsthY+WVMx5XxhkJDh4CYD3v40TYX 4T1MvlVonRyuGVU3DVdyGilv8JZ2H8vL0e4A3pIphSeRRap517kCpTXRJw6nqfFTQ0K0 17w8pZJ3n+E5BFSrI7g/A32DohVCqh05u5s1CFcJExcahVVOYs1hNWtrL328wMXHTSul uovLMIAuyUF9BmB/J8tOUuYbrex1kE3nFab4rtqCvrYas92vjNjf1zpyQ+5/h5Cu1G7z URmg== 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=NtIifyQv6KPb/3aRrNRoHYWVhpmVCXdyanE/dQXjL8E=; b=Tl1f2/wnVq7pdgz6IfvAtvuFfpLM3fdjEyIRjFkfRlIR6vpXVRf9VnqXxGEO+iT5kL Ocq4uQ7B/oK7moWGwIAviOxW+DZtRb3VYKj2gP7xBfMPzX9woqNsM57hP9R4CaeWFJe7 Td8M9Tp3VlWjXg5Cbye0JbErgbzI01avDaQ/gk9sQ0xjITHIP+aONOO4VkLHtmDWZW4o c8EqolGB3Ewm5IyDA6ldQhc1iZGaiJW/UWQUjuD03mY/TD7TfDWsybNp+gO/Ht6ouu+a x3irgVUvgESB5hk1WkalDXTW+xFTRp1c0ejs5qNwmPbnoYqXszPq8di1KtH1sfpXtEG7 NrQg== 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 u9si9550917pfa.293.2018.04.22.07.12.28; Sun, 22 Apr 2018 07:12:42 -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 S1756460AbeDVOLR (ORCPT + 99 others); Sun, 22 Apr 2018 10:11:17 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:54212 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756019AbeDVOLK (ORCPT ); Sun, 22 Apr 2018 10:11:10 -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 23937CAF; Sun, 22 Apr 2018 14:11:09 +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.9 10/95] usb: musb: gadget: misplaced out of bounds check Date: Sun, 22 Apr 2018 15:52:39 +0200 Message-Id: <20180422135210.847117081@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135210.432103639@linuxfoundation.org> References: <20180422135210.432103639@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.9-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; }