From nobody Thu Sep 24 14:25:41 2026 Received: from mail-dl2-f43.google.com (mail-dl2-f43.google.com [74.125.229.171]) (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 A94244A49B3 for ; Tue, 22 Sep 2026 19:48:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.229.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790106526; cv=none; b=dEG8K7LRZDgsM0cKImSlCD2aPYiF202lXPUN644HpczuH6ynNH8xQo4vKUKHdauQ1NM5UhDkMZH/4XiIIEwjUdLhnjqlWwvlZImpes7uRDQY8LOC/PMus81vAMBkE5UvJxtp0FeV2uH8T7qt/yTndBiitcj7dLK+CP90/CrVrPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790106526; c=relaxed/simple; bh=vxnVhGFWw4jrl9DnCaFJw/l/iEJ5JQ9+0zwI6d/+tsY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NCiBafhZGSVGRkcCwec7DUnHV+MhFYEvEMjDg2v8gdj3T4kMCtEoPgzLkRuYlFpJ6uJaw4AyrRylATAWCZT8RJiL1OEIBUWcEGuO9xn7JLbPZt0VufKgHMYOwc5U6C+ms0ysL5Ff3MJdsRQxJ9oYokYTtT7mApCxjS9ElZBb7T4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com; spf=pass smtp.mailfrom=trailofbits.com; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b=S4LVVW7c; arc=none smtp.client-ip=74.125.229.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b="S4LVVW7c" Received: by mail-dl2-f43.google.com with SMTP id a92af1059eb24-144f9160b81so70458c88.0 for ; Tue, 22 Sep 2026 12:48:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trailofbits.com; s=google; t=1790106524; x=1790711324; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=yLkGtM8tazdcdnHvLp+FEgu253YR4i7gpOlAe8BcjDA=; b=S4LVVW7c8gptlrl0KKeyWBmzCNnr5co4UIEUcxyviep7qmg0WfNbn8Xg/ix3UoSEji 94i9F7C1VeoFddlrJ8sKWPmbYfM1gayrL31VlMystolF+pjxXGEQKWf5BGj9xBRv2Eb9 lJAyjOwzWy0qTwNp2GKE8/eQ7Lgos0Qt73RmS+VDQygOxfrOJEh6tg0jcEQUVDedtoxl 2l0gqqvuVG3Q7U+radGAUlxzaQC6HmywTCF0hwCoKqJacgxm2EexmCl6W6S90QLv8EC8 kpB1v5j1ErEi0da3LmbKAb/gQ8jL5Ct+ciWBFoTR/fWEVud3eT1rsLZXH8d8++TGUEU/ 0Teg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790106524; x=1790711324; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=yLkGtM8tazdcdnHvLp+FEgu253YR4i7gpOlAe8BcjDA=; b=PxH1tueraP942qhta8QBDxj6K2NXI5xk3mOYyj13e22kvX4I8uEQzpBHnuqgU2S8rp uryX+jGVSxzSOWoML/tbejMcDDRUQZswPwINiLV8ZwCL2+2/+nFFsLoccms+/u1rdAsh 50R7ALK5rZZLctcV3pQExZNTwJ5575LdAWcSlLlBLQLHjWTDF+DYOOoUpKgc2S7bmFAU z84CI+ovr+xQNqsNUgDJPsjZ2tIUKiVkwbs+01mll9RQ4S41f5alkx4CB3JN5pBqGCiN NKptleiGDerXbSDEDtiVm4MTcEzDoGZmjr6rT5OC18WG5xecII5K8cc+1JG/16oWJbIL l07Q== X-Forwarded-Encrypted: i=1; AKwUvBwc5ac9nBYkwfQmeWArYFds7EuIkiUPkX9qDF8U8N9bHRBQyL26ktYX60zDBWmMfME4rN09d/dZNp2ywfA=@vger.kernel.org X-Gm-Message-State: AFuF++kaTGu4Agv/8pYVfkg3jJF4MUdCjycs2UZ2c8ftYI5w9CUaoc4G YJMNga36yaBc4erRNO1OFGAUuUVJRvaaNmKgCS4/cBMavQkxZF0PFwP054QOeE+IE1w= X-Gm-Gg: AYBFou0Q+5TylVaLIAK9c7QLK1a1gEX58Opq5WqhLdApm8CMek8jNwJQoK4X9UEWHGY XioRZvrTmrwFHeZ+rXegl9IczeMRBNwh4Fbly09SHgmdBAUsoBWWrtAknDOfnEq/fMjOSMqNdk7 sgqJcqd+di/aO2EiZq9CspFpx68Vu2tgbIX2OVT1zuDaR7PYPolsDaxxiGJmKFSmDsa6tLlkgXM YQea+2+aPHFcyeq2+sTzlR9jXsH191V1tvyuvvHTK+ChvMFnCcxuSukm0rUxqLmSoZFBvEQDhD0 2AIz88K/nsmloNK5FXKu6tCmCUJkNda8GvzwRuv1QWqVzL0iZTqlfqNDi4UMoprDTK5LWN6DBc7 NbN3bpbw3Cmp3jU0FVgMkFXDu9FLgnJS2KADatLv9G3G0NhwBy0G8LvaQMOvHFSRyvrnKLK59+Y yFr0CRL0+63nCCp67Vfug+9dHqFbmFLwIPeaA8kIOaDQ/3VhoZSMUXgVH3jUlI2TpCpid3hz/hs +0V4VfH6Es3mnWAhbJSZAbNhNRnG/n65tPKJZMKuso7m9cx9jzMMAQwu5lO51iYrQt0hasepIBk F2xTrQ== X-Received: by 2002:a05:7022:f901:b0:134:cf34:b8e0 with SMTP id a92af1059eb24-144f908714amr417661c88.9.1790106523570; Tue, 22 Sep 2026 12:48:43 -0700 (PDT) Received: from localhost.localdomain ([2603:8001:5f01:8bab:c016:77a6:d382:7611]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-144f98a288esm708550c88.13.2026.09.22.12.48.42 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 22 Sep 2026 12:48:43 -0700 (PDT) From: Artem Dinaburg To: stable@vger.kernel.org Cc: Artem Dinaburg , Greg Kroah-Hartman , Sasha Levin , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Luiz Augusto von Dentz , Pauli Virtanen Subject: [PATCH 6.1.y 1/2] Bluetooth: hci_sync: Fix UAF in hci_disconnect_all_sync Date: Tue, 22 Sep 2026 15:48:33 -0400 Message-ID: <20260922194838.26223-2-artem@trailofbits.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260922194838.26223-1-artem@trailofbits.com> References: <20260922194838.26223-1-artem@trailofbits.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Luiz Augusto von Dentz [ Upstream commit 94d9ba9f9888b748d4abd2aa1547af56ae85f772 ] Use-after-free can occur in hci_disconnect_all_sync if a connection is deleted by concurrent processing of a controller event. To prevent this the code now tries to iterate over the list backwards to ensure the links are cleanup before its parents, also it no longer relies on a cursor, instead it always uses the last element since hci_abort_conn_sync is guaranteed to call hci_conn_del. UAF crash log: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D BUG: KASAN: slab-use-after-free in hci_set_powered_sync (net/bluetooth/hci_sync.c:5424) [bluetooth] Read of size 8 at addr ffff888009d9c000 by task kworker/u9:0/124 CPU: 0 PID: 124 Comm: kworker/u9:0 Tainted: G W 6.5.0-rc1+ #10 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-1.fc38 04/01/2014 Workqueue: hci0 hci_cmd_sync_work [bluetooth] Call Trace: dump_stack_lvl+0x5b/0x90 print_report+0xcf/0x670 ? __virt_addr_valid+0xdd/0x160 ? hci_set_powered_sync+0x2c9/0x4a0 [bluetooth] kasan_report+0xa6/0xe0 ? hci_set_powered_sync+0x2c9/0x4a0 [bluetooth] ? __pfx_set_powered_sync+0x10/0x10 [bluetooth] hci_set_powered_sync+0x2c9/0x4a0 [bluetooth] ? __pfx_hci_set_powered_sync+0x10/0x10 [bluetooth] ? __pfx_lock_release+0x10/0x10 ? __pfx_set_powered_sync+0x10/0x10 [bluetooth] hci_cmd_sync_work+0x137/0x220 [bluetooth] process_one_work+0x526/0x9d0 ? __pfx_process_one_work+0x10/0x10 ? __pfx_do_raw_spin_lock+0x10/0x10 ? mark_held_locks+0x1a/0x90 worker_thread+0x92/0x630 ? __pfx_worker_thread+0x10/0x10 kthread+0x196/0x1e0 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x2c/0x50 Allocated by task 1782: kasan_save_stack+0x33/0x60 kasan_set_track+0x25/0x30 __kasan_kmalloc+0x8f/0xa0 hci_conn_add+0xa5/0xa80 [bluetooth] hci_bind_cis+0x881/0x9b0 [bluetooth] iso_connect_cis+0x121/0x520 [bluetooth] iso_sock_connect+0x3f6/0x790 [bluetooth] __sys_connect+0x109/0x130 __x64_sys_connect+0x40/0x50 do_syscall_64+0x60/0x90 entry_SYSCALL_64_after_hwframe+0x6e/0xd8 Freed by task 695: kasan_save_stack+0x33/0x60 kasan_set_track+0x25/0x30 kasan_save_free_info+0x2b/0x50 __kasan_slab_free+0x10a/0x180 __kmem_cache_free+0x14d/0x2e0 device_release+0x5d/0xf0 kobject_put+0xdf/0x270 hci_disconn_complete_evt+0x274/0x3a0 [bluetooth] hci_event_packet+0x579/0x7e0 [bluetooth] hci_rx_work+0x287/0xaa0 [bluetooth] process_one_work+0x526/0x9d0 worker_thread+0x92/0x630 kthread+0x196/0x1e0 ret_from_fork+0x2c/0x50 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Fixes: 182ee45da083 ("Bluetooth: hci_sync: Rework hci_suspend_notifier") Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz [ Backport to 6.1.y: the source change is unchanged; only hunk locations in hci_sync.c differ. ] Assisted-by: LLM Signed-off-by: Artem Dinaburg --- Stable submission note: patch 1/2 in the CVE-2023-53762 series for Linux 6.1.y. CVE: CVE-2023-53762 Build: This patch was included in an x86_64 allmodconfig and CONFIG_WERROR=3Dy build. It produced vmlinux and modules with no new warnings or errors. net/bluetooth/hci_sync.c | 55 +++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index d5856448d46782..da9e6e55bc1d00 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -5587,6 +5587,7 @@ int hci_abort_conn_sync(struct hci_dev *hdev, struct = hci_conn *conn, u8 reason) { int err =3D 0; u16 handle =3D conn->handle; + struct hci_conn *c; =20 switch (conn->state) { case BT_CONNECTED: @@ -5600,43 +5601,57 @@ int hci_abort_conn_sync(struct hci_dev *hdev, struc= t hci_conn *conn, u8 reason) err =3D hci_reject_conn_sync(hdev, conn, reason); break; default: + hci_dev_lock(hdev); conn->state =3D BT_CLOSED; + hci_disconn_cfm(conn, reason); + hci_conn_del(conn); + hci_dev_unlock(hdev); return 0; } =20 + hci_dev_lock(hdev); + + /* Check if the connection hasn't been cleanup while waiting + * commands to complete. + */ + c =3D hci_conn_hash_lookup_handle(hdev, handle); + if (!c || c !=3D conn) { + err =3D 0; + goto unlock; + } + /* Cleanup hci_conn object if it cannot be cancelled as it * likelly means the controller and host stack are out of sync * or in case of LE it was still scanning so it can be cleanup * safely. */ - if (err) { - struct hci_conn *c; - - /* Check if the connection hasn't been cleanup while waiting - * commands to complete. - */ - c =3D hci_conn_hash_lookup_handle(hdev, handle); - if (!c || c !=3D conn) - return 0; - - hci_dev_lock(hdev); - hci_conn_failed(conn, err); - hci_dev_unlock(hdev); - } + hci_conn_failed(conn, reason); =20 +unlock: + hci_dev_unlock(hdev); return err; } =20 static int hci_disconnect_all_sync(struct hci_dev *hdev, u8 reason) { - struct hci_conn *conn, *tmp; - int err; + struct list_head *head =3D &hdev->conn_hash.list; + struct hci_conn *conn; =20 - list_for_each_entry_safe(conn, tmp, &hdev->conn_hash.list, list) { - err =3D hci_abort_conn_sync(hdev, conn, reason); - if (err) - return err; + rcu_read_lock(); + while ((conn =3D list_first_or_null_rcu(head, struct hci_conn, list))) { + /* Make sure the connection is not freed while unlocking */ + conn =3D hci_conn_get(conn); + rcu_read_unlock(); + /* Disregard possible errors since hci_conn_del shall have been + * called even in case of errors had occurred since it would + * then cause hci_conn_failed to be called which calls + * hci_conn_del internally. + */ + hci_abort_conn_sync(hdev, conn, reason); + hci_conn_put(conn); + rcu_read_lock(); } + rcu_read_unlock(); =20 return 0; } --=20 2.39.5 From nobody Thu Sep 24 14:25:41 2026 Received: from mail-dl2-f42.google.com (mail-dl2-f42.google.com [74.125.229.170]) (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 D814947ECC6 for ; Tue, 22 Sep 2026 19:48:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.229.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790106527; cv=none; b=UyDaFUXtmxXZjLbjdjV62eYdTnnx8pvK21FIqRm8to08VZcaYart3FuJkle5SyHu5Rw069xRs7zzlIK3XNNKYP0ynx0ha5j3DDZKYwurvE8dW6UmF1oOZD5LvSMQmPBcvDT9PhPco1vMlsSOfOzf/ngDA1R3lmcfQ+bcPVjH19o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790106527; c=relaxed/simple; bh=pEijDvSbnzNOm0euzfZ8M0Xgpum18qudVoKWgWc48zI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xl7K55Sc6l58bgL3XDFSvTf8Vvxpv2uE2G7KHAHccmFLKYQ+tduPXrxROCiNhAHPipTdw31CHl/8hJKxczKmbJttlfFAGyyQYiFgKKmJvePWdIJ/PJmx0TOuXplYh5xD2f62SX4Y/oyEaMV4VRQrhy8xVzpS7gH40tNW0Ftscp4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com; spf=pass smtp.mailfrom=trailofbits.com; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b=hxi5T9Ql; arc=none smtp.client-ip=74.125.229.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=trailofbits.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=trailofbits.com header.i=@trailofbits.com header.b="hxi5T9Ql" Received: by mail-dl2-f42.google.com with SMTP id a92af1059eb24-144d60be6b0so98600c88.0 for ; Tue, 22 Sep 2026 12:48:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trailofbits.com; s=google; t=1790106525; x=1790711325; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=U0hyw392EUOq/7oRWDEQtoJ6bKtIqDyqp12q5Vya77U=; b=hxi5T9Qlv14xsRHgwQk2IISd3iMKupqOazU77Df6H0M6zFwsL/h70+C7c+RfInofnn Mafy/RsWQf1arY/btZVMEtgcWhqciWnajXXYFeAv6mqa2SAyX6fqct3vZtwUIC1kcKZL /AdcB9M9KCsCREhh5sUpnWDDb/+9vFRDZiEoIPnvPhyP09D+6N8Eeb5JhWTSqDXw3/sU Q2QioWwP3tepRogWLsw4MYv7vpvbgxjaMrslRqIocEJ53+3S4jmEVve0tT0ixzYG20Qg W3ittuP1+5ICdHfGcGHEYqCvIrCD/3v/wh/JGMavgH8pieIWSugcaAOKv10MkGIdSCBD XmKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790106525; x=1790711325; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=U0hyw392EUOq/7oRWDEQtoJ6bKtIqDyqp12q5Vya77U=; b=GEHgK1ca0pq878mXOUjuLs34Echbg/JpepXW2iKSFjua1z7V1XrHoFTMRibhmiJ+67 keCDy7FB598DYds9HdDKu8ZvFMd1u82ZsIJiAnwXYYVc3ThXofxHTZ9Gf6QtLCmdld5h CuHssBWBS1rMdFF/gxIa5VEz2I17mSC3oK1H0pWu3YoG5TAY/cCCQsptbs5V+BjNdhvg +rWccQujmZSzDkMuh/F5AZUFrm9y1dSNQVTKDomKOBs8pwpEe71iPyTO8GaEIHn84qNu 5mZIaxw/QRW/jXIvzhbwrTzNQnyidIztAe1/t8pUypI7mmiO8N6rBZ3e1sXMwUCBpqrE 8wkg== X-Forwarded-Encrypted: i=1; AKwUvBywk5bhJSuoUjQ1NhFll7e45U72yQCPARGQHuHUdcGbhRZ/12rilmg7YkIlsBMKyalYh50Q121HH1EHiRo=@vger.kernel.org X-Gm-Message-State: AFuF++nDm//OghnqDWBI/YYCoR7NI7C1P82GS2X4y7fAbAUQKYoo+eii FfXEqEF0oqSU/HhYZSBekV+jn3VTQ09cwJo0Cz3MqJSVAvPaWMzEDFHF8lFl+zavYwU= X-Gm-Gg: AYBFou3P/YKZ7fuhaakthIFStQM4jhHuexh9lHW/DRqoS0eRus8W3qH6PVKNavnitiS 5AaGqWFGrks0vGXXgr1f8VO7VL0Y4RNivzf0oyPj5ZWc2lRMLygeQkd+v+lJO8DsmXJQGVKhrts MsDSFvYg4rVKlD9xTj3/eM/+kk1SJCpH+MkPdXQSGCnyeoF8YFPuOC4KTotmTAiN80LCfjiMtoa UgECvCJrfYJrXEJEw6/OEcqabM/kc/MKGaoVytGlKInLLOqkK86kKFJORtrwe4iQDuuCz/cFSdz BlAivxpNaWmv7j9KnEBbgDP9fB5Q/PlQ9Sj8rahFjdZgISzHWiwz98dZEx6OFMj43k7opndb1hM 2QiAJju82o5n9RhJvqsuYTku9w3AI1xKbT8U1nYWm3m+9eyop0Ha7nSKaCBADjtC1ZR/z5hnmTh xygyegMVkmwo+Dv9m1AycP6X53mQCAIN6MOaJZtACOuE+Om/x8La6TIOgLUn4AO/qyT9gth3eiW aY4ZQpfzm9tj5OFux7Tb4WvjKIWWyvo8C8G/ZDJstnxdvF6WqK6VIdRBhBc05TMsaCdVo62kCUX AJlNmA== X-Received: by 2002:a05:7022:3a08:b0:143:26ed:2dd5 with SMTP id a92af1059eb24-144f917a486mr532983c88.31.1790106524848; Tue, 22 Sep 2026 12:48:44 -0700 (PDT) Received: from localhost.localdomain ([2603:8001:5f01:8bab:c016:77a6:d382:7611]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-144f98a288esm708550c88.13.2026.09.22.12.48.43 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 22 Sep 2026 12:48:44 -0700 (PDT) From: Artem Dinaburg To: stable@vger.kernel.org Cc: Artem Dinaburg , Greg Kroah-Hartman , Sasha Levin , Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Luiz Augusto von Dentz , Pauli Virtanen Subject: [PATCH 6.1.y 2/2] Bluetooth: hci_sync: always check if connection is alive before deleting Date: Tue, 22 Sep 2026 15:48:34 -0400 Message-ID: <20260922194838.26223-3-artem@trailofbits.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260922194838.26223-1-artem@trailofbits.com> References: <20260922194838.26223-1-artem@trailofbits.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Pauli Virtanen [ Upstream commit a239110ee8e0b0aafa265f0d54f7a16744855e70 ] In hci_abort_conn_sync it is possible that conn is deleted concurrently by something else, also e.g. when waiting for hdev->lock. This causes double deletion of the conn, so UAF or conn_hash.list corruption. Fix by having all code paths check that the connection is still in conn_hash before deleting it, while holding hdev->lock which prevents any races. Log (when powering off while BAP streaming, occurs rarely): =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D kernel BUG at lib/list_debug.c:56! ... ? __list_del_entry_valid (lib/list_debug.c:56) hci_conn_del (net/bluetooth/hci_conn.c:154) bluetooth hci_abort_conn_sync (net/bluetooth/hci_sync.c:5415) bluetooth ? __pfx_hci_abort_conn_sync+0x10/0x10 [bluetooth] ? lock_release+0x1d5/0x3c0 ? hci_disconnect_all_sync.constprop.0+0xb2/0x230 [bluetooth] ? __pfx_lock_release+0x10/0x10 ? __kmem_cache_free+0x14d/0x2e0 hci_disconnect_all_sync.constprop.0+0xda/0x230 [bluetooth] ? __pfx_hci_disconnect_all_sync.constprop.0+0x10/0x10 [bluetooth] ? hci_clear_adv_sync+0x14f/0x170 [bluetooth] ? __pfx_set_powered_sync+0x10/0x10 [bluetooth] hci_set_powered_sync+0x293/0x450 [bluetooth] =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Fixes: 94d9ba9f9888 ("Bluetooth: hci_sync: Fix UAF in hci_disconnect_all_sy= nc") Signed-off-by: Pauli Virtanen Signed-off-by: Luiz Augusto von Dentz [ Backport to 6.1.y follow-up to 94d9ba9f9888: this tree lacks the later BT_OPEN and BT_BOUND special cases, so retain its existing state switch and add the common liveness check. ] Assisted-by: LLM Signed-off-by: Artem Dinaburg --- Stable submission note: patch 2/2 in the CVE-2023-53762 series for Linux 6.1.y. CVE: CVE-2023-53762 Build: This patch was included in an x86_64 allmodconfig and CONFIG_WERROR=3Dy build. It produced vmlinux and modules with no new warnings or errors. net/bluetooth/hci_sync.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index da9e6e55bc1d00..08e90dab73459b 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -5587,6 +5587,7 @@ int hci_abort_conn_sync(struct hci_dev *hdev, struct = hci_conn *conn, u8 reason) { int err =3D 0; u16 handle =3D conn->handle; + bool disconnect =3D false; struct hci_conn *c; =20 switch (conn->state) { @@ -5601,19 +5602,13 @@ int hci_abort_conn_sync(struct hci_dev *hdev, struc= t hci_conn *conn, u8 reason) err =3D hci_reject_conn_sync(hdev, conn, reason); break; default: - hci_dev_lock(hdev); - conn->state =3D BT_CLOSED; - hci_disconn_cfm(conn, reason); - hci_conn_del(conn); - hci_dev_unlock(hdev); - return 0; + disconnect =3D true; + break; } =20 hci_dev_lock(hdev); =20 - /* Check if the connection hasn't been cleanup while waiting - * commands to complete. - */ + /* Check if the connection has been cleaned up concurrently */ c =3D hci_conn_hash_lookup_handle(hdev, handle); if (!c || c !=3D conn) { err =3D 0; @@ -5625,7 +5620,13 @@ int hci_abort_conn_sync(struct hci_dev *hdev, struct= hci_conn *conn, u8 reason) * or in case of LE it was still scanning so it can be cleanup * safely. */ - hci_conn_failed(conn, reason); + if (disconnect) { + conn->state =3D BT_CLOSED; + hci_disconn_cfm(conn, reason); + hci_conn_del(conn); + } else { + hci_conn_failed(conn, reason); + } =20 unlock: hci_dev_unlock(hdev); --=20 2.39.5