Skip to content

Commit

Permalink
Bluetooth: Fix potential double free caused by hci_conn_unlink
Browse files Browse the repository at this point in the history
commit ca1fd42 upstream.

The hci_conn_unlink function is being called by hci_conn_del, which
means it should not call hci_conn_del with the input parameter conn
again. If it does, conn may have already been released when
hci_conn_unlink returns, leading to potential UAF and double-free
issues.

This patch resolves the problem by modifying hci_conn_unlink to release
only conn's child links when necessary, but never release conn itself.

Reported-by: syzbot+690b90b14f14f43f4688@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/linux-bluetooth/000000000000484a8205faafe216@google.com/
Fixes: 0614974 ("Bluetooth: hci_conn: Add support for linking multiple hcon")
Signed-off-by: Ruihan Li <lrh2000@pku.edu.cn>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Reported-by: syzbot+690b90b14f14f43f4688@syzkaller.appspotmail.com
Reported-by: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Reported-by: syzbot+8bb72f86fc823817bc5d@syzkaller.appspotmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
lrh2000 authored and gregkh committed Jun 14, 2023
1 parent e9cb7be commit 75e35bd
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions net/bluetooth/hci_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1088,8 +1088,18 @@ static void hci_conn_unlink(struct hci_conn *conn)
if (!conn->parent) {
struct hci_link *link, *t;

list_for_each_entry_safe(link, t, &conn->link_list, list)
hci_conn_unlink(link->conn);
list_for_each_entry_safe(link, t, &conn->link_list, list) {
struct hci_conn *child = link->conn;

hci_conn_unlink(child);

/* Due to race, SCO connection might be not established
* yet at this point. Delete it now, otherwise it is
* possible for it to be stuck and can't be deleted.
*/
if (child->handle == HCI_CONN_HANDLE_UNSET)
hci_conn_del(child);
}

return;
}
Expand All @@ -1105,13 +1115,6 @@ static void hci_conn_unlink(struct hci_conn *conn)

kfree(conn->link);
conn->link = NULL;

/* Due to race, SCO connection might be not established
* yet at this point. Delete it now, otherwise it is
* possible for it to be stuck and can't be deleted.
*/
if (conn->handle == HCI_CONN_HANDLE_UNSET)
hci_conn_del(conn);
}

int hci_conn_del(struct hci_conn *conn)
Expand Down

0 comments on commit 75e35bd

Please sign in to comment.