Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4069870iob; Tue, 17 May 2022 13:13:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYCVK2+EBvlTrMneiXXOGvqieR9ivcXR90VBUFjzcu7Vr7uIir8Q///f4bU7EQOtyhORKc X-Received: by 2002:a17:903:240c:b0:153:c8df:7207 with SMTP id e12-20020a170903240c00b00153c8df7207mr23587722plo.44.1652818419959; Tue, 17 May 2022 13:13:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652818419; cv=none; d=google.com; s=arc-20160816; b=Pe6sFmVkrNNo7YnrFDngCi7YPzmNz4dVx4cH99nWfXg9/LUw74O+AeQfskRiV5ELLe sG2r/nlStid65+/CtMLAUX5fe2iQrIbV1pTPUH1OrAfej56tlxQzYrmnTkAOau3m8SiA Gm6Y/uN3RKK+rSJwAE7DseeCzzQfCHQ4w7FQjbgk/4PAXP2A9sgpeCqRik/7POHA8XTv zVNK8jOTfaJxnHiMD9kEhbgt1iem2lSDcgfrgeLLC0i7mQcCt31YekvVLvTGAHdDa+fw gH1/3YXwInMtTuKa1sr6hK3FttHmcqiluNy7SXU4IjNC4muYcaPOC2PwV2weNvz5T4gk PQBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=Nst/okWzt+1Pt7btm5FYdNUScd4Lw2KRfwoUVrWaXsw=; b=JmPB8nnr8VzaJmLgiyi5qbBf3oxF1msRUBdAKgFFVXQSMicBH/eNgX8gTJfxz7utjC nLlTFyozoJ3FGsxla5Erdt+ja2VX50PXrzm6pUvP4JwCLIZSFwZqnc1KtdqfhD+PNyXH /3mBrwVEbGl81VQksvFYG7iVR0co/xPAWLimxcmhvsq7DenM04FKNm7cfHfT2hguB7qn Ynd+39LKS99cQGBDiViW65xhf2319JUDE40qrRTVYLaeqHyBPVoQujK7PM2/LMS4Qirc ilqZqL5kFNaa5YZPvtg945hwFhW9rbuXuht6DcGL2wKZ4Qxt6CvHEu64KjiiaXql4gws HQ4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="NUjqy/+b"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s17-20020a17090302d100b0015d281d00a5si17849583plk.599.2022.05.17.13.13.25; Tue, 17 May 2022 13:13:39 -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=@google.com header.s=20210112 header.b="NUjqy/+b"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350923AbiEQQdi (ORCPT + 99 others); Tue, 17 May 2022 12:33:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350912AbiEQQdh (ORCPT ); Tue, 17 May 2022 12:33:37 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9A1D4E395 for ; Tue, 17 May 2022 09:33:36 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id d188-20020a25cdc5000000b00648429e5ab9so16256208ybf.13 for ; Tue, 17 May 2022 09:33:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=Nst/okWzt+1Pt7btm5FYdNUScd4Lw2KRfwoUVrWaXsw=; b=NUjqy/+bSbXrnYySDW8oHLK7ZvYo8UxSan1NjQOA0bI65RPnMb9WnR8tImW6L88OHi V36uWEmPNdeRafPTRd9eC+JpOr60TfgZdy3f6mTSXAZp8MyQxR1Twg85xE1SWCE/MC75 Fg80X4tCgEOggsX6AKjdLhvX4UPF0MEKnfv02sHr60SQ9QCLpZEfTTLp3dlkexRmhzy+ tCwSZJNpk++N6G+lwt4t+097KiDUTySpn9hD/KkoEITW2KP9SMs3jHNCnLEUypJRX14J fcOf5HP9xcwDUhK5vMIbCeS6kGgCZKbthNoXMuwmGql1IZN+Nwv9UfWZ1EpL2cAYGk6s UGjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=Nst/okWzt+1Pt7btm5FYdNUScd4Lw2KRfwoUVrWaXsw=; b=h8CofjfDaTfoM1fZgxe4V5XSmN3n7BNZEJhBNgkHVwZ8+NfpfIZU1JsHYJaoY13rMt lL0T1RtAsYKUEyHqca91avyG9Y74qBlGVrqeKnHEsnS4m6dpLJmpchl+4VKsUi8xcA3i zJ5JzHksJXykfO8gBIBMxncUGXCKSnJZQXvbtrA2mufGIZysIp0HhOVEYoSRXe/nGrRB ikJP8liNBp2Wixfnl9MAVj3SG/0NfRGuqq8El4nB1WQL30qVf8SNeNZiYxuD5FvPPyfs 3MwAvFlRCGEyUA6DOrQ36WtllfkUyXK2mDD1abaF5ZftJje5nX5x+KgmePwm4Di+o0AP Wy4g== X-Gm-Message-State: AOAM5304KfvgYpx4GQNVa5baF6SttVOaMy3nHKHDY83ElJ7bq68dEpsT VwGUVFXBINQ1bOOg79mvzTsC9PcTlrG4fK1Qzqw= X-Received: from albertccwang.ntc.corp.google.com ([2401:fa00:fc:202:e585:74ab:1a58:5276]) (user=albertccwang job=sendgmr) by 2002:a25:d741:0:b0:64d:b05e:f263 with SMTP id o62-20020a25d741000000b0064db05ef263mr11319662ybg.72.1652805215997; Tue, 17 May 2022 09:33:35 -0700 (PDT) Date: Wed, 18 May 2022 00:33:28 +0800 Message-Id: <20220517163328.3135065-1-albertccwang@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.36.1.124.g0e6072fb45-goog Subject: [PATCH v4] usb: dwc3: gadget: Move null pinter check to proper place From: Albert Wang To: balbi@kernel.org, gregkh@linuxfoundation.org, quic_jackp@quicinc.com Cc: badhri@google.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Albert Wang Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HK_RANDOM_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 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") Signed-off-by: Albert Wang --- drivers/usb/dwc3/gadget.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 19477f4bbf54..7edd4a5dc6af 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -3366,14 +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 (!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)) -- 2.36.1.124.g0e6072fb45-goog