Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2316553pxb; Fri, 25 Mar 2022 15:20:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6IFApvnMhc+oamixG7xzITSy5vf8hTQwj7rfujGbS8RW4O9MMvrE+Yfhzt7OJfxCZarRB X-Received: by 2002:a17:902:930b:b0:14d:b0c0:1f71 with SMTP id bc11-20020a170902930b00b0014db0c01f71mr14055769plb.113.1648246815627; Fri, 25 Mar 2022 15:20:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648246815; cv=none; d=google.com; s=arc-20160816; b=hhEqeGxGXcIakosaD8Ocu8T8TB0+V1r2zUaPFHZlsYeIuZfiAuWRmEbFfCaTGJ172C 7v7bjjC0SryLcq9kWhZbcaF+GfRzIW4WIc72CNVQSM04ocWfoa5bT924WiHbETESt/P/ T0G9RtN/UwUl9bqhnS9jBGTOiYtjUQ6TOB7NEM3VSQWq7Yl62QYR/P3qJv2lUEP8VWLs 2O7drxEiI9RH99B1ddOouwLU3wcNaIKWmgAl7Tjrdw8AM8VP2O8IuFDL3YH3knYI6cIJ gMc4ag1e/0MlpbHdeJACp5cyHrMz/MJeOni1XZ/rEKGx8Hk6bAtLNMWi5+2uN/O6xnQz uvlA== 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:date:cc:to:from:subject :message-id:dkim-signature; bh=O89r3kLV+3EEUAMr9w+snOfj3ajDh1BFqK6IJ85WWws=; b=is4XOH9/Tj6XkEWAxhBR1omH9H/NK0dvSwY28d7/A6b2B7KXGxUAw+m/OOJU7XJPWl IFD+nQvT9OdF+S8VGvN4lZtSRuYq251Pc8ulGcT68B8qzvb/uggw7tX71/rR/Yon68UI 8pTd2pSJMDe/+u9buTrct3uyHhrmHltWQjdzGSqiyD6Ir3NcTnRcC+OV5QR0ei2TZj9Z HbhBkmkZflWRlLuGxMV4iLoEP3OeEbrO5YQSm9ukfsp1Uu02frS6U0KV9vklm2Skt6QF JFn661bzxAsJ5cEy1FD4DFT2tcO+GZ/as1YGFGIhOMEnHTtDZ05NIBzXWn+E7I6Jl3kQ oOTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=JdU9HHVz; spf=softfail (google.com: domain of transitioning linux-wireless-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id c20-20020a63d514000000b003816043f042si3558701pgg.567.2022.03.25.15.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 15:20:15 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-wireless-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=JdU9HHVz; spf=softfail (google.com: domain of transitioning linux-wireless-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=REJECT dis=NONE) header.from=sipsolutions.net Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 451BF23162; Fri, 25 Mar 2022 14:54:51 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233584AbiCYV4X (ORCPT + 70 others); Fri, 25 Mar 2022 17:56:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233577AbiCYV4W (ORCPT ); Fri, 25 Mar 2022 17:56:22 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:191:4433::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADEEF220EE; Fri, 25 Mar 2022 14:54:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: Content-Type:References:In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=O89r3kLV+3EEUAMr9w+snOfj3ajDh1BFqK6IJ85WWws=; t=1648245287; x=1649454887; b=JdU9HHVzw1faTiB4XMBqevUSguuZ0AZlBynDLpExZrGG/Af XH1bixD477b7stiskx3zKgVq2jpa8V7Y7MBmhHoK4EcBtNsrtTpNpcwaToKfHAYnJYtA6UKhpM+MO 8E5NTGVCyQESKJz53ikINo9Y+VPrZiIYdNdvoidvyFmrGKFUjWU2J1pzRcZZKw0Ajv+ZO9VDnbrtd dE0wb9kYSbPw6gfZ/dG8b1VO04sE7r76Z7oTErgNvfJ8RoewvT6WGazjo778LBdP+MmAxzmeWrEBo dYbs3xBKkZp/kB81/PxriZ8F9GvNL8uxawBz6dyRjCNPDiLPt2J/W4Ca3i1KlOjg==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.95) (envelope-from ) id 1nXrtH-000Wd1-2D; Fri, 25 Mar 2022 22:54:39 +0100 Message-ID: <1e4ef09dea2c22a03fa2303a0e909b99e8ed9028.camel@sipsolutions.net> Subject: Re: [BUG] deadlock in nl80211_vendor_cmd From: Johannes Berg To: William McVicker Cc: Jakub Kicinski , linux-wireless@vger.kernel.org, Marek Szyprowski , Kalle Valo , "David S. Miller" , netdev@vger.kernel.org, Amitkumar Karwar , Ganapathi Bhat , Xinming Hu , kernel-team@android.com, Paolo Abeni Date: Fri, 25 Mar 2022 22:54:38 +0100 In-Reply-To: <976e8cf697c7e5bc3a752e758a484b69a058710a.camel@sipsolutions.net> References: <0000000000009e9b7105da6d1779@google.com> <99eda6d1dad3ff49435b74e539488091642b10a8.camel@sipsolutions.net> <5d5cf050-7de0-7bad-2407-276970222635@quicinc.com> <19e12e6b5f04ba9e5b192001fbe31a3fc47d380a.camel@sipsolutions.net> <20220325094952.10c46350@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> <976e8cf697c7e5bc3a752e758a484b69a058710a.camel@sipsolutions.net> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-1.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-malware-bazaar: not-scanned X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,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=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-wireless@vger.kernel.org On Fri, 2022-03-25 at 22:16 +0100, Johannes Berg wrote: > > > Thread 1 Thread 2 > > nl80211_pre_doit(): > > rtnl_lock() > > wiphy_lock() nl80211_pre_doit(): > > rtnl_lock() // blocked by Thread 1 > > nl80211_vendor_cmd(): > > doit() > > cfg80211_unregister_netdevice() > > rtnl_unlock(): > > netdev_run_todo(): > > __rtnl_unlock() > > > > wiphy_lock() // blocked by Thread 1 > > rtnl_lock(); // DEADLOCK > > nl80211_post_doit(): > > wiphy_unlock(); > > > Right, this is what I had discussed in my other mails. > > Basically, you're actually doing (some form of) unregister_netdevice() > before rtnl_unlock(). > > Clearly this isn't possible in cfg80211 itself. > > However, I couldn't entirely discount the possibility that this is > possible: > > Thread 1 Thread 2 > rtnl_lock() > unregister_netdevice() > __rtnl_unlock() > rtnl_lock() > wiphy_lock() > netdev_run_todo() > __rtnl_unlock() > // list not empty now > // because of thread 2 rtnl_lock() > rtnl_lock() > wiphy_lock() > > ** DEADLOCK ** > > > Given my other discussion with Jakub though, it seems that we can indeed > make sure that this cannot happen, and then this scenario is impossible > without the unregistration you're doing. > I just sent a patch for this then, forgot to CC everyone: https://lore.kernel.org/r/20220325225055.37e89a72f814.Ic73d206e217db20fd22dcec14fe5442ca732804b@changeid But basically it changes nothing, just adds a WARN_ON with documentation ensuring that the invariant never breaks, i.e. that Thread 2 can't happen. And maybe I should've written that with 3 Threads, but the setup of unregister_netdevice()/__rtnl_unlock() could happen anywhere in the system anyway. johannes