Skip to contentSkip to conversation

monitor: Improbe decoding of ATT Read by Group Type Respose

PATCH In review Luiz Augusto von Dentz 2 participants 5 messages May 24, 2015 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 monitor: Improbe decoding of ATT Read by Group Type Respose

From: Luiz Augusto von Dentz <[email protected]>

The group data is as follow:

Attribute Handle (2 octets) End Group Handle (2 octets) Attribute Value (Length - 4) octets

But since only primary and secondary can be used in ATT Read by Group Type Request the value is garanteed to be a UUID:

< ACL Data TX: Handle 3585 flags 0x00 dlen 24

      ATT: Read By Group Type Response (0x11) len 19
        Attribute data length: 6
        Attribute group list: 3 entries
        Handle range: 0x0001-0x0005
        UUID: Generic Access Profile (0x1800)
        Handle range: 0x0006-0x000d
        UUID: Heart Rate (0x180d)
        Handle range: 0x000e-0x0011
        UUID: Battery Service (0x180f)
---
 monitor/l2cap.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
monitor/l2cap.c +24 -1
index 55efa54..409f5f4 100644
@@ -2217,12 +2217,35 @@ static void att_read_group_type_req(const struct l2cap_frame *frame)
 	print_uuid("Attribute group type", frame->data + 4, frame->size - 4);
 }
 
+static void print_group_list(const char *label, uint8_t length,
+					const void *data, uint16_t size)
+{
+	uint8_t count;
+
+	if (length == 0)
+		return;
+
+	count = size / length;
+
+	print_field("%s: %u entr%s", label, count, count == 1 ? "y" : "ies");
+
+	while (size >= length) {
+		print_handle_range("Handle range", data);
+		print_uuid("UUID", data + 4, length - 4);
+
+		data += length;
+		size -= length;
+	}
+
+	packet_hexdump(data, size);
+}
+
 static void att_read_group_type_rsp(const struct l2cap_frame *frame)
 {
 	const struct bt_l2cap_att_read_group_type_rsp *pdu = frame->data;
 
 	print_field("Attribute data length: %d", pdu->length);
-	print_data_list("Attribute data list", pdu->length,
+	print_group_list("Attribute group list", pdu->length,
 					frame->data + 1, frame->size - 1);
 }
 
Signature · 1 line
2.1.0
#1 lore raw

Hi Luiz,

Quoted 12 lines · Luiz Augusto von Dentz
monitor/l2cap.c +12 -0
+static void print_group_list(const char *label, uint8_t length,
+					const void *data, uint16_t size)
+{
+	uint8_t count;
+
+	if (length == 0)
+		return;
+
+	count = size / length;
+
+	print_field("%s: %u entr%s", label, count, count == 1 ? "y" : "ies");
+

monitor/l2cap.c static void att_read_group_type_req(const struct l2cap_frame *frame) · line 2241

Quoted 10 lines
monitor/l2cap.c +10 -0
+	while (size >= length) {
+		print_handle_range("Handle range", data);
+		print_uuid("UUID", data + 4, length - 4);
+
+		data += length;
+		size -= length;
+	}
+
+	packet_hexdump(data, size);
+}

Looks good, but to avoid btmon crashes (e.g. when analyzing codenomicon logs) might be good to add check for 'length >= 6' and jump to packet_hexdump if you get something smaller than that.

Johan

author maintainer
#2 lore raw

Hi Johan,

Quoted 21 lines · Johan Hedberg

Hi Luiz,

Quoted 18 lines · Luiz Augusto von Dentz
monitor/l2cap.c +18 -0
+static void print_group_list(const char *label, uint8_t length,
+                                     const void *data, uint16_t size)
+{
+     uint8_t count;
+
+     if (length == 0)
+             return;
+
+     count = size / length;
+
+     print_field("%s: %u entr%s", label, count, count == 1 ? "y" : "ies");
+
+     while (size >= length) {
+             print_handle_range("Handle range", data);
+             print_uuid("UUID", data + 4, length - 4);
+
+             data += length;
+             size -= length;
Quoted 8 lines

monitor/l2cap.c static void att_read_group_type_req(const struct l2cap_frame *frame) · line 2241

Quoted 4 lines
monitor/l2cap.c +4 -0
+     }
+
+     packet_hexdump(data, size);
+}

Looks good, but to avoid btmon crashes (e.g. when analyzing codenomicon logs) might be good to add check for 'length >= 6' and jump to packet_hexdump if you get something smaller than that.

print_uuid already does that and we have a check for minimal size of 4 for att_read_group_type_rsp, what I think we really want to check field by field like is done in avctp.c for example, so we get exactly where the pdu is breaking, but to get to that we will have to fix much more than print_group_list

Signature · 1 line
Luiz Augusto von Dentz
#3 lore raw

Hi Luiz,

Quoted 31 lines · Luiz Augusto von Dentz
Quoted 21 lines · Johan Hedberg

Hi Luiz,

Quoted 18 lines · Luiz Augusto von Dentz
monitor/l2cap.c +18 -0
+static void print_group_list(const char *label, uint8_t length,
+                                     const void *data, uint16_t size)
+{
+     uint8_t count;
+
+     if (length == 0)
+             return;
+
+     count = size / length;
+
+     print_field("%s: %u entr%s", label, count, count == 1 ? "y" : "ies");
+
+     while (size >= length) {
+             print_handle_range("Handle range", data);
+             print_uuid("UUID", data + 4, length - 4);
+
+             data += length;
+             size -= length;
Quoted 8 lines

monitor/l2cap.c static void att_read_group_type_req(const struct l2cap_frame *frame) · line 2241

Quoted 4 lines
monitor/l2cap.c +4 -0
+     }
+
+     packet_hexdump(data, size);
+}

Looks good, but to avoid btmon crashes (e.g. when analyzing codenomicon logs) might be good to add check for 'length >= 6' and jump to packet_hexdump if you get something smaller than that.

Quoted 2 lines

print_uuid already does that and we have a check for minimal size of 4 for att_read_group_type_rsp,

I was aware of the checks in print_uuid() but not of the minimum size 4 check that has already happened before entering the print_group_list function. That should indeed be enough protection for buffer overflows.

Quoted 3 lines

what I think we really want to check field by field like is done in avctp.c for example, so we get exactly where the pdu is breaking, but to get to that we will have to fix much more than print_group_list

Sounds reasonable to me.

Johan

#4 lore raw
In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 9 lines · Luiz Augusto von Dentz

The group data is as follow:

Attribute Handle (2 octets) End Group Handle (2 octets) Attribute Value (Length - 4) octets

But since only primary and secondary can be used in ATT Read by Group Type Request the value is garanteed to be a UUID:

< ACL Data TX: Handle 3585 flags 0x00 dlen 24

Quoted 12 lines
      ATT: Read By Group Type Response (0x11) len 19
        Attribute data length: 6
        Attribute group list: 3 entries
        Handle range: 0x0001-0x0005
        UUID: Generic Access Profile (0x1800)
        Handle range: 0x0006-0x000d
        UUID: Heart Rate (0x180d)
        Handle range: 0x000e-0x0011
        UUID: Battery Service (0x180f)
---
 monitor/l2cap.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

Applied now (with s/Improbe/Improve/ to the subject). Thanks.

Johan