From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2F7F0626B2; Mon, 4 Mar 2024 21:34:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709588073; cv=none; b=HJYwT0EwjMSjG0o1H/GHDlTJ0nDp+qY3LaAeyHyxzSI1npEL0x7O+XPI56ddyMwf8VLkwwE5QRHDEDiRgY6FWgzQTTThre/z1wAiU/Gs4PBLIcSjdxKJru3ii37ZPXx+RkgZOZEmYA+dEBPcfO942gxTTx7Ptr1cV82tPAzAHDU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709588073; c=relaxed/simple; bh=omYvwM8MoDgltTYqeELVNYhOm0A/EEgU7HB/ECcXG8s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=quQHJQUC/q3zmHcfjyA/k8bHJ6PMCpw/kC+3cZLfBXhV6JxkLemg0GTJeXvk1cbpIGnn8vgUxwC1fiR8Ud30ZTw7EuFD5O09dGiqDGRGgFAJDqbzF9YDmU+LQ7uASbtUDmn/VF6HLwS/ubYxUktdEaq8IRMYoMpa44tI4jrayO4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=yg14rvyP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="yg14rvyP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B95BFC433C7; Mon, 4 Mar 2024 21:34:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1709588073; bh=omYvwM8MoDgltTYqeELVNYhOm0A/EEgU7HB/ECcXG8s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yg14rvyPzEYl5rHB7bzwJ3AdpuXMPkjramqrzznIwf0iDTus+uAa0jsAjnmeCdwWs EgI6kTWA8TdtljtGrKC4Cj7HB2VApXPot3GVeVFqqx9k0rqsjPZSLqE2EhzywYqehV CtC8ZOuaD8SjZTDLiYf1lijGZeKbYCb7XiqkA1T8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ying Hsu , Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 5.10 11/42] Bluetooth: Avoid potential use-after-free in hci_error_reset Date: Mon, 4 Mar 2024 21:23:38 +0000 Message-ID: <20240304211538.019822426@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240304211537.631764077@linuxfoundation.org> References: <20240304211537.631764077@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ying Hsu [ Upstream commit 2449007d3f73b2842c9734f45f0aadb522daf592 ] While handling the HCI_EV_HARDWARE_ERROR event, if the underlying BT controller is not responding, the GPIO reset mechanism would free the hci_dev and lead to a use-after-free in hci_error_reset. Here's the call trace observed on a ChromeOS device with Intel AX201: queue_work_on+0x3e/0x6c __hci_cmd_sync_sk+0x2ee/0x4c0 [bluetooth ] ? init_wait_entry+0x31/0x31 __hci_cmd_sync+0x16/0x20 [bluetooth ] hci_error_reset+0x4f/0xa4 [bluetooth ] process_one_work+0x1d8/0x33f worker_thread+0x21b/0x373 kthread+0x13a/0x152 ? pr_cont_work+0x54/0x54 ? kthread_blkcg+0x31/0x31 ret_from_fork+0x1f/0x30 This patch holds the reference count on the hci_dev while processing a HCI_EV_HARDWARE_ERROR event to avoid potential crash. Fixes: c7741d16a57c ("Bluetooth: Perform a power cycle when receiving hardware error event") Signed-off-by: Ying Hsu Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin --- net/bluetooth/hci_core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index e33fe4b1c4e29..5f1fbf86e0ceb 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2318,6 +2318,7 @@ static void hci_error_reset(struct work_struct *work) { struct hci_dev *hdev = container_of(work, struct hci_dev, error_reset); + hci_dev_hold(hdev); BT_DBG("%s", hdev->name); if (hdev->hw_error) @@ -2325,10 +2326,10 @@ static void hci_error_reset(struct work_struct *work) else bt_dev_err(hdev, "hardware error 0x%2.2x", hdev->hw_error_code); - if (hci_dev_do_close(hdev)) - return; + if (!hci_dev_do_close(hdev)) + hci_dev_do_open(hdev); - hci_dev_do_open(hdev); + hci_dev_put(hdev); } void hci_uuids_clear(struct hci_dev *hdev) -- 2.43.0