Skip to contentSkip to conversation

Bluetooth: Don't increment twice in eir_has_data_type()

PATCH Applied [email protected] 3 participants 5 messages Mar 26, 2012 – Mar 27, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Bluetooth: Don't increment twice in eir_has_data_type()

From: Johan Hedberg <[email protected]>

The parsed variable is already incremented inside the for-loop so there no need to increment it again (not to mention that the code was incrementing it the wrong amount).

---
 include/net/bluetooth/hci_core.h |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)
include/net/bluetooth/hci_core.h +3 -4
index 8dc07fa..83cd301 100644
@@ -911,11 +911,10 @@ static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status,
 
 static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type)
 {
-	u8 field_len;
-	size_t parsed;
+	size_t parsed = 0;
 
-	for (parsed = 0; parsed < data_len - 1; parsed += field_len) {
-		field_len = data[0];
+	while (parsed < data_len - 1) {
+		u8 field_len = data[0];
 
 		if (field_len == 0)
 			break;
Signature · 1 line
1.7.9.1
#1 lore raw

PATCH 2/2 Bluetooth: Check for minimum data length in eir_has_data_type()

From: Johan Hedberg <[email protected]>

If passed 0 as data_length the (parsed < data_length - 1) test will be true and cause a buffer overflow. In practice we need at least two bytes for the element length and type so add a test for it to the very beginning of the function.

---
 include/net/bluetooth/hci_core.h |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
include/net/bluetooth/hci_core.h +3 -0
index 83cd301..fa2c778 100644
@@ -913,6 +913,9 @@ static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type)
 {
 	size_t parsed = 0;
 
+	if (data_len < 2)
+		return false;
+
 	while (parsed < data_len - 1) {
 		u8 field_len = data[0];
 
Signature · 1 line
1.7.9.1
maintainer Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] Bluetooth: Check for minimum data length in eir_has_data_type()

Hi Johan,

Quoted 9 lines

If passed 0 as data_length the (parsed < data_length - 1) test will be true and cause a buffer overflow. In practice we need at least two bytes for the element length and type so add a test for it to the very beginning of the function.

---
 include/net/bluetooth/hci_core.h |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

Regards

Marcel

#3 lore raw

Re: [PATCH 2/2] Bluetooth: Check for minimum data length in eir_has_data_type()

In reply to [email protected]

Hi Johan,

Quoted 11 lines · * [email protected] <[email protected]> [2012-03-26 14:21:42 +0300]:

From: Johan Hedberg <[email protected]>

If passed 0 as data_length the (parsed < data_length - 1) test will be true and cause a buffer overflow. In practice we need at least two bytes for the element length and type so add a test for it to the very beginning of the function.

---
 include/net/bluetooth/hci_core.h |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

I applied both patches to bluetooth-next

Gustavo

maintainer Acked-by on v1 1/2
#4 lore raw
In reply to [email protected]

Hi Johan,

Quoted 9 lines

The parsed variable is already incremented inside the for-loop so there no need to increment it again (not to mention that the code was incrementing it the wrong amount).

---
 include/net/bluetooth/hci_core.h |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

Regards

Marcel