Received: by 10.213.65.68 with SMTP id h4csp510957imn; Fri, 16 Mar 2018 09:59:20 -0700 (PDT) X-Google-Smtp-Source: AG47ELtaffDQ2qkmqfimBVEGQ94b32+DpaQhkNa9XkdkyGrl6AddabKYXpWUkqgh5JsMRXHT9MSh X-Received: by 10.98.38.133 with SMTP id m127mr2164209pfm.122.1521219560523; Fri, 16 Mar 2018 09:59:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521219560; cv=none; d=google.com; s=arc-20160816; b=MDgwfRISdmEJqb5ZzoJOW6Tq/SSEQY3dUEusTXGCET65Cr//mg9g7Y0JreM6Y6P5MB NjZBo528CK9o476WGOVngPKFIuKvPmEesdOrjjcMY2lvw3ZebxVwStOqKLismEb29cHu tEGBZoY62qW4yWn9MaprOdS/5a0xinJ/GD+ESuhPB0sEa/ac0Lm3O8Rhonmd3ouluMXi mMCQhJfCt8TtzeJYLVxXZQhOy+7Ssu9ppKNK55IvRTDDhSmPhObQd/MsurhDV+54gEVL W4jo1jwTHz9gggFd+UWHHBDUFhjN/X/X5oY7Qng8SjyiulMXK93GOfurwAQXl64nbCvO 15zQ== 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=4VQe5BJdvEl88oQ7OPDy65gZ6IOGVUy/KWgdzeYYW3Q=; b=NZqc3Mt/nPD3WlfSV96hBtVilmb7GM8OgtUqp7sbNyaYIygPkqISio/E62ngY86Agz DR755UDL6iEAQ+pu6i9C+TDGVF3mKL3lYa4MQRxcE4l3MG//f6U7C4QQ+D6SVokRRJKY pOAoSuRyKfkxbI1Z4kAcj0cPqxhLieCQbUnvcaeBL2ehivVOUEjA0gtD7vKLkMqC9Dhd EyPJH60ORfE9qSbP2m1y00bjVWWQ67fbp9d3OeX0UaRv7ZDwhSTTFfgodEJkugMMzKcG 61c+CRZHyB+UJlq5zGvCejhnY8HG+OPac0SdV48WfzRM4IinItcvrC2lJjCdRMZuW1IM Bi5g== 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 u2-v6si6460580plm.476.2018.03.16.09.59.06; Fri, 16 Mar 2018 09:59:20 -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 S932689AbeCPQ57 (ORCPT + 99 others); Fri, 16 Mar 2018 12:57:59 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:38390 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933403AbeCPPdU (ORCPT ); Fri, 16 Mar 2018 11:33:20 -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 306F01252; Fri, 16 Mar 2018 15:33:20 +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.9 79/86] usbip: vudc: fix null pointer dereference on udc->lock Date: Fri, 16 Mar 2018 16:23:42 +0100 Message-Id: <20180316152322.671262250@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180316152317.167709497@linuxfoundation.org> References: <20180316152317.167709497@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: 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 @@ -117,10 +117,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; }