Netdev Archive on
help / color / mirror / Atom feed
* [PATCH v2] Bluetooth: skip invalid hci_sync_conn_complete_evt
@ 2021-07-28  7:51 Desmond Cheong Zhi Xi
  2021-07-29 11:38 ` Marcel Holtmann
  0 siblings, 1 reply; 2+ messages in thread
From: Desmond Cheong Zhi Xi @ 2021-07-28  7:51 UTC (permalink / raw)
  To: marcel, johan.hedberg, luiz.dentz, davem, kuba
  Cc: Desmond Cheong Zhi Xi, linux-bluetooth, netdev, linux-kernel,
	skhan, gregkh, linux-kernel-mentees, syzbot+66264bf2fd0476be7e6c

Syzbot reported a corrupted list in kobject_add_internal [1]. This
happens when multiple HCI_EV_SYNC_CONN_COMPLETE event packets with
status 0 are sent for the same HCI connection. This causes us to
register the device more than once which corrupts the kset list.

As this is forbidden behavior, we add a check for whether we're
trying to process the same HCI_EV_SYNC_CONN_COMPLETE event multiple
times for one connection. If that's the case, the event is invalid, so
we report an error that the device is misbehaving, and ignore the

Link: [1]
Signed-off-by: Desmond Cheong Zhi Xi <>

v1 -> v2:
- Added more comments to explain the reasoning behind the new check, and
a bt_dev_err message upon detecting the invalid event. As suggested by
Marcel Holtmann.

 net/bluetooth/hci_event.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 016b2999f219..a6df4f9d2c23 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -4373,6 +4373,22 @@ static void hci_sync_conn_complete_evt(struct hci_dev *hdev,
 	switch (ev->status) {
 	case 0x00:
+		/* The synchronous connection complete event should only be
+		 * sent once per new connection. Receiving a successful
+		 * complete event when the connection status is already
+		 * BT_CONNECTED means that the device is misbehaving and sent
+		 * multiple complete event packets for the same new connection.
+		 *
+		 * Registering the device more than once can corrupt kernel
+		 * memory, hence upon detecting this invalid event, we report
+		 * an error and ignore the packet.
+		 */
+		if (conn->state == BT_CONNECTED) {
+			bt_dev_err(hdev,
+				   "received multiple HCI_EV_SYNC_CONN_COMPLETE events with status 0 for conn %p",
+				   conn);
+			goto unlock;
+		}
 		conn->handle = __le16_to_cpu(ev->handle);
 		conn->state  = BT_CONNECTED;
 		conn->type   = ev->link_type;

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-29 11:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-28  7:51 [PATCH v2] Bluetooth: skip invalid hci_sync_conn_complete_evt Desmond Cheong Zhi Xi
2021-07-29 11:38 ` Marcel Holtmann

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox