Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2156648iof; Tue, 7 Jun 2022 21:39:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwk1bO+swCHd/o1epdCXSKbBZMwmpPTfpwNEvoXRRwqWmLOPPaZbIAlm7Vig4aVbnX5Y3Ue X-Received: by 2002:a17:902:b18e:b0:15f:b2c:6ca with SMTP id s14-20020a170902b18e00b0015f0b2c06camr32164745plr.84.1654663154526; Tue, 07 Jun 2022 21:39:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654663154; cv=none; d=google.com; s=arc-20160816; b=IpOBssL7zlCj+WTIZRdKHzBg71g6V8CAhXHqRVXu6NzP3TTj1N/9Er0tH/10391RDG BDseUC2251aJQWT8rvcTArEoGpIAUmakEvv0+N27iiwWLx0RHRTWr/6uS0ejmWxG2Xy9 10E9TAOXt0dKwYicYb29YpGgKkPyZAYnjxfZeqSo0c4DwXJPcCqMuZiMo6LywW2+Ys+E 3GbWsvVcer8bXqV3Nih3ugOE+B0AT4W2ZPVD9KKTjvmLh9/V6QazppXCTm5JsrvIjNZB KTm2vZDBdP1ypf1WcvtpQmysbase0OprGlVzIW66KT+tQb6b8KTYhx659V8emZaEXkwo rGnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6bCYEjgkIxDtIUU4Ti3pY7DOGTHxA6ESZhjspUcaI+4=; b=WaeTGx+e4ZWyj7pdZtS4AZYBhImxMbHfMq+vyxZWxquWTWuc+WipZh/XD6ecMhvteI Av1odD5PdxMgC0inV5TEpH6DwYlXZMSpPwe6aCeahlFxoGVfcXisPPMrT5EAKFQC9m0F DXIUbQGewZPBJ9oUlih63CeIW6dTa8q/WSW51gaZtxFN7+H+H1AJ6pnp9vzYOhD7YEqH kLigkTrCNk+fkwTVIXD4R6/vn5TCmZWoYw0LDEqdsxfP+tM5dvEQhNrp77ehjq0nmxnD rG7xkp7RM+gEVDP8YDpi4DKitm96IacWMXvPO5go6fcrNfmsja2aKw7fkBewe2xzFmNU qxXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=y755U4w0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id k186-20020a6384c3000000b003fce072f541si21989545pgd.333.2022.06.07.21.39.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:39:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=y755U4w0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BA5B529ADD7; Tue, 7 Jun 2022 21:07:36 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345541AbiFGRSc (ORCPT + 99 others); Tue, 7 Jun 2022 13:18:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345517AbiFGRSW (ORCPT ); Tue, 7 Jun 2022 13:18:22 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45473104C96; Tue, 7 Jun 2022 10:18:21 -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 dfw.source.kernel.org (Postfix) with ESMTPS id D68B0618CF; Tue, 7 Jun 2022 17:18:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E44F0C34115; Tue, 7 Jun 2022 17:18:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654622300; bh=quySYJtomJ+ruxzvdbbgP8BcCD9LVEd0iWQJMe7v50s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y755U4w0ekXmuxuiWgXTRZNrCxnJ9X1i8CeBX9hwKYhbVhVsbIZXI+H/8lDhppveo ib5olTDb11dgfKsxk9Ha+hqAE/nF7d07qK3bT+2AsrF3ZPLwPUAH6W6gku9wlPOmUq Lma93u7KJV3n85ll+XAFwAYrAblhyRb8Y5sKAekA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable , Albert Wang Subject: [PATCH 5.10 011/452] usb: dwc3: gadget: Move null pinter check to proper place Date: Tue, 7 Jun 2022 18:57:48 +0200 Message-Id: <20220607164908.873134406@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607164908.521895282@linuxfoundation.org> References: <20220607164908.521895282@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Albert Wang commit 3c5880745b4439ac64eccdb040e37fc1cc4c5406 upstream. When dwc3_gadget_ep_cleanup_completed_requests() called to dwc3_gadget_giveback() where the dwc3 lock is released, other thread is able to execute. In this situation, usb_ep_disable() gets the chance to clear endpoint descriptor pointer which leds to the null pointer dereference problem. So needs to move the null pointer check to a proper place. Example call stack: Thread#1: dwc3_thread_interrupt() spin_lock -> dwc3_process_event_buf() -> dwc3_process_event_entry() -> dwc3_endpoint_interrupt() -> dwc3_gadget_endpoint_trbs_complete() -> dwc3_gadget_ep_cleanup_completed_requests() ... -> dwc3_giveback() spin_unlock Thread#2 executes Thread#2: configfs_composite_disconnect() -> __composite_disconnect() -> ffs_func_disable() -> ffs_func_set_alt() -> ffs_func_eps_disable() -> usb_ep_disable() wait for dwc3 spin_lock Thread#1 released lock clear endpoint.desc Fixes: 26288448120b ("usb: dwc3: gadget: Fix null pointer exception") Cc: stable Signed-off-by: Albert Wang Link: https://lore.kernel.org/r/20220518061315.3359198-1-albertccwang@google.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/gadget.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2960,14 +2960,14 @@ static bool dwc3_gadget_endpoint_trbs_co 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 (!dep->endpoint.desc) + return no_started_trb; + if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && list_empty(&dep->started_list) && (list_empty(&dep->pending_list) || status == -EXDEV))