Skip to contentSkip to conversation

Bluetooth: Fix for double free of st buffer.

PATCH In review [email protected] 2 participants 5 messages Jul 17, 2012 – Aug 3, 2012 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Bluetooth: Fix for double free of st buffer.

From: Ram Malovany <[email protected]>

When the Shared Transport line discipline driver (st_core) get data it pushes the skb received to the relevant protocol stacks , it then excepts that the relevant protocol stacks should handle the buffer , and if it cannot then the stack should respond with an error. In our case the Bluetooth driver for shared transport (btwilink) should always be able to handle the buffer , in case of an error it will release it , thus we always should return 0.

---
 drivers/bluetooth/btwilink.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
drivers/bluetooth/btwilink.c +8 -4
index 8869469..1f60d84 100644
@@ -94,18 +94,22 @@ static void st_reg_completion_cb(void *priv_data, char data)
 }
 
 /* Called by Shared Transport layer when receive data is
- * available */
+ * available
+ * Return:
+ * 0 if buffer handled (affectivly allways even if error found)
+ * if return !=0 the buffer will be freed by the st
+ */
 static long st_receive(void *priv_data, struct sk_buff *skb)
 {
 	struct ti_st *lhst = priv_data;
 	int err;
 
 	if (!skb)
-		return -EFAULT;
+		return 0;
 
 	if (!lhst) {
 		kfree_skb(skb);
-		return -EFAULT;
+		return 0;
 	}
 
 	skb->dev = (void *) lhst->hdev;
@@ -114,7 +118,7 @@ static long st_receive(void *priv_data, struct sk_buff *skb)
 	err = hci_recv_frame(skb);
 	if (err < 0) {
 		BT_ERR("Unable to push skb to HCI core(%d)", err);
-		return err;
+		return 0;
 	}
 
 	lhst->hdev->stat.byte_rx += skb->len;
Signature · 1 line
1.7.4.1
#1 lore raw

Hi Ram,

Quoted 30 lines · * [email protected] <[email protected]> [2012-07-17 10:49:30 +0300]:

From: Ram Malovany <[email protected]>

When the Shared Transport line discipline driver (st_core) get data it pushes the skb received to the relevant protocol stacks , it then excepts that the relevant protocol stacks should handle the buffer , and if it cannot then the stack should respond with an error. In our case the Bluetooth driver for shared transport (btwilink) should always be able to handle the buffer , in case of an error it will release it , thus we always should return 0.

---
 drivers/bluetooth/btwilink.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
drivers/bluetooth/btwilink.c +5 -1
index 8869469..1f60d84 100644
@@ -94,18 +94,22 @@ static void st_reg_completion_cb(void *priv_data, char data)
 }
 
 /* Called by Shared Transport layer when receive data is
- * available */
+ * available
+ * Return:
+ * 0 if buffer handled (affectivly allways even if error found)
+ * if return !=0 the buffer will be freed by the st
+ */
 static long st_receive(void *priv_data, struct sk_buff *skb)

drivers/bluetooth/btwilink.c static void st_reg_completion_cb(void *priv_data, char data) · line 111

Quoted 10 lines
drivers/bluetooth/btwilink.c +1 -1
 {
 	struct ti_st *lhst = priv_data;
 	int err;
 
 	if (!skb)
-		return -EFAULT;
+		return 0;
 
 	if (!lhst) {
 		kfree_skb(skb);

If you remove this call to kfree_skb() from here doesn't it fixes your problem?

Gustavo

#2 lore raw

HI Gustavo,

Quoted 50 lines

-----Original Message-----
From: Gustavo Padovan [mailto:[email protected]]
Sent: Wednesday, July 25, 2012 2:01 AM
To: Malovany, Ram
Cc: [email protected]
Subject: Re: [PATCH] Bluetooth: Fix for double free of st buffer.

Hi Ram,

drivers/bluetooth/btwilink.c static void st_reg_completion_cb(void *priv_data, char

Quoted 20 lines · * [email protected] <[email protected]> [2012-07-17 10:49:30 +0300]:

From: Ram Malovany <[email protected]>

When the Shared Transport line discipline driver (st_core) get data it pushes the skb received to the relevant protocol stacks , it then excepts that the relevant protocol stacks should handle the buffer , and if it cannot then the stack should respond with an error. In our case the Bluetooth driver for shared transport (btwilink) should always be able to handle the buffer , in case of an error it will release it , thus we always should return 0.

---
 drivers/bluetooth/btwilink.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
drivers/bluetooth/btwilink.c +0 -0
index 8869469..1f60d84 100644
@@ -94,18 +94,22 @@ static void st_reg_completion_cb(void *priv_data, char

data)

Quoted 18 lines
drivers/bluetooth/btwilink.c +6 -2
 }
 
 /* Called by Shared Transport layer when receive data is
- * available */
+ * available
+ * Return:
+ * 0 if buffer handled (affectivly allways even if error found)
+ * if return !=0 the buffer will be freed by the st
+ */
 static long st_receive(void *priv_data, struct sk_buff *skb)
 {
 	struct ti_st *lhst = priv_data;
 	int err;
 
 	if (!skb)
-		return -EFAULT;
+		return 0;
 
Quoted 7 lines

drivers/bluetooth/btwilink.c static void st_reg_completion_cb(void *priv_data, char data) · line 111

Quoted 2 lines
drivers/bluetooth/btwilink.c +0 -0
 	if (!lhst) {
 		kfree_skb(skb);

If you remove this call to kfree_skb() from here doesn't it fixes your problem?

Gustavo

You are correct , I was going to send a new version for this patch.

Thanks,
Ram

#3 lore raw
In reply to Gustavo Padovan

HI Gustavo,

Quoted 7 lines

-----Original Message-----
From: Malovany, Ram
Sent: Wednesday, July 25, 2012 11:01 AM
To: 'Gustavo Padovan'
Cc: [email protected]
Subject: RE: [PATCH] Bluetooth: Fix for double free of st buffer.

Quoted 59 lines

HI Gustavo,

Quoted 57 lines

-----Original Message-----
From: Gustavo Padovan [mailto:[email protected]]
Sent: Wednesday, July 25, 2012 2:01 AM
To: Malovany, Ram
Cc: [email protected]
Subject: Re: [PATCH] Bluetooth: Fix for double free of st buffer.

Hi Ram,

drivers/bluetooth/btwilink.c static void st_reg_completion_cb(void *priv_data, char

Quoted 20 lines · * [email protected] <[email protected]> [2012-07-17 10:49:30 +0300]:

From: Ram Malovany <[email protected]>

When the Shared Transport line discipline driver (st_core) get data it pushes the skb received to the relevant protocol stacks , it then excepts that the relevant protocol stacks should handle the buffer , and if it cannot then the stack should respond with an error. In our case the Bluetooth driver for shared transport (btwilink) should always be able to handle the buffer , in case of an error it will release it , thus we always should return 0.

---
 drivers/bluetooth/btwilink.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
drivers/bluetooth/btwilink.c +0 -0
index 8869469..1f60d84 100644
@@ -94,18 +94,22 @@ static void st_reg_completion_cb(void *priv_data, char

data)

Quoted 10 lines
drivers/bluetooth/btwilink.c +5 -1
 }
 
 /* Called by Shared Transport layer when receive data is
- * available */
+ * available
+ * Return:
+ * 0 if buffer handled (affectivly allways even if error found)
+ * if return !=0 the buffer will be freed by the st
+ */
 static long st_receive(void *priv_data, struct sk_buff *skb)

drivers/bluetooth/btwilink.c static void st_reg_completion_cb(void *priv_data, char data) · line 111

Quoted 10 lines
drivers/bluetooth/btwilink.c +1 -1
 {
 	struct ti_st *lhst = priv_data;
 	int err;
 
 	if (!skb)
-		return -EFAULT;
+		return 0;
 
 	if (!lhst) {
 		kfree_skb(skb);

If you remove this call to kfree_skb() from here doesn't it fixes your problem?

Gustavo

I looked at the fix again , and I think we shouldn't change it since the main problem that I am observing her is not the kfree_skb() at this point , The problem is related to who is in charge of the buffer at this point , and in our case the function hci_recv_frame() can use different transports and upon an error it will free the buffer as well , in my fix I made sure that st_receive() will always take care of the buffer.

Quoted 5 lines

You are correct , I was going to send a new version for this patch.

Thanks,
Ram

#4 lore raw
In reply to Gustavo Padovan

Ping

Quoted 87 lines

-----Original Message-----
From: Malovany, Ram
Sent: Wednesday, July 25, 2012 11:31 AM
To: 'Gustavo Padovan'
Cc: '[email protected]'
Subject: RE: [PATCH] Bluetooth: Fix for double free of st buffer.

HI Gustavo,

Quoted 7 lines

-----Original Message-----
From: Malovany, Ram
Sent: Wednesday, July 25, 2012 11:01 AM
To: 'Gustavo Padovan'
Cc: [email protected]
Subject: RE: [PATCH] Bluetooth: Fix for double free of st buffer.

Quoted 19 lines

HI Gustavo,

Quoted 17 lines

-----Original Message-----
From: Gustavo Padovan [mailto:[email protected]]
Sent: Wednesday, July 25, 2012 2:01 AM
To: Malovany, Ram
Cc: [email protected]
Subject: Re: [PATCH] Bluetooth: Fix for double free of st buffer.

Hi Ram,

Quoted 6 lines · * [email protected] <[email protected]> [2012-07-17 10:49:30 +0300]:

From: Ram Malovany <[email protected]>

When the Shared Transport line discipline driver (st_core) get data it pushes the skb received to the relevant protocol stacks , it then excepts that the relevant protocol stacks should handle the buffer , and if it cannot then the stack should respond with an

error.

Quoted 32 lines
Quoted 32 lines
Quoted 14 lines

In our case the Bluetooth driver for shared transport (btwilink) should always be able to handle the buffer , in case of an error it will release it , thus we always should return 0.

---
 drivers/bluetooth/btwilink.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/bluetooth/btwilink.c index 8869469..1f60d84 100644

drivers/bluetooth/btwilink.c static void st_reg_completion_cb(void · line 94

Quoted 1 line
drivers/bluetooth/btwilink.c +0 -0
@@ -94,18 +94,22 @@ static void st_reg_completion_cb(void
 *priv_data, char

data)

Quoted 16 lines
drivers/bluetooth/btwilink.c +5 -2
 }
 
 /* Called by Shared Transport layer when receive data is
- * available */
+ * available
+ * Return:
+ * 0 if buffer handled (affectivly allways even if error found)
+ * if return !=0 the buffer will be freed by the st */
 static long st_receive(void *priv_data, struct sk_buff *skb)  {
 	struct ti_st *lhst = priv_data;
 	int err;
 
 	if (!skb)
-		return -EFAULT;
+		return 0;
 
Quoted 7 lines
Quoted 7 lines

drivers/bluetooth/btwilink.c static void st_reg_completion_cb(void *priv_data, char data) · line 111

Quoted 2 lines
drivers/bluetooth/btwilink.c +0 -0
 	if (!lhst) {
 		kfree_skb(skb);

If you remove this call to kfree_skb() from here doesn't it fixes your problem?

Gustavo

I looked at the fix again , and I think we shouldn't change it since the main problem that I am observing her is not the kfree_skb() at this point , The problem is related to who is in charge of the buffer at this point , and in our case the function hci_recv_frame() can use different transports and upon an error it will free the buffer as well , in my fix I made sure that st_receive() will always take care of the buffer.

Quoted 5 lines

You are correct , I was going to send a new version for this patch.

Thanks,
Ram