Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1216980rwd; Thu, 8 Jun 2023 14:13:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6nWUDW2sDxKLVnU0fGr159rNBL8rKDaWiPw9DIa6l5ACy0vbz4PPU9jR3LywpURoZeB+aq X-Received: by 2002:a05:6a00:1f9e:b0:657:622b:21b5 with SMTP id bg30-20020a056a001f9e00b00657622b21b5mr2769470pfb.12.1686258838387; Thu, 08 Jun 2023 14:13:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686258838; cv=none; d=google.com; s=arc-20160816; b=jDuG7+sr1uitqBm6x1rX8Mp7NAOUbIkcpPUPmdgCogrRcN5gLexg/wdzog5x48+oc7 2R32Knij3mT7Cjc8wNBlT+vk8AjirGQymU9/D7f3mXi8AMz06haZBGpNtZbC26L+iOpz 6ZHPJrZx8eqSwkubfOz7WUWFfJs8BbXmWlJHTcZ1Jclu7EveTCoQM0uU/NihL9b1Ygm2 G3szeJ8w9xkjmSMMASwtAl9qWZjmBysw5JEohp/Tcy0nwmZMacB05PdVG+fzR7LOyhNK FXfkV5zoFlsRHmH/wssColDaFkbka3GdQ0XTsIEMiLE6B2EEZfwaC6+UG1QYFgmX0pdI af8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Z/cWOdE9Cl4ghSCati9orroM7J3NkJ+yK6Fnm2pVwJU=; b=ocObl775Bbw7joxC7eXtQ+jGsDnmuGfVZNxGEj3Wa64+A4sIv9pu+SLTYyGtQYYIj2 i4A266sNrYi1UGqIkexUmBcDyRBB6O3Px2oJ1hi/KEIx9E/AzQH9wqMf6vDTyu/PQoCl 2tYcaNYvRtxMtdp9MUQlOjj+uTwj84fJUI/bfB/O1sZg4oNgbrBNCUhvSwwir9IaeY5j X1i2Cs/XDfWvafDQla90kTBjXNU7YhHQQ8EWF4v/gm+0GpEfg17PLsnREPdjEv0tTzFO k+777+oKnfL0vIWpEncz6Pt680waUGPnqWRrR+Q+cyhWt3bIymZxZYRP9yEd6IRvHltv K7eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=GiRa6Wzk; 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 v13-20020a63b94d000000b005348fd7cb66si1453441pgo.873.2023.06.08.14.13.45; Thu, 08 Jun 2023 14:13:58 -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=20221208 header.b=GiRa6Wzk; 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 S232119AbjFHUsf (ORCPT + 99 others); Thu, 8 Jun 2023 16:48:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230290AbjFHUse (ORCPT ); Thu, 8 Jun 2023 16:48:34 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 472352119 for ; Thu, 8 Jun 2023 13:48:32 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-25695bb6461so102431a91.1 for ; Thu, 08 Jun 2023 13:48:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686257312; x=1688849312; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Z/cWOdE9Cl4ghSCati9orroM7J3NkJ+yK6Fnm2pVwJU=; b=GiRa6WzkGzsFTmbxE578/6wmNaD4wDVcmaHNzIz8Yr+O8oFpKOBOCy0YSaJuhAqsEM L3ILbz7NT12kFAJ5BuEEJpKiGgw4VksSjdXJV40v3TxbwDPn3c4Vy8D2tgoO2lP7nna6 hpiKCtyUVhA1DkYu5iVO9YETZ9uk913mB+gGTgVM9Pnjtu3UXjGmOfVe26u1AxIsc/mm +uYHy+v7Q6RaOcHR3F3xRY6lHfpUZLDbi83RwuBE8xeRJ+i/Dks/sZglO2ZjBHEGWhdH WRJ3fPFPaqZuqJLzf/LQP1sHFOzaqmE05lfuHwsepDjRt7rtCatUXfizQnU/+knR4uhK F6XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686257312; x=1688849312; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z/cWOdE9Cl4ghSCati9orroM7J3NkJ+yK6Fnm2pVwJU=; b=fU2eyzWslOJZidCN+bIbIaw3fWJeB9noNPF/DttzE12KcS2AdW1uVKiaUgsyIUJ6uC ZBZPLejh9NxLGzzz+/lMeoWFaoEqkkdmSL96Rgmm7shsNnRiTzezhz8onv8u2avHrfGV jIgqNMCHtDnVZiePwiidcTQ87Kky1qq/ePd+ZfFZnkhpxXLh3lf/nVXQMiLLaB6jK1AO 7dpb1fHrbsgTNh1QWXX2cQAQmwq39fm5klAq9fLA5VOTNcq+dioeHwH1j3Ta2cdJPNsB O098JVm5SlrWG7C1xpCrpjGFPtOF5pG631eDD19XBymvvaXBBfzRisI3SiRaRgu354Co j+mg== X-Gm-Message-State: AC+VfDxSk7QDrD5oJOK1OpQjuLlHjOK5anWVtMldlST90acQN62PZVGU LSqpqK0295FcbVPvebHgp5J4/lhV5cgztrzRxyKFJA== X-Received: by 2002:a17:90b:17d1:b0:253:25c3:7a95 with SMTP id me17-20020a17090b17d100b0025325c37a95mr3729209pjb.14.1686257311593; Thu, 08 Jun 2023 13:48:31 -0700 (PDT) MIME-Version: 1.0 References: <20230601031028.544244-1-badhri@google.com> <20230601031028.544244-2-badhri@google.com> <0bea99f1-cf66-4e80-b89b-41007c2ccfee@rowland.harvard.edu> <66a886aa-4b3d-421d-a229-8bb400c6fc8b@rowland.harvard.edu> In-Reply-To: <66a886aa-4b3d-421d-a229-8bb400c6fc8b@rowland.harvard.edu> From: Badhri Jagan Sridharan Date: Thu, 8 Jun 2023 13:47:54 -0700 Message-ID: Subject: Re: [PATCH v6 2/2] usb: gadget: udc: core: Prevent soft_connect_store() race To: Alan Stern 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Thanks Alan ! Just sent out the v7 of the series after fixing all other comments. Regards, Badhri On Thu, Jun 8, 2023 at 8:27=E2=80=AFAM Alan Stern wrote: > > On Wed, Jun 07, 2023 at 10:17:04PM -0700, Badhri Jagan Sridharan wrote: > > On Wed, Jun 7, 2023 at 11:26=E2=80=AFAM Alan Stern > > wrote: > > > > @@ -756,10 +772,12 @@ int usb_gadget_disconnect(struct usb_gadget > > > *gadget) > > > > if (!gadget->connected) > > > > goto out; > > > > > > > > - if (gadget->deactivated) { > > > > + if (gadget->deactivated || !gadget->udc->started) { > > > > > > Do you really need to add this extra test? After all, if the gadget > > > isn't started then how could the previous test of gadget->connected > > > possibly succeed? > > > > > > In fact, I suspect this entire section of code was always useless, si= nce > > > the gadget couldn't be connected now if it was already deactivated. > > > > > > > Thanks Alan ! Will fix all other comments in v7 but not sure about this= one. > > Although the ->pullup() function will not be called, > > -> connected flag could actually be set when the gadget is not started. > > > > - if (gadget->deactivated || !gadget->udc->allow_connect) { > > + if (gadget->deactivated || !gadget->udc->allow_connect || > > !gadget->udc->started) { > > /* > > * If gadget is deactivated we only save new state. > > * Gadget will be connected automatically after activation. > > + * > > + * udc first needs to be started before gadget can be pulled up. > > */ > > gadget->connected =3D true; > > > > This could happen, for instance, when usb_udc_vbus_handler() is invok= ed > > after soft_connect_store() disconnects the gadget. > > Same applies to when usb_gadget_connect() is called after the gadget ha= s > > been deactivated through usb_gadget_deactivate(). > > > > This implies that the checks should be there, right ? > > Yes, you're right; the checks do need to be there. I had forgotten > about these possible cases. Ignore that comment. > > Alan Stern