Received: by 10.213.65.68 with SMTP id h4csp490110imn; Fri, 16 Mar 2018 09:18:32 -0700 (PDT) X-Google-Smtp-Source: AG47ELuxAhOrsnDqdAUhi3uLQXX2om5lrvVytSr5YFUhjevTNcyLgslXI1i6SCMNidNlM5lkSJnT X-Received: by 10.98.61.133 with SMTP id x5mr2053933pfj.181.1521217112844; Fri, 16 Mar 2018 09:18:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521217112; cv=none; d=google.com; s=arc-20160816; b=dJgJ4ZXaWzLmc67JkahBSCqnaC70f7EAfmI3rHoBG45R8gPllbJ9OuxStr6S8iz1tE M904+/l+w+T0Yoc+5Ql5NifBZU0KO+6PjYuMkhKmzCGMBxP2b4n3Chk+KqiFcJ7oQ/cJ 9styMFgYH25/SCGXYL3TGfQsZPBI6yH6RjAxlfFrOKcQ0YJHQzHVZstpjSDW4x2XmNYx hocJpgj1VzhVVNKkN/XAF9BNwvjZNuvhh3Lc+T96ye6qAm/kKSj/2r6TAd5WGeDRJ07t rQzl0UOA+3zWp1V3kJcpw2Z4UV3jFACxDZXQzrZ8kbKoTWfyzYC5tMKpAzUbEwVSkMg/ 068g== 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=no+fIsZ82Drx+o2muN/Bc7yiWhpsOrpyBGz9x3ooDso=; b=fj6h0YlY5e0ckXGXrjcYJ6gPlS+wQIoh6vj39sa7WOd16c6ema5ekcrdwX1V++tTAu z+eSqAnC13GPpEo91vKzwD2wwG+UyGTHaWC7+sQiyBVTo01bG7aS3uXJ+/hnXMLQ83i4 ZV8OrQNj9dSi+yZsaQM741lGs8PLBh7CLHSAfcxTdajPa2abWP9eml12Yqwe08QE1vOP bTabQqwQt9zu84MGT2tb6fk8AT5+JcBrI7aHxTQjeWwRwsoS8k8EdKOhPjg3ordDpnw+ O2L9M0SHkOEc2PJLd5MiaLr4ZrJOVpBKmKw2Vwkf1h8AxgfZ8/FVScPAHdbztYbtiJeu Q3ZQ== 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 s2-v6si5729082plq.674.2018.03.16.09.18.18; Fri, 16 Mar 2018 09:18:32 -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 S933529AbeCPQQX (ORCPT + 99 others); Fri, 16 Mar 2018 12:16:23 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:43322 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964936AbeCPPjh (ORCPT ); Fri, 16 Mar 2018 11:39:37 -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 1883BD34; Fri, 16 Mar 2018 15:39:36 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Shuah Khan , Krzysztof Opasiak Subject: [PATCH 4.15 016/128] usbip: vudc: fix null pointer dereference on udc->lock Date: Fri, 16 Mar 2018 16:22:37 +0100 Message-Id: <20180316152337.208011989@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180316152336.199007505@linuxfoundation.org> References: <20180316152336.199007505@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.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Colin Ian King commit df3334c223a033f562645712e832ca4cbb326bbf upstream. Currently the driver attempts to spin lock on udc->lock before a NULL pointer check is performed on udc, hence there is a potential null pointer dereference on udc->lock. Fix this by moving the null check on udc before the lock occurs. Fixes: ea6873a45a22 ("usbip: vudc: Add SysFS infrastructure for VUDC") Signed-off-by: Colin Ian King Acked-by: Shuah Khan Reviewed-by: Krzysztof Opasiak Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/usb/usbip/vudc_sysfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) --- a/drivers/usb/usbip/vudc_sysfs.c +++ b/drivers/usb/usbip/vudc_sysfs.c @@ -105,10 +105,14 @@ static ssize_t store_sockfd(struct devic if (rv != 0) return -EINVAL; + if (!udc) { + dev_err(dev, "no device"); + return -ENODEV; + } spin_lock_irqsave(&udc->lock, flags); /* Don't export what we don't have */ - if (!udc || !udc->driver || !udc->pullup) { - dev_err(dev, "no device or gadget not bound"); + if (!udc->driver || !udc->pullup) { + dev_err(dev, "gadget not bound"); ret = -ENODEV; goto unlock; }