Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp841506ybi; Fri, 12 Jul 2019 05:32:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqxl9ooWQvvwbfFR/SzHCdOfhipaJwL+hFHsPhKYwHqx01scjqXgnsMxSWhVM3VC/bqe276X X-Received: by 2002:a63:69c1:: with SMTP id e184mr10282572pgc.198.1562934770751; Fri, 12 Jul 2019 05:32:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562934770; cv=none; d=google.com; s=arc-20160816; b=VGZHDX6gyFjer1eQGuY0A6lM6mK/FAF0z4RhFsdFszTdXCLpCXVH4/rwyijcsXzyGM t+CKsx5kr0aEwHWwZLO0megeqVYrWtTVOXxgnRdRyWHtklPBP4Jciq7Brp/NBZgmff/d gHPa5BfNiQiKrg8SGTI0pjUVUAw7kGfRBH2ehIe+hCh5UkNG/T8fLSly90jCxkh15Ckb dYKocqUeC092fVL2StUU9tj/7iXSeFg52w+3ftLcQVF2o2yZ0SaQc3DDJr4SRfZdjhx1 KDRzh87K0G0bvjDSkKEY715ZRNh0ZyxPgyjB64m5iJlUXZpJFd3cxXXeh78/H2NWYXOR 03Kw== 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=sFuhcVOAg63cqlgE/5Rdoen9NESkd/22Do1SlWrWDPfmunn5w7gdf1SvFJTY5M2tSP ALRlswzWGHczkad8z76L7nUj/PTedYCYYXY6HwRHwS3V2dAu2Ltd5MBag+8MFu7SMFA7 pu6qJvmhGGEkUx0xkkNGFg+XHPwd1m27DkjvFLWfdqSo3qTFyTjb++fkchj4sRm7kMqN Gz/icHQYyjWjBHqL3gx7gmsnEjK0EmvYSdE5qE6LqiuZeg4r6oriP2UMh0utc/EbiUB7 BrzdUEnW6huqtvgPyWZMvowbs1MwZfjoIy8P5+zgKgcANcpRnoU4YX3kewp1ZrzhLcxH EmWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LFy9zsOI; 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 f1si8596820pgc.144.2019.07.12.05.32.35; Fri, 12 Jul 2019 05:32:50 -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=LFy9zsOI; 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 S1729094AbfGLMa1 (ORCPT + 99 others); Fri, 12 Jul 2019 08:30:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:46020 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729205AbfGLMaV (ORCPT ); Fri, 12 Jul 2019 08:30:21 -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 0909A208E4; Fri, 12 Jul 2019 12:30:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562934620; bh=kkrwADmsFdGw9iAWHFHMsOpjY/8rQPkoENMN+/bHssM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LFy9zsOIjPvTjZyn29ENVwcQTA8xDReIH/Tq9aKNnO/ZUvRH/i8JwrRsMerfFz5gE ooUNT0kE7KU2PKJY24QbVKrVugsUd1h5qMLsdURFfRFaYV7qLne3rxryAaUsO0ImMx 0qoKl7DM86of2/ZTc3zcwLETgKLfiasCnguyBQaM= 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.1 113/138] usb: gadget: ether: Fix race between gether_disconnect and rx_submit Date: Fri, 12 Jul 2019 14:19:37 +0200 Message-Id: <20190712121633.090388606@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190712121628.731888964@linuxfoundation.org> References: <20190712121628.731888964@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) {