From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796381789; b=FFKfsc8QTuWHLWz3JwaQTzmFXIDlTIAlu30wmfZVw+AJtNTx8irkfL+PGNsC2dGVQ0HU gpovwiAAvaqCmTr09wDDhJ8LAyxpTK7eXESFtmRcRPP90fa9seVbNDrQEwbQsU18w4I1b 4p0LivmuikyrtwyrzEOQVkApZXkhkurq/O7Ndl6rj7ZKLe5/0A6pwPYJakDqDETbLusMf SCrnW0o46jmTEY3hjMlf3Ba9xv/sbZq6o6vx6Rji/WMJrvUX/TYu8rY/fEAUfhakNqqwy dNyJWHtpPVKFTSjGB4AbawgqCrTzZekPp9poSEFqVrhzi0vCKnelIDLwybs4V0TKx2Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381789; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=tbOykfqwVo9KpSX5X6Z05NEO+igUR9LFwjMFijqD9b8=; b=zFlUl++VbL5w3YqDtm8lD1IOMoJvOR0urAxiAT3bPkGv9ZOklGkIPvDuDt4V2yR87A38 iLMBGyAVgmTQsZuLvf8ubD4dV1l5XKkIeDGnTRWD6umf8fzO3WklFrabTsos70fYmeLkl HGn/Br1SFljACgjsnMQ+ue7Ct3NAO9VNptL6pkZqSQz+7qFHOFTHDlM2xDtU8rOR5m2QO EtIuZUFABmyj849r2oI4lQUtdeQjza/zd9WLlMfVsPD084MCCScsqp/GxqSOzBsmoqIBK 6aOTI+HPhRE7bnxHWtwarkHaat9ZkQ1NBU+8FNfNaVyrKhAeUUPvOtKAW0zERQ2xe5g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=nnSIMJuW; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70B4D606A32C; Fri, 4 Dec 2026 10:56:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=nnSIMJuW Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA1231F0093A; Fri, 4 Dec 2026 10:56:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381789; bh=tbOykfqwVo9KpSX5X6Z05NEO+igUR9LFwjMFijqD9b8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nnSIMJuW41w7nSTnWYk4Mi3AEpfFoVkfkKVY9SKu+wJXHRgtm2vStKNUOHdVv8V40 +PgYRVrrtCGOtL2HZMqHRuwIFdHRE23KzEvWGrpeenZts3A5UufAKI7nL//KS11AU5 Ojj61Cyl5oMdNUw1TvHHiEZxqVu4Ph60iRSKDU68= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sashiko , Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 6.18 173/703] Bluetooth: hci_core: Hold hdev->lock when removing advertisement monitors Date: Fri, 4 Dec 2026 19:01:12 +0900 Message-ID: <20261204100632.478649234@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Luiz Augusto von Dentz [ Upstream commit 7f08b6ef44fa17f1a5ad3926663ddb5abe6ff68a ] hci_remove_single_adv_monitor() and hci_remove_all_adv_monitor() only require hci_req_sync_lock, yet they look up and free monitors, modifying hdev->adv_monitors_idr and adv_monitors_cnt, which Read Advertisement Monitor Features iterates under hdev->lock. Take hdev->lock around the IDR accesses and the freeing, but not across the HCI commands sent to the controller. Reported-by: Sashiko Link: https://sashiko.dev/#/bug/linux-8b358899-5ac9-4687-af16-58420a4d9bba Fixes: 7cf5c2978f23 ("Bluetooth: hci_sync: Refactor remove Adv Monitor") Assisted-by: OpenCode:claude-fable-5.2 Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin --- net/bluetooth/hci_core.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 5c5cee7ea9ae6..03ff64db62861 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2064,7 +2064,10 @@ static int hci_remove_adv_monitor(struct hci_dev *hdev, if (status == -ENOENT) bt_dev_warn(hdev, "Removing monitor with no matching handle %d", monitor->handle); + + hci_dev_lock(hdev); hci_free_adv_monitor(hdev, monitor); + hci_dev_unlock(hdev); return status; } @@ -2072,7 +2075,11 @@ static int hci_remove_adv_monitor(struct hci_dev *hdev, /* This function requires the caller holds hci_req_sync_lock */ int hci_remove_single_adv_monitor(struct hci_dev *hdev, u16 handle) { - struct adv_monitor *monitor = idr_find(&hdev->adv_monitors_idr, handle); + struct adv_monitor *monitor; + + hci_dev_lock(hdev); + monitor = idr_find(&hdev->adv_monitors_idr, handle); + hci_dev_unlock(hdev); if (!monitor) return -EINVAL; @@ -2088,7 +2095,10 @@ int hci_remove_all_adv_monitor(struct hci_dev *hdev) int status = 0; while (1) { + hci_dev_lock(hdev); monitor = idr_get_next(&hdev->adv_monitors_idr, &idr_next_id); + hci_dev_unlock(hdev); + if (!monitor) break; -- 2.53.0