Received: by 10.223.185.116 with SMTP id b49csp2200266wrg; Thu, 22 Feb 2018 09:40:20 -0800 (PST) X-Google-Smtp-Source: AH8x227vWU8Ih5iM4zdmBlQE1OMXBUjEGjDpnrmZJnWEHm9a7DD/RmNW3mqriqvYkTwTNp8J/5FZ X-Received: by 10.98.9.5 with SMTP id e5mr7209021pfd.189.1519321220322; Thu, 22 Feb 2018 09:40:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519321220; cv=none; d=google.com; s=arc-20160816; b=bjjWCt2a5gxxzAp2oG0zjIkMelduWCh/X29YX5JeY7Mgapd8aH5AjBVYa7D2e44q/g 7yVxS8fuEdIa4EfEnSfhcesMNKLohT7XKf8zHejl5H/PbNDxd53Q+O3ZGcepSh+0aOzY nS55xYIGIcj9SCdg/HTIOUldLHrVihFHUsG4nmn3qssx3BDFHA3v+aA8hUsTw8J4B9vy mfEdjprM/IncXkLsNtcKuxdm1cUJX4T+mso416FiUr+tc7dAJMyNyhxcyQTSj6lBi9Nt xfTpjcl0pTANGiJE4Hos7717gzOtPLP4esXaRX58ANgvzjoC2b+TIhRVPykuiR5AzN0a 3Kng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:arc-authentication-results; bh=3CG81BIdh8ktZ1lwYP5/xbtY/7dzA4am7fIvrmaYYyk=; b=ChVuAKCsgHCd1Uct+khxz9xYsb6F9rF/xav3CHDp+60T+Nd2fSQQ9c4Kf1firT3GB3 cxE76cRJiYsFLKFw++4jz8q3xW54kZ6qmvTDD4apCbpX7n7RrmLpaPsz3hxeM8b6evYJ PxaZq8Fg4VnaInoVc2zRgmHJjmPg9fSBq1Jn2KywvVGt1XGZ7QpYy+G5kKr1PkknH5cB nonTJZ9/H99kyCOruY54VqrB05ZhNkx+kGFfoNg5B8orDDPclxksVoxBqF/rwZgTomJl bLrvMeJOHLUiT8m8O+xvc/OG3syqnkfJl33IhMG1r5bcbhwtNpCF+El8hjHC8aMKjub+ EkvQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m24si329492pfi.66.2018.02.22.09.40.05; Thu, 22 Feb 2018 09:40:20 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933526AbeBVRjX (ORCPT + 99 others); Thu, 22 Feb 2018 12:39:23 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:54728 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933378AbeBVRjT (ORCPT ); Thu, 22 Feb 2018 12:39:19 -0500 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1eoupx-0002o7-GB; Thu, 22 Feb 2018 17:39:17 +0000 From: Colin King To: Shuah Khan , Greg Kroah-Hartman , linux-usb@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] usbip: vudc: fix null pointer dereference on udc->lock Date: Thu, 22 Feb 2018 17:39:17 +0000 Message-Id: <20180222173917.10841-1-colin.king@canonical.com> X-Mailer: git-send-email 2.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King 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 --- drivers/usb/usbip/vudc_sysfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/usb/usbip/vudc_sysfs.c b/drivers/usb/usbip/vudc_sysfs.c index d86f72bbbb91..6dcd3ff655c3 100644 --- a/drivers/usb/usbip/vudc_sysfs.c +++ b/drivers/usb/usbip/vudc_sysfs.c @@ -105,10 +105,14 @@ static ssize_t usbip_sockfd_store(struct device *dev, struct device_attribute *a 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; } -- 2.15.1