Skip to content

Commit 8c4b65f

Browse files
Vudentzgregkh
authored andcommitted
Bluetooth: hci_conn: Fix possible UAF
commit 5dc7d23 upstream. This fixes the following trace: ================================================================== BUG: KASAN: slab-use-after-free in hci_conn_del+0xba/0x3a0 Write of size 8 at addr ffff88800208e9c8 by task iso-tester/31 CPU: 0 PID: 31 Comm: iso-tester Not tainted 6.3.0-rc2-g991aa4a69a47 #4716 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.1-2.fc36 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0x1d/0x70 print_report+0xce/0x610 ? __virt_addr_valid+0xd4/0x150 ? hci_conn_del+0xba/0x3a0 kasan_report+0xdd/0x110 ? hci_conn_del+0xba/0x3a0 hci_conn_del+0xba/0x3a0 hci_conn_hash_flush+0xf2/0x120 hci_dev_close_sync+0x388/0x920 hci_unregister_dev+0x122/0x260 vhci_release+0x4f/0x90 __fput+0x102/0x430 task_work_run+0xf1/0x160 ? __pfx_task_work_run+0x10/0x10 ? mark_held_locks+0x24/0x90 exit_to_user_mode_prepare+0x170/0x180 syscall_exit_to_user_mode+0x19/0x50 do_syscall_64+0x4e/0x90 entry_SYSCALL_64_after_hwframe+0x70/0xda Fixes: 0f00cd3 ("Bluetooth: Free potentially unfreed SCO connection") Link: https://syzkaller.appspot.com/bug?extid=8bb72f86fc823817bc5d Cc: <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 4290d89 commit 8c4b65f

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

net/bluetooth/hci_conn.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,17 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
10511051
return conn;
10521052
}
10531053

1054+
static bool hci_conn_unlink(struct hci_conn *conn)
1055+
{
1056+
if (!conn->link)
1057+
return false;
1058+
1059+
conn->link->link = NULL;
1060+
conn->link = NULL;
1061+
1062+
return true;
1063+
}
1064+
10541065
int hci_conn_del(struct hci_conn *conn)
10551066
{
10561067
struct hci_dev *hdev = conn->hdev;
@@ -1062,15 +1073,16 @@ int hci_conn_del(struct hci_conn *conn)
10621073
cancel_delayed_work_sync(&conn->idle_work);
10631074

10641075
if (conn->type == ACL_LINK) {
1065-
struct hci_conn *sco = conn->link;
1066-
if (sco) {
1067-
sco->link = NULL;
1076+
struct hci_conn *link = conn->link;
1077+
1078+
if (link) {
1079+
hci_conn_unlink(conn);
10681080
/* Due to race, SCO connection might be not established
10691081
* yet at this point. Delete it now, otherwise it is
10701082
* possible for it to be stuck and can't be deleted.
10711083
*/
1072-
if (sco->handle == HCI_CONN_HANDLE_UNSET)
1073-
hci_conn_del(sco);
1084+
if (link->handle == HCI_CONN_HANDLE_UNSET)
1085+
hci_conn_del(link);
10741086
}
10751087

10761088
/* Unacked frames */
@@ -1086,7 +1098,7 @@ int hci_conn_del(struct hci_conn *conn)
10861098
struct hci_conn *acl = conn->link;
10871099

10881100
if (acl) {
1089-
acl->link = NULL;
1101+
hci_conn_unlink(conn);
10901102
hci_conn_drop(acl);
10911103
}
10921104

@@ -2445,6 +2457,12 @@ void hci_conn_hash_flush(struct hci_dev *hdev)
24452457
c->state = BT_CLOSED;
24462458

24472459
hci_disconn_cfm(c, HCI_ERROR_LOCAL_HOST_TERM);
2460+
2461+
/* Unlink before deleting otherwise it is possible that
2462+
* hci_conn_del removes the link which may cause the list to
2463+
* contain items already freed.
2464+
*/
2465+
hci_conn_unlink(c);
24482466
hci_conn_del(c);
24492467
}
24502468
}

0 commit comments

Comments
 (0)