Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp287755lqp; Mon, 10 Jun 2024 04:25:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXt6dYTkdSXb3HtDB+OhV4sWxsO1HF4W7+d1QtwWWW3kaRat4MgLLj0azHc7Jv8xkRE+vR4KsqGshgwDTfGLXPO0IcUOTGgrR74xX4CQQ== X-Google-Smtp-Source: AGHT+IFoxXjrfme6C2g/rrkePLa6IaJW8mw92n2r54WMPdeqXkqd/TXB+SGDPjtxRrfI7DC5Qkak X-Received: by 2002:a17:902:e80e:b0:1f6:e8ee:54b7 with SMTP id d9443c01a7336-1f7171ea2e5mr23792895ad.20.1718018717149; Mon, 10 Jun 2024 04:25:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718018717; cv=pass; d=google.com; s=arc-20160816; b=FZq9coy3y3yjJRRJ+6Mx3hctJoPHZwd0c+AEKC1Zf0zbMnGWcvYTpdMGJbbnWzMihm XNlPOaHy0Z0PzxtQxrTMt7Gou11ziZ8tLdcCpDH8qDIIM6la4Rzk85UGs1cLIvWsPIJN m+XA2bNeSsjae3E//GXRjZUDlYN9sIx+xlPDUXadACTLdWmNFuLsgCdLZbdobaXx0KGu G3F6BP+GLQkP926n++O9Ip3r+8xayIPASXzadsqN6ebisbg2E2W5fz81SyK5eSV6yrAS kZHijuvhxwdDlJu22NsHQMv2/ErmTOdxG983EbH1dqk3dp9QivrwCqwKBivbAD926WWH xkgw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:cc:content-language :references:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=nqbsfiopqlt2V8VnNoKJoP/cgCyWKLzePp2IJBBtJoc=; fh=RpKCrvA1Wnu3qvOIExM+3PnNxtHSyb6bc8O7wHNjvAM=; b=p75OUduVdBL1XiDT1S3TuEiZBWFYrnGMjykjpqGH+LxHn5HG8/qqT0MFcdN8WJ7BdH Xl17UKdf1Sc4WELNeRR+cXH+29JIsNP15zZrgidQbZlaX0EX2/D8rggItULPj/2KVex0 iXnA49m5Ciam2CgRhesp1W3X6LxUIC62EgiogyoER2eLG79qNhynwYM3DnahWzbNA9Zn tdP/af0eVSn3IYBdYaoR+CRnlDC+c8SvPfOVDPAvsZRmz7RFDeEKDfrQ0PzhFd3tE0ta Oix2qzg5Q97JjaAx1viTkJv3rpTypAx2J9/QRyFWhwwfafoWpxYYXD6VQiAiOFgCVr+m LKFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=i-love.sakura.ne.jp); spf=pass (google.com: domain of linux-bluetooth+bounces-5221-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-5221-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f6bd7e403fsi38840045ad.350.2024.06.10.04.25.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 04:25:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-5221-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=i-love.sakura.ne.jp); spf=pass (google.com: domain of linux-bluetooth+bounces-5221-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-5221-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 2403EB20A7A for ; Mon, 10 Jun 2024 11:00:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B686778C6D; Mon, 10 Jun 2024 11:00:51 +0000 (UTC) X-Original-To: linux-bluetooth@vger.kernel.org Received: from www262.sakura.ne.jp (www262.sakura.ne.jp [202.181.97.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DE07F9E8 for ; Mon, 10 Jun 2024 11:00:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.181.97.72 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718017251; cv=none; b=TVmsEIqqAAAy5c2MxxMvod2KgmYn5A95a7sp9a1/hAeooRUel1B26VMHkLIpUDaryuZ6b2gdi88LT77DWg6ExauJWKdGLQC8WjRdd1a2rVVBT/Hk+vrCjkowIzPTdzU7LVUx/KXWsiF/ETO54F+yY1QkG1iz/27UWyuIPCewNss= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718017251; c=relaxed/simple; bh=f9Mogg+jvZKEZ8qLwBmspRnlfU0+Btg1bLoW3fc+npA=; h=Message-ID:Date:MIME-Version:Subject:To:References:Cc:From: In-Reply-To:Content-Type; b=u9LEMNod788Ah5qHrV1fdwvvC4Dw305DkpaIoxlaB/rTaH9nhtNULkem7BfEAWRy0xFdGHC+fYI0mJxiXcaKStfVzdBntZAyirKVaxy/NWj54I7EzCNi2ag6lki9e86MMhB9g+ATfaVqE7ive8f1DxJpvgYWt/RXzGp5BNVKAVA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=I-love.SAKURA.ne.jp; spf=pass smtp.mailfrom=I-love.SAKURA.ne.jp; arc=none smtp.client-ip=202.181.97.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=I-love.SAKURA.ne.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=I-love.SAKURA.ne.jp Received: from fsav312.sakura.ne.jp (fsav312.sakura.ne.jp [153.120.85.143]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 45AB0XkX036714; Mon, 10 Jun 2024 20:00:33 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav312.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav312.sakura.ne.jp); Mon, 10 Jun 2024 20:00:33 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav312.sakura.ne.jp) Received: from [192.168.1.6] (M106072142033.v4.enabler.ne.jp [106.72.142.33]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id 45AB0Xlr036710 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Mon, 10 Jun 2024 20:00:33 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Message-ID: <7d6f0ed3-678e-4fd5-bd64-f980e0035b87@I-love.SAKURA.ne.jp> Date: Mon, 10 Jun 2024 20:00:32 +0900 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH] Bluetooth: hci_core: cancel rx_work,cmd_work,tx_work,power_on,error_reset works upon hci_unregister_dev() To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz References: <00000000000097c554060f215b50@google.com> Content-Language: en-US Cc: "linux-bluetooth@vger.kernel.org" , syzbot+da0a9c9721e36db712e8@syzkaller.appspotmail.com, syzkaller-bugs From: Tetsuo Handa In-Reply-To: <00000000000097c554060f215b50@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit syzbot is reporting that calling hci_release_dev() from hci_error_reset() due to hci_dev_put() from hci_error_reset() can cause deadlock at destroy_workqueue(), for hci_error_reset() is called from hdev->req_workqueue which destroy_workqueue() needs to flush. We need to make sure that hdev->{rx_work,cmd_work,tx_work} which are queued into hdev->workqueue and hdev->{power_on,error_reset} which are queued into hdev->req_workqueue are no longer running by the moment destroy_workqueue(hdev->workqueue); destroy_workqueue(hdev->req_workqueue); are called from hci_release_dev(). Call cancel_work_sync() on these work items from hci_unregister_dev() as soon as hdev->list is removed from hci_dev_list. Reported-by: syzbot Closes: https://syzkaller.appspot.com/bug?extid=da0a9c9721e36db712e8 Signed-off-by: Tetsuo Handa --- Completely untested. Please do tests with lockdep enabled before committing. Maybe it is too early to cancel hdev->{rx_work,cmd_work,tx_work}. Maybe there are more work items which should be canceled before hci_unregister_dev() completes. I don't know... net/bluetooth/hci_core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index dd3b0f501018..dbbe5e2da210 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2751,7 +2751,11 @@ void hci_unregister_dev(struct hci_dev *hdev) list_del(&hdev->list); write_unlock(&hci_dev_list_lock); + cancel_work_sync(&hdev->rx_work); + cancel_work_sync(&hdev->cmd_work); + cancel_work_sync(&hdev->tx_work); cancel_work_sync(&hdev->power_on); + cancel_work_sync(&hdev->error_reset); hci_cmd_sync_clear(hdev); -- 2.18.4