All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Bluetooth: Don't increment twice in eir_has_data_type()
@ 2012-03-26 11:21 johan.hedberg
  2012-03-26 11:21 ` [PATCH 2/2] Bluetooth: Check for minimum data length " johan.hedberg
  2012-03-26 11:47 ` [PATCH 1/2] Bluetooth: Don't increment twice " Marcel Holtmann
  0 siblings, 2 replies; 5+ messages in thread
From: johan.hedberg @ 2012-03-26 11:21 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

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).

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci_core.h |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 8dc07fa..83cd301 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -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;
-- 
1.7.9.1


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

* [PATCH 2/2] Bluetooth: Check for minimum data length in eir_has_data_type()
  2012-03-26 11:21 [PATCH 1/2] Bluetooth: Don't increment twice in eir_has_data_type() johan.hedberg
@ 2012-03-26 11:21 ` johan.hedberg
  2012-03-26 11:48   ` Marcel Holtmann
  2012-03-27 16:02   ` Gustavo Padovan
  2012-03-26 11:47 ` [PATCH 1/2] Bluetooth: Don't increment twice " Marcel Holtmann
  1 sibling, 2 replies; 5+ messages in thread
From: johan.hedberg @ 2012-03-26 11:21 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

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.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci_core.h |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 83cd301..fa2c778 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -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];
 
-- 
1.7.9.1


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

* Re: [PATCH 1/2] Bluetooth: Don't increment twice in eir_has_data_type()
  2012-03-26 11:21 [PATCH 1/2] Bluetooth: Don't increment twice in eir_has_data_type() johan.hedberg
  2012-03-26 11:21 ` [PATCH 2/2] Bluetooth: Check for minimum data length " johan.hedberg
@ 2012-03-26 11:47 ` Marcel Holtmann
  1 sibling, 0 replies; 5+ messages in thread
From: Marcel Holtmann @ 2012-03-26 11:47 UTC (permalink / raw)
  To: johan.hedberg; +Cc: linux-bluetooth

Hi Johan,

> 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).
> 
> Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
>  include/net/bluetooth/hci_core.h |    7 +++----
>  1 files changed, 3 insertions(+), 4 deletions(-)

Acked-by: Marcel Holtmann <marcel@holtmann.org>

Regards

Marcel



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

* Re: [PATCH 2/2] Bluetooth: Check for minimum data length in eir_has_data_type()
  2012-03-26 11:21 ` [PATCH 2/2] Bluetooth: Check for minimum data length " johan.hedberg
@ 2012-03-26 11:48   ` Marcel Holtmann
  2012-03-27 16:02   ` Gustavo Padovan
  1 sibling, 0 replies; 5+ messages in thread
From: Marcel Holtmann @ 2012-03-26 11:48 UTC (permalink / raw)
  To: johan.hedberg; +Cc: linux-bluetooth

Hi Johan,

> 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.
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
>  include/net/bluetooth/hci_core.h |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)

Acked-by: Marcel Holtmann <marcel@holtmann.org>

Regards

Marcel



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

* Re: [PATCH 2/2] Bluetooth: Check for minimum data length in eir_has_data_type()
  2012-03-26 11:21 ` [PATCH 2/2] Bluetooth: Check for minimum data length " johan.hedberg
  2012-03-26 11:48   ` Marcel Holtmann
@ 2012-03-27 16:02   ` Gustavo Padovan
  1 sibling, 0 replies; 5+ messages in thread
From: Gustavo Padovan @ 2012-03-27 16:02 UTC (permalink / raw)
  To: johan.hedberg; +Cc: linux-bluetooth

Hi Johan,

* johan.hedberg@gmail.com <johan.hedberg@gmail.com> [2012-03-26 14:21:42 +0300]:

> From: Johan Hedberg <johan.hedberg@intel.com>
> 
> 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.
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
>  include/net/bluetooth/hci_core.h |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)

I applied both patches to bluetooth-next

	Gustavo

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

end of thread, other threads:[~2012-03-27 16:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-26 11:21 [PATCH 1/2] Bluetooth: Don't increment twice in eir_has_data_type() johan.hedberg
2012-03-26 11:21 ` [PATCH 2/2] Bluetooth: Check for minimum data length " johan.hedberg
2012-03-26 11:48   ` Marcel Holtmann
2012-03-27 16:02   ` Gustavo Padovan
2012-03-26 11:47 ` [PATCH 1/2] Bluetooth: Don't increment twice " Marcel Holtmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.