Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1427477rwd; Thu, 8 Jun 2023 18:31:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4BN3DCCgY9CPGzSknrrpqameHmXm4v+AWvpUP1LvcfuL3BRDH8/WxCmt09AUuaYpJmu11Y X-Received: by 2002:a17:90b:1002:b0:259:c176:e3fb with SMTP id gm2-20020a17090b100200b00259c176e3fbmr67705pjb.37.1686274286550; Thu, 08 Jun 2023 18:31:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686274286; cv=none; d=google.com; s=arc-20160816; b=HWAyr+PSU82aJw4CYhUVAr09tornm79HhmGfbu7dqhwt+yEgsmHK3EAGJK2B4drklw sXaOeNWb58izenPGlnTFCosK+P5dNA6n4djSuBh9zeKGzJ3LoSjN45tcyPOQJRpZXkka K95yKHGHvpjiSLnVVEb7xy7w4DTeqKlBAdSOPpYSJ2pptocAgE2Nzrg7mHVjFe0twQWJ /5HhO14zzsVOCcxKciNeowib5ut/O1ibHDIVjhOYtdDVtMAim97dPI69C5yTJ+PjKArP ZGsN6hKQv5/Z6LlgHjbzktJrwPYAsmU4zGScOzk+YJHe3/ET3GtzjMAL1C+Ve857EO3H DU0w== 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; bh=0yKbz2/HoXqSIMZWbtwT49g9q/Yqz3nkUTgpLQrK1bM=; b=t5HduWa6FCJMqbYTbLmdzldJ1bcBJfVsUVcSWfuWxnG1ynPTiNOo/TCDvP3kOzetqV 9gf9kTqYXFVI66oGxv5u8i4lRICGvhLrsy7qb/6DcY6WZaKTJtu4clpSiNKw5BcRNhJ7 QfHqKR7Nl5d/FLglnelNnLAbOA9LbybNXMV5+TqfjfDLav4fsM8hMtay8Ms1gBLj4IdY cyG510hantA//uFOAihRqpJpdOYkZ6okSIaJZBwPmpR8Z0J0NlV9NTGBRpb5tRtcqgsK tBNd0nwXtR66P1dtmQUdvCS2b6U1YZuU5+CZ5DOMCnVBPTUZphJikeV4XyHiHfnZHfTC j+Dw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s9-20020a17090a440900b0024e500f373fsi1845520pjg.82.2023.06.08.18.31.12; Thu, 08 Jun 2023 18:31:26 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237549AbjFIBSD (ORCPT + 99 others); Thu, 8 Jun 2023 21:18:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229692AbjFIBSB (ORCPT ); Thu, 8 Jun 2023 21:18:01 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 169E62D4F for ; Thu, 8 Jun 2023 18:17:59 -0700 (PDT) Received: (qmail 283453 invoked by uid 1000); 8 Jun 2023 21:17:59 -0400 Date: Thu, 8 Jun 2023 21:17:59 -0400 From: Alan Stern To: Badhri Jagan Sridharan Cc: gregkh@linuxfoundation.org, colin.i.king@gmail.com, xuetao09@huawei.com, quic_eserrao@quicinc.com, water.zhangjiantao@huawei.com, francesco@dolcini.it, alistair@alistair23.me, stephan@gerhold.net, bagasdotme@gmail.com, luca@z3ntu.xyz, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v8 2/2] usb: gadget: udc: core: Prevent soft_connect_store() race Message-ID: <7b1a8de9-3811-4b4b-b85f-9afded0e45d1@rowland.harvard.edu> References: <20230609010227.978661-1-badhri@google.com> <20230609010227.978661-2-badhri@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230609010227.978661-2-badhri@google.com> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 On Fri, Jun 09, 2023 at 01:02:27AM +0000, Badhri Jagan Sridharan wrote: > usb_udc_connect_control(), soft_connect_store() and > usb_gadget_deactivate() can potentially race against each other to invoke > usb_gadget_connect()/usb_gadget_disconnect(). To prevent this, guard > udc->started, gadget->allow_connect, gadget->deactivate and > gadget->connect with connect_lock so that ->pullup() is only invoked when > the gadget is bound, started and not deactivated. The routines > usb_gadget_connect_locked(), usb_gadget_disconnect_locked(), > usb_udc_connect_control_locked(), usb_gadget_udc_start_locked(), > usb_gadget_udc_stop_locked() are called with this lock held. > > An earlier version of this commit was reverted due to the crash reported in > https://lore.kernel.org/all/ZF4BvgsOyoKxdPFF@francesco-nb.int.toradex.com/. > commit 16737e78d190 ("usb: gadget: udc: core: Offload usb_udc_vbus_handler processing") > addresses the crash reported. > > Cc: stable@vger.kernel.org > Fixes: 628ef0d273a6 ("usb: udc: add usb_udc_vbus_handler") > Signed-off-by: Badhri Jagan Sridharan > --- Reviewed-by: Alan Stern