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 8FC2F1C687; Mon, 4 Mar 2024 21:34:12 +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=1709588052; cv=none; b=Tsz30vmS1jyRTLPLXA8n+DmjXHN13xsf2/aN+wwFjQ3UfxIlnlCvF0Sm/G3VVwTF7//CuEZv6qwfqnau4srhzeruok8RSVdhVSeIvsZ4S3lI0U9ur9kA5+9+v7GgEK4MGwGkKU78PezwBnKrn4F4Rjfa45Nz/e+ZCJgM9OMVkv4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709588052; c=relaxed/simple; bh=bCY8b5QFjuPlpZUK5CUX0AAwej1qLFdJ9uA3wmmmoas=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KB2iKdCAw+xGSnTjrF352zf55pLbxbPeyOChYwssKf19/mSlT80swk+cyuQC1tCoA5iZl4930Ye7o5/ESXLt+PThingUjG/tkofMJhfjoaBwDVwrvt0rfJ/uhQQwKb8tvxR5R1rTNYBDyUFJ1V73293oFcdZECxHTL7oSCYMwx4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=vyzy1J1D; 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="vyzy1J1D" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24189C433F1; Mon, 4 Mar 2024 21:34:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1709588052; bh=bCY8b5QFjuPlpZUK5CUX0AAwej1qLFdJ9uA3wmmmoas=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vyzy1J1DX3Ser+DwDHsD36FqJNUoDh/MZsYJcXRToZNrMwDXPfVPhmnj3iLMsQP1s JI1jVSFObhA67B9GbMtX2y3iXvjMr75FLlsgEYnTQ7KmNiSAejTNrzgNHhfXxCoomT V9k75u2mR4VCK/FdHcObg9xE7DvJImK5EtLbmAaE= 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.4 07/25] Bluetooth: Avoid potential use-after-free in hci_error_reset Date: Mon, 4 Mar 2024 21:23:43 +0000 Message-ID: <20240304211535.988605917@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240304211535.741936181@linuxfoundation.org> References: <20240304211535.741936181@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.4-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 54c55c30db17b..289fb28529f8c 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2272,6 +2272,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) @@ -2279,10 +2280,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