Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp833172ybi; Fri, 12 Jul 2019 05:24:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqwJ9DanzdjYia3mDZYXHip3pnCMwlgIDGugLMWwmAI84u+5MmxS1VnSuJETOxZ8Ky1omrmd X-Received: by 2002:a17:90a:f491:: with SMTP id bx17mr11748737pjb.118.1562934282117; Fri, 12 Jul 2019 05:24:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562934282; cv=none; d=google.com; s=arc-20160816; b=KhCT6fVnbLP8R+jHdETg+tf2+6BQxcWWKbJpFuADhFdAfZw+0EucoTsh8zLRHPcTr5 /NlKbC7IVnAwzhwPWfTGyg2zlWDlKejmvTV3avkx7z2E30pL8hUVk4Q/oAcPY+93DF2D XkidTwdtnKorzfOEzSrMhnlo4crwSrxyPu8vdDawpSiQ0o7owXOPR/UMnQHrcDKUUBNO OFRcawEQiSg7CoLlqxjPYwfmkmejJ0zej0dBWdP2AzWNwilRTyq3I7/4lJlgDPgeeDa1 wnJK9jM4vBbIH6Q705qhpaWhpHzAwOQOnlXpJHyC9/Yi+n55n3Cvd+3PmxddhXUphIbb KwdQ== 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=cGwaRbbdUgJIECHfGLJdBk+tPXR+qv4kN2gwgTAsEgrDRdSPFZwtobM3Y5s6eNMftS pqxS9CIZtzTpKqKsh5vosV8ae2V9qYDC6RsN4IAE0bkcDhZ0vg+e09YLkHN5TECDzh6T UEag8SPv+9Dvko0ssarGKxwIFm4rVbG4Y/ioxWkhOThSQuU4PBvU1DlrXn5s8fOTayS3 zlfjpKPYzjIkTF213tcf/9UENqCZpJ5h5PgiIW07cNamcCizVewJuh+g1h3COGm5f1Zq bYaugVO7LJ3qKyntGDZ0VhmMRyGh4iMjnEjfxAmwjNJcrmX/2h8j40wOr6puwl2GsaDc /iuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RZTHOCgT; 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 91si7781961plc.54.2019.07.12.05.24.27; Fri, 12 Jul 2019 05:24:42 -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=RZTHOCgT; 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 S1727569AbfGLMXi (ORCPT + 99 others); Fri, 12 Jul 2019 08:23:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:59394 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727964AbfGLMXf (ORCPT ); Fri, 12 Jul 2019 08:23:35 -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 65031208E4; Fri, 12 Jul 2019 12:23:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562934214; bh=kkrwADmsFdGw9iAWHFHMsOpjY/8rQPkoENMN+/bHssM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RZTHOCgTkNaUjtg6FpfyOP+VWlXPOOhmWohgvyNrvNprWd9UkJrygMEKstKm2QVk1 4/l1nHQq1YdfJpR5Fex0UJ3GOVFAObwjRXDO01FaZinV5GDlbyPxwGI01V3xaEpKpF 1oEtqWsAPIwC55MRmrc33Uw5PcLv+hYV1EStF11A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kiruthika Varadarajan , Felipe Balbi Subject: [PATCH 4.19 73/91] usb: gadget: ether: Fix race between gether_disconnect and rx_submit Date: Fri, 12 Jul 2019 14:19:16 +0200 Message-Id: <20190712121625.737094366@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190712121621.422224300@linuxfoundation.org> References: <20190712121621.422224300@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) {