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 13BEF1CA94; Mon, 4 Mar 2024 21:26:00 +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=1709587560; cv=none; b=Z2ZEFCjREvgZhvd9XAWiDDj4ATwIjCh4kx7pJdUd4LXMvHBBICXNgpqGEszZhLLXfzZFRGjsL8Tn6CFG5qQ2r4n3aicd2NWj0oku31YYBFUEP61sUMexG/MtDxDHmKW4xsd7Tvja4xJ6jnadzdFrdokmu3L3lKWzBc94hkYyNU4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709587560; c=relaxed/simple; bh=bcQ8lYzwcqJ7zWPEUfb+me6Zr+T9oAZluhslB2vmQb8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eHwkLPe+wK/XmSb5xwHsrXK5O2EGyNVBZy96ThYVNBIqOqWNXB4byCPr3tW3ZaFfFmsBGLmYHLc3MzTIgOgUDc72QgLGP4g+fhinqx4x3S8bc4D/XR1ME3r7mxuiNzdwTrkhRme3/9pqmL9oKxEEpIce4LkQZWGZcSgnBi1u1UA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=eGV2i/vc; 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="eGV2i/vc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 98DD0C433C7; Mon, 4 Mar 2024 21:25:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1709587559; bh=bcQ8lYzwcqJ7zWPEUfb+me6Zr+T9oAZluhslB2vmQb8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eGV2i/vcPv2Bu0PSUz+G6KXp55ALQ0cW4uZJdtcCDDijRcCPKgCzXT13vZNS7+GAr RAYKoUz66V6clxDu97MFUtpcKl6ExmwbQmmovFypBvkSCYCim3MwGnuS9IMOSOJn1g OJ3E71UZx3bZwOZCvyCmlwzHWl46JmXKJ/sf0as4= 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 4.19 05/16] Bluetooth: Avoid potential use-after-free in hci_error_reset Date: Mon, 4 Mar 2024 21:23:26 +0000 Message-ID: <20240304211534.524417830@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240304211534.328737119@linuxfoundation.org> References: <20240304211534.328737119@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 4.19-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 4d89e38dceec3..f455a503f5b04 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2217,6 +2217,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) @@ -2224,10 +2225,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