Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp847626ybi; Fri, 12 Jul 2019 05:38:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqxDWWDREBkQjwce30pGP9HDFri6L1qzlpMGidTaiPuco5++tDyik1xl9DvRi7xKl+1WSbll X-Received: by 2002:a17:902:12d:: with SMTP id 42mr10689776plb.187.1562935121192; Fri, 12 Jul 2019 05:38:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562935121; cv=none; d=google.com; s=arc-20160816; b=W3l6umTFJwUyDlXlqiF1yJ+/4I6VD3xnhYiYXCAixvDo0V0JXFKwQ7ekWxr1e21g+6 DiB/PRzs9+5v9LgZe1GR27EWFN4zyWdGwIL8/45l+yzv2SML12aOVwuHx9GfhYV/qge0 i0WPDJJ/1s0UH/zcrQndZOubckPS7BizLUZ0LaG7Rec8TCcyCJWpKvZhWeksGHL+XRVO TF7+3p3yK1kyFdr37X/6704H/hKN+EWIRDBswXHqmFJVNQUIcvnP9H5zMZ9CzHH9HLuv 45V03iZ1XUmpHSxcuKppzJFMhcCNU2PsYwd+RVrJLtEdCvCSabNUDUp669f5QhGFAHPF 0CNw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=stAD3/LLHL/vBXAV42PERvdqvi+gj3htQTvpumm/Gq0=; b=XZmvQd3tG6geYR2RiGvsE5rZUQ6n9C41Ud+3YVWz7H4AQcaeQYx5dNSVO0c4NP7Kja 3FY759xi9FBN9ab5/zo92IgHisWivZsO0wqWGt/HAJ0Bjda7NUKyL9/OIFssHRG5Hm7j FguA4mD9yWUgtfoGmnazoza6AEszUQ7yvzO3KSAQRhZHL/6hQHApwCL0cbPVnR2l0SIB Sd/6rkcpY+lD2VKVE/y1nwHeApiPzlH37EGDFmfU77aPcdQSSPtvrHWj7BPMg83xS+iw xev0h2cRGXlP0bYbFDdmzkb59qcoBeLZRl+PCQ4R6rQ1dZJbK9784HeIggsR6TAcY79q 6klA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=remSjPOW; 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 x190si2074426pgd.146.2019.07.12.05.38.26; Fri, 12 Jul 2019 05:38:41 -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; dkim=pass header.i=@kernel.org header.s=default header.b=remSjPOW; 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 S1727154AbfGLMdG (ORCPT + 99 others); Fri, 12 Jul 2019 08:33:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:51848 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727633AbfGLMdD (ORCPT ); Fri, 12 Jul 2019 08:33:03 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3A1942084B; Fri, 12 Jul 2019 12:33:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562934782; bh=kkrwADmsFdGw9iAWHFHMsOpjY/8rQPkoENMN+/bHssM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=remSjPOWea30y1Fwx9ZqFJRA8B4iiGvTB9lj7vmamFW2VQEd38zFJkBWQiK9BQphP Mkim8nuTd+l7cWTSlqDalVpU8PrlM2mQJSZQj0A2w3S3DuETVnK7KinpGv6HbYnO9d kKu1zceA4nuUB7t8IcxfX7KV697zOoxCyzTKdLjY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kiruthika Varadarajan , Felipe Balbi Subject: [PATCH 5.2 29/61] usb: gadget: ether: Fix race between gether_disconnect and rx_submit Date: Fri, 12 Jul 2019 14:19:42 +0200 Message-Id: <20190712121622.182500408@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190712121620.632595223@linuxfoundation.org> References: <20190712121620.632595223@linuxfoundation.org> User-Agent: quilt/0.66 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: Kiruthika Varadarajan commit d29fcf7078bc8be2b6366cbd4418265b53c94fac upstream. On spin lock release in rx_submit, gether_disconnect get a chance to run, it makes port_usb NULL, rx_submit access NULL port USB, hence null pointer crash. Fixed by releasing the lock in rx_submit after port_usb is used. Fixes: 2b3d942c4878 ("usb ethernet gadget: split out network core") Cc: Signed-off-by: Kiruthika Varadarajan Signed-off-by: Felipe Balbi Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/u_ether.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/usb/gadget/function/u_ether.c +++ b/drivers/usb/gadget/function/u_ether.c @@ -186,11 +186,12 @@ rx_submit(struct eth_dev *dev, struct us out = dev->port_usb->out_ep; else out = NULL; - spin_unlock_irqrestore(&dev->lock, flags); if (!out) + { + spin_unlock_irqrestore(&dev->lock, flags); return -ENOTCONN; - + } /* Padding up to RX_EXTRA handles minor disagreements with host. * Normally we use the USB "terminate on short read" convention; @@ -214,6 +215,7 @@ rx_submit(struct eth_dev *dev, struct us if (dev->port_usb->is_fixed) size = max_t(size_t, size, dev->port_usb->fixed_out_len); + spin_unlock_irqrestore(&dev->lock, flags); skb = __netdev_alloc_skb(dev->net, size + NET_IP_ALIGN, gfp_flags); if (skb == NULL) {