Received: by 10.223.185.116 with SMTP id b49csp825303wrg; Sat, 10 Feb 2018 21:17:27 -0800 (PST) X-Google-Smtp-Source: AH8x224wy8u5uL5Hd15V6k9k3yABTnnH9E8LFnUkbsFwM1Y78wIjvBdTQ6koqnGcpKgzZggcztj2 X-Received: by 2002:a17:902:8544:: with SMTP id d4-v6mr7430623plo.312.1518326247240; Sat, 10 Feb 2018 21:17:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518326247; cv=none; d=google.com; s=arc-20160816; b=DSeqFd6EqcNomsbl35m2dGyU5wrlfDX0JZqfLkkxrwLFomOy9O+U7/4uvLGjKptuzL mfaxluzGW//cTdWXF0Zdq+xoXAix2h4l9usqGaO2ZkkZtBSsoMZHBVDya2c9kgek9Th2 pKDZNvozMPhYyKzKReX1IWkIKxDImnvGZ/v/qxCEyzodGdyVbTLoIRiRgWVGvPhR8QXQ qOrM8v7ili80IVA1BJOR1ji0joqYWR+x0cAOdNHcW7yfjUlgr3pooIcEtLOBh3HcLz86 8nG5sRnmBJLsq7kTGibGZVJlq+62iws0iAGlpNKgiUgjd6esEwIcvfW1yT4VmdRN/MlL 3cVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=IYeSva/+cPvuuaL6NMT0G8neVjLxItLu5reN/e0Lrxk=; b=w+kYmDAZdZcPdwfSwG/PeCsB03vB8SYHoiZLHBw+F/HalHvYFn7Goud5lMAQAIO+l+ UNFwPkPotqA/JDoPUGZcDZJ9/JAB3Op+LRQpmUU/t68us3M4Hh6xSWwlmM9OaetlY+XW vpEmpQUJnvoZpYo6oqFGSFGc7Tx7jvnjXkIC8cApBkCXAhzmngn3WQE7ADfzFCeulFm+ Een3+DliVRo3CYcFkCWyyLts9ek/qOe5oBtukGZgtz0NgxWJg9nIHOnqwKLXdAU9tMvn gl4Wiqs4qaaBi8ibmdP/6DANofyZa+SYXe7V1MbdUqVYk4hVCj19QfSG4mP6+dBmdOZo gY/Q== 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 23si4332348pfs.322.2018.02.10.21.17.13; Sat, 10 Feb 2018 21:17:27 -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; 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 S1753892AbeBKFOT (ORCPT + 99 others); Sun, 11 Feb 2018 00:14:19 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41387 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752618AbeBKEdl (ORCPT ); Sat, 10 Feb 2018 23:33:41 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ekjKd-0002hH-0V; Sun, 11 Feb 2018 04:33:39 +0000 Received: from ben by deadeye with local (Exim 4.90) (envelope-from ) id 1ekjKY-0004XJ-UB; Sun, 11 Feb 2018 04:33:34 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Secunia Research" , "Greg Kroah-Hartman" , "Shuah Khan" Date: Sun, 11 Feb 2018 04:20:06 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.2 73/79] usbip: fix stub_rx: get_pipe() to validate endpoint number In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.2.99-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Shuah Khan commit 635f545a7e8be7596b9b2b6a43cab6bbd5a88e43 upstream. get_pipe() routine doesn't validate the input endpoint number and uses to reference ep_in and ep_out arrays. Invalid endpoint number can trigger BUG(). Range check the epnum and returning error instead of calling BUG(). Change caller stub_recv_cmd_submit() to handle the get_pipe() error return. Reported-by: Secunia Research Signed-off-by: Shuah Khan Signed-off-by: Greg Kroah-Hartman [bwh: Backported to 3.2: adjust filename, context] Signed-off-by: Ben Hutchings --- drivers/staging/usbip/stub_rx.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) --- a/drivers/staging/usbip/stub_rx.c +++ b/drivers/staging/usbip/stub_rx.c @@ -356,15 +356,15 @@ static int get_pipe(struct stub_device * struct usb_host_endpoint *ep; struct usb_endpoint_descriptor *epd = NULL; + if (epnum < 0 || epnum > 15) + goto err_ret; + if (dir == USBIP_DIR_IN) ep = udev->ep_in[epnum & 0x7f]; else ep = udev->ep_out[epnum & 0x7f]; - if (!ep) { - dev_err(&sdev->interface->dev, "no such endpoint?, %d\n", - epnum); - BUG(); - } + if (!ep) + goto err_ret; epd = &ep->desc; if (usb_endpoint_xfer_control(epd)) { @@ -395,9 +395,10 @@ static int get_pipe(struct stub_device * return usb_rcvisocpipe(udev, epnum); } +err_ret: /* NOT REACHED */ - dev_err(&sdev->interface->dev, "get pipe, epnum %d\n", epnum); - return 0; + dev_err(&sdev->interface->dev, "get pipe() invalid epnum %d\n", epnum); + return -1; } static void masking_bogus_flags(struct urb *urb) @@ -463,6 +464,9 @@ static void stub_recv_cmd_submit(struct struct usb_device *udev = sdev->udev; int pipe = get_pipe(sdev, pdu->base.ep, pdu->base.direction); + if (pipe == -1) + return; + priv = stub_priv_alloc(sdev, pdu); if (!priv) return;