Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2129196iof; Tue, 7 Jun 2022 20:42:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDtN97JedgTYEl5O7+wcqFEMCtMVBMeujbRIJieJO5d7T27vO/0J7bE7bmHJu0Jfvd4RSk X-Received: by 2002:a05:6a00:1741:b0:51b:ca1a:8563 with SMTP id j1-20020a056a00174100b0051bca1a8563mr30351669pfc.58.1654659776516; Tue, 07 Jun 2022 20:42:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654659776; cv=none; d=google.com; s=arc-20160816; b=KNEU9tmz/tykxeOeNiecIgOBb2V0+xdlsM/o55WEkiJ2ecEVoy7g4dQIiOP7UEJYsl 1GtHqA9Zdn4TVnirSvOAtb3PQpoD0wIOtjaqJPvcsXmCf7uCYoAAn0hl5eQ7kvnfpm9V lOPUda4ORE8E5VWKjBwdiIekD8mGL2KHvHxwRamxXZsISKwp1IElcfHXmEMeLDgGH755 iST7d8f+eTeYUKn6hfUPX19+idI8YnBRJaHCj2rNxYaM36SxvfPK/2lnQgyzK0Nsr+Pp hKUxGpbPZ3KbvRZndX8V2sDuzZtcKQFpU+xnMz/KMrLWhWRYrbSYbaynhppnCBiZ6pXZ 7DPw== 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=NRh+zJeU/MJ0Z/bAHjdsj6+1O9OVbJ0crHhjNccu9qU=; b=r67aQzj6ws57Apyidqu8xBqTMPvUU934MIOgAbWn47juI/7ORErJWksRvgvs+uQ4ox XHkMj2WiH+4QHqqVQSdTBVRMjpW9S4fgM0pItM4Hjvw4eTa7SRbddDOXnFmvxZk+HHkm DDTgQunQGW2wWd202HDARHSTDw8k/R7S90jd9CRtFWuR625WBlTwnij29Tlbmu3eSe2e jidaBgm3tWBWI/4SyLy6JuvFUOMM02b5OrYmrjmDYalvSCn6NlUvTLnM6hcHHspCkYka t+vFMfIGUrvVkebEZJmeEE8MKkevWpSADqCSroc6PMgFxQaBuvpSD8rQVw/Z1jn1FQHs d0JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qMVUHs+z; 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 l14-20020a170902f68e00b0016645f83ef1si23597513plg.213.2022.06.07.20.42.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 20:42:56 -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=qMVUHs+z; 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 A6C43392A05; Tue, 7 Jun 2022 20:08:52 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347687AbiFGWCP (ORCPT + 99 others); Tue, 7 Jun 2022 18:02:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379064AbiFGVCA (ORCPT ); Tue, 7 Jun 2022 17:02:00 -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 63E6F11AFF1; Tue, 7 Jun 2022 11:46:20 -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 EF7C96160D; Tue, 7 Jun 2022 18:46:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09978C385A5; Tue, 7 Jun 2022 18:46:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654627579; bh=ISjmmFkAO+VM1yqXdbRb0UZ0YuSh7g7+PxFHZvOoPMk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qMVUHs+zLhCOm/1R3QDBlz66fV3F6KxfkJok0uranU57mPp8C36kne3AmvWmULAnz /S8lYJizsv5EY+WTUYxhgKkhI8nzqdcET/KpqCiBcVTf9aNYD7dYMKffYssElAhmbb L5XEn3WF9nF0A2R4lC9ZOwDlLPh3BtF/GdB/BAHc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable , Albert Wang Subject: [PATCH 5.18 019/879] usb: dwc3: gadget: Move null pinter check to proper place Date: Tue, 7 Jun 2022 18:52:17 +0200 Message-Id: <20220607165003.228890970@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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 @@ -3380,14 +3380,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))