Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7660476rdb; Thu, 4 Jan 2024 03:57:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IGdiwBm4mEdNmiDf+1LcWVmRJSndrNwV7+NdgrW7pJi/k1ohEhE6alqpQgFsdkMulMrYlxe X-Received: by 2002:a05:620a:13e9:b0:781:5e1f:e414 with SMTP id h9-20020a05620a13e900b007815e1fe414mr454083qkl.9.1704369443696; Thu, 04 Jan 2024 03:57:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704369443; cv=none; d=google.com; s=arc-20160816; b=kDgvxSWCtqSdY6MvASuikpaXHMvwVfPyi6xPTCq8VFBgE/UN2qit3YmwHTVhxIAIg0 Xi3w3U+mo0KndKBcoSiO+Nklh+ZhyEuv5RPJmteJ+joWXZ0QQf54q5ykT0QKqNsPh33w a3BF3qpQEQe2aORBrrxXmtwq/50GuJq+6coKrQCXgyVrj7utE4lOHduO7yWUcQP0mMMZ H9ymuQZ/IyBigxPwYsUhfNkbm/otTubuXjmFX8bEvZfNjL13Xy+MyUOwWK/AO/raTxac mgpb4du6Knov0NpTASymOBBSDTKXOVWnUKMZv1dV3/LvpeIS/1Xi4QDAA/RZvbsWuq8l Qq5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=AaeihiujCSNV/IpYyiqh1GWzfHkk93j+fBxfYGSZUOs=; fh=CfprHIOQnZt2UlCy1LqUsd58mfWxwrnLvXoUWIM/zgE=; b=RImM4ew6P2Qy6V0rvlYSLtACmcLSJnadlVT+l77ElGBJkzvmkpR108od0CxkLQr/ht GggGg7+diGKJ4kWDv7q7SFYUdlkyxz3SanbUg2Pbpmw0nMi5q90U7KXzRzJQI4FAuyzw ric+tMFYJlYDTeWcxv9neplmKJAMA6VbAgfukn4ckn3rRwAI1qDAb9UzqzDFOjoxYngX HZ3yY5uG3HVCZqhoYou/mrEhzP2FBMdr1pzjvm8rFq+w3djQKybfAGOXxS7OsjsVWhir oAYTCukc/eKmTrSBOcmeF0Ou9QH8HPm8VVz4aVeTGr+dOkyW1idc3dB+aQQtA4Ye4IVS hzNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DsunAFqk; spf=pass (google.com: domain of linux-kernel+bounces-16610-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16610-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id n4-20020a05620a294400b007810c541f20si32158167qkp.274.2024.01.04.03.57.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 03:57:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16610-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=DsunAFqk; spf=pass (google.com: domain of linux-kernel+bounces-16610-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16610-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 747BC1C21C64 for ; Thu, 4 Jan 2024 11:57:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC6A02136D; Thu, 4 Jan 2024 11:57:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="DsunAFqk" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73D2E2135C for ; Thu, 4 Jan 2024 11:57:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6d9b37f4804so956744b3a.1 for ; Thu, 04 Jan 2024 03:57:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1704369433; x=1704974233; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=AaeihiujCSNV/IpYyiqh1GWzfHkk93j+fBxfYGSZUOs=; b=DsunAFqkdVuIlLhHUHLGKF2imFxqdZhNXhfkQ57iaq+AFbsPjHVdoWq3TtB0YhOTVG 6PFVEqjvtzF3DrDVjTrVduIem5q3cesAEgb9yBXlaHDnUWLsHleu6wlKXEc+tjykIgZg 9DKFp3LQ/M+HiMrGZ0ISK56z1K2mOD4MfRKV4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704369433; x=1704974233; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AaeihiujCSNV/IpYyiqh1GWzfHkk93j+fBxfYGSZUOs=; b=ia3OomvWHMtU9EtWu/uLRfrYmHkEfjMxnQy08/uMqghpO9rupBD8TTmjrMs+rcs9Ea ULnVQ7zhABGwwLwPvFUGBAL16Jb5j+VnmaXW/KqYxIHVNDVTXL037cLbLbWMzbl9bqTL D0MiWSythNcOlxFL7pEwMabwNsx+g+IXevBIudnpqTBIA6kprM3NfGi5dgL5fROcZhfw oZZ/0GHAzzut8K+p3y+csTeACpuGC/0bir4RR7aP1uhE4F3bty1eitm7iWEnR//aj3n+ On1ZYSKzl4eKUKMwlJIOX1VzcFHsi1cXPMrqpoH3Ckcy9SPJDjGQNTpWsfty2U6kEuz3 MwPQ== X-Gm-Message-State: AOJu0YzfQbD4YMvUDcd+v7Ny6NT/BQdPOGgqDkY55pWclYmEtrM2pjBv Pd2j0qFXfWcQAtGIcskombPg2kaUPwa3 X-Received: by 2002:a05:6a20:be1f:b0:197:33ea:f45 with SMTP id ge31-20020a056a20be1f00b0019733ea0f45mr423598pzb.60.1704369432702; Thu, 04 Jan 2024 03:57:12 -0800 (PST) Received: from localhost (231.137.80.34.bc.googleusercontent.com. [34.80.137.231]) by smtp.gmail.com with UTF8SMTPSA id fn1-20020a056a002fc100b006d9a0902934sm20668062pfb.70.2024.01.04.03.57.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 04 Jan 2024 03:57:12 -0800 (PST) From: Ying Hsu To: linux-bluetooth@vger.kernel.org Cc: luiz.dentz@gmail.com, linux-kernel@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.org, Ying Hsu Subject: [PATCH] Bluetooth: Avoid potential use-after-free in hci_error_reset Date: Thu, 4 Jan 2024 11:56:32 +0000 Message-ID: <20240104115453.1.Iaa08c695d3dcf819910ea723c3eb502935638172@changeid> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. Signed-off-by: Ying Hsu --- Tested this commit on a chromebook with Intel BT controller. net/bluetooth/hci_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 65601aa52e0d..a42417926028 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1049,6 +1049,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) @@ -1060,6 +1061,7 @@ static void hci_error_reset(struct work_struct *work) return; hci_dev_do_open(hdev); + hci_dev_put(hdev); } void hci_uuids_clear(struct hci_dev *hdev) -- 2.43.0.472.g3155946c3a-goog