Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1147309iob; Wed, 4 May 2022 15:57:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJSXohF25Tsk2r7hfug5NpXPwgZgyIlm1esiS+pfsBQYi06awRR0quqr0GQGURUXJ98ZoK X-Received: by 2002:a17:907:2cc5:b0:6f3:9121:5172 with SMTP id hg5-20020a1709072cc500b006f391215172mr23198771ejc.366.1651705020265; Wed, 04 May 2022 15:57:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651705020; cv=none; d=google.com; s=arc-20160816; b=r57UKq1eBqPvbkoFOAjrfqKjnkB9l0wSAN9AVuc7pPh1xkjs8fg7k8lweIJmlfn9oI 00+RlGughMEfozcJbJZXB+ajb6e1ucX5xiyE7e5rOTJmCBJKdeiwZuGqr8nbt9MpHf9/ tmxTmWV3h77SMlDo400B/l6Onk8pea7I3fUHG/JvkZmZ7BCA/VL9KjorwajaFRah18dS Zad1tjoBRkyBIvcoLdPX79tAhKwGXNt1IJUrzqofw2meHKpfCWoqVOKNGA0/up4YiH1C CKFSaPOEs75NX60A3/0oSSxZXKt088PXwdzRwwW2KyU1NnMNPlOKQifKKND2PsOiLhqe l6jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=86Ixel75CqJ8WkTduz0yCW0fBLn5b8p2jNFTMzTj22g=; b=1KIouaePEClUmEzlOKfES736CgC8sEytxoirBDr4Y7yyW54Dy+2qS/zlVM+zlpIQqb 1LyWMzMYjXiDSD1bTN/zeDmzM2kcc+1AF9NRHUO+gA9uMrXqse0X06Oa0QPlQSf1jZfc JThfT1/In+s32/e36Qr1OpRurdJ7w78SLc6uxAvKyHGF0ZpsNpBH3ExO8ps0qSzBcSir 7eJaBx7X516nxuJI3NkEu5pvub36OSMXqbXzJo06tzuyt1ZXmmgGuqc5rRvOb2zhwRqr KZMZ9cZQHuJ8/Z68RdsmrgJLXpZ0zAR3asA+n2v+rd12DOqQA8TL/0AQtJAfq5yl7O5T uy0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PZCJuy2G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y20-20020a50ce14000000b0041d70951197si16801119edi.530.2022.05.04.15.56.36; Wed, 04 May 2022 15:57:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PZCJuy2G; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351406AbiEDOjS (ORCPT + 99 others); Wed, 4 May 2022 10:39:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351400AbiEDOi4 (ORCPT ); Wed, 4 May 2022 10:38:56 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 480E0C3B; Wed, 4 May 2022 07:35:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 08FA6B825A5; Wed, 4 May 2022 14:35:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 743CFC385A5; Wed, 4 May 2022 14:35:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651674916; bh=FpqXWG4km/rO5KQV/khRTb/6jDcIdGQHP3TKMQAPa9s=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PZCJuy2GW/102BzQOqCgO3IixzxWNvXpJJGLfg9nFyS2sNSsZmVQfe7d45j/GAPEi aW4cZ5ZHVBvej2D5MKS6V1voGaM+qmzi7Kn44FMWS2BXjkGayVfYXu+/LlNKvf9n7h Yp/wmzw4l/GvpGH0n3J6HxB10RzYq8X+MZiMmnpA= Date: Wed, 4 May 2022 16:35:15 +0200 From: Greg KH To: Albert Wang Cc: balbi@kernel.org, quic_jackp@quicinc.com, badhri@google.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] usb: dwc3: gadget: Fix null pointer dereference Message-ID: References: <20220504072802.83487-1-albertccwang@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220504072802.83487-1-albertccwang@google.com> X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 04, 2022 at 03:28:02PM +0800, Albert Wang wrote: > There are still race conditions to hit the null pointer deference > with my previous commit. So I re-write the code to dereference the > pointer right after checking it is not null. What race conditions? And just moving it is not going to solve a race condition, you need a lock. > > Fixes: 26288448120b ("usb: dwc3: gadget: Fix null pointer exception") > > Signed-off-by: Albert Wang > --- > drivers/usb/dwc3/gadget.c | 7 +++---- > 1 file changed, 3 insertions(+), 4 deletions(-) > > diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c > index 19477f4bbf54..f2792968afd9 100644 > --- a/drivers/usb/dwc3/gadget.c > +++ b/drivers/usb/dwc3/gadget.c > @@ -3366,15 +3366,14 @@ static bool dwc3_gadget_endpoint_trbs_complete(struct dwc3_ep *dep, > struct dwc3 *dwc = dep->dwc; > bool no_started_trb = true; > > - if (!dep->endpoint.desc) > - return no_started_trb; > - > dwc3_gadget_ep_cleanup_completed_requests(dep, event, status); > > if (dep->flags & DWC3_EP_END_TRANSFER_PENDING) > goto out; > > - if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && > + if (!dep->endpoint.desc) > + return no_started_trb; > + else if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && There is no locking here, so why would this change do anything but reduce the window? thanks, greg k-h