All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: Fix use after free in l2cap_chan_timeout
@ 2015-03-19  8:19 Harish Jenny K N
  2015-03-19  8:25 ` Johan Hedberg
  2015-03-19 14:59 ` Sergei Shtylyov
  0 siblings, 2 replies; 8+ messages in thread
From: Harish Jenny K N @ 2015-03-19  8:19 UTC (permalink / raw)
  To: marcel
  Cc: gustavo, johan.hedberg, davem, linux-bluetooth, netdev,
	linux-kernel, harish_kandiga

There is a potential use after free in bt_sock_poll when a
socket gets killed without getting unlinked from accept_q.
Hence added code to unlink from accpept_q by calling teardown
before freeing the socket for channel type L2CAP_CHAN_CONN_ORIENTED.

Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
---
 net/bluetooth/l2cap_core.c |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 6ba33f9..c6955fb 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -415,6 +415,11 @@ static void l2cap_chan_timeout(struct work_struct *work)
 
 	l2cap_chan_close(chan, reason);
 
+	if ((chan->state == BT_CONNECTED || chan->state == BT_CONFIG) &&
+	    chan->chan_type == L2CAP_CHAN_CONN_ORIENTED) {
+		chan->ops->teardown(chan, 0);
+	}
+
 	l2cap_chan_unlock(chan);
 
 	chan->ops->close(chan);
-- 
1.7.9.5


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

* Re: [PATCH] Bluetooth: Fix use after free in l2cap_chan_timeout
  2015-03-19  8:19 [PATCH] Bluetooth: Fix use after free in l2cap_chan_timeout Harish Jenny K N
@ 2015-03-19  8:25 ` Johan Hedberg
  2015-03-19  8:57   ` Harish Jenny Kandiga Nagaraj
  2015-03-19  8:59   ` Harish Jenny Kandiga Nagaraj
  2015-03-19 14:59 ` Sergei Shtylyov
  1 sibling, 2 replies; 8+ messages in thread
From: Johan Hedberg @ 2015-03-19  8:25 UTC (permalink / raw)
  To: Harish Jenny K N; +Cc: linux-bluetooth

Hi,

On Thu, Mar 19, 2015, Harish Jenny K N wrote:
> There is a potential use after free in bt_sock_poll when a
> socket gets killed without getting unlinked from accept_q.
> Hence added code to unlink from accpept_q by calling teardown
> before freeing the socket for channel type L2CAP_CHAN_CONN_ORIENTED.
> 
> Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
> ---
>  net/bluetooth/l2cap_core.c |    5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
> index 6ba33f9..c6955fb 100644
> --- a/net/bluetooth/l2cap_core.c
> +++ b/net/bluetooth/l2cap_core.c
> @@ -415,6 +415,11 @@ static void l2cap_chan_timeout(struct work_struct *work)
>  
>  	l2cap_chan_close(chan, reason);
>  
> +	if ((chan->state == BT_CONNECTED || chan->state == BT_CONFIG) &&
> +	    chan->chan_type == L2CAP_CHAN_CONN_ORIENTED) {
> +		chan->ops->teardown(chan, 0);
> +	}

Looks quite ok to me, except for a minor issue: we generally don't use
{} for single-line branches.

Do you have some simple way to reproduce this? It'd be nice if we could
add a test case for it to our user space l2cap-tester tool.

Johan

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

* Re: [PATCH] Bluetooth: Fix use after free in l2cap_chan_timeout
  2015-03-19  8:25 ` Johan Hedberg
@ 2015-03-19  8:57   ` Harish Jenny Kandiga Nagaraj
  2015-03-19  8:59   ` Harish Jenny Kandiga Nagaraj
  1 sibling, 0 replies; 8+ messages in thread
From: Harish Jenny Kandiga Nagaraj @ 2015-03-19  8:57 UTC (permalink / raw)
  To: linux-bluetooth



On Thursday 19 March 2015 01:55 PM, Johan Hedberg wrote:
> Hi,
>
> On Thu, Mar 19, 2015, Harish Jenny K N wrote:
>> There is a potential use after free in bt_sock_poll when a
>> socket gets killed without getting unlinked from accept_q.
>> Hence added code to unlink from accpept_q by calling teardown
>> before freeing the socket for channel type L2CAP_CHAN_CONN_ORIENTED.
>>
>> Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
>> ---
>>  net/bluetooth/l2cap_core.c |    5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
>> index 6ba33f9..c6955fb 100644
>> --- a/net/bluetooth/l2cap_core.c
>> +++ b/net/bluetooth/l2cap_core.c
>> @@ -415,6 +415,11 @@ static void l2cap_chan_timeout(struct work_struct *work)
>>  
>>  	l2cap_chan_close(chan, reason);
>>  
>> +	if ((chan->state == BT_CONNECTED || chan->state == BT_CONFIG) &&
>> +	    chan->chan_type == L2CAP_CHAN_CONN_ORIENTED) {
>> +		chan->ops->teardown(chan, 0);
>> +	}
> Looks quite ok to me, except for a minor issue: we generally don't use
> {} for single-line branches.
>
> Do you have some simple way to reproduce this? It'd be nice if we could
> add a test case for it to our user space l2cap-tester tool.
>
> Johan

There is a potential use after free in bt_sock_poll when a
socket gets killed without getting unlinked from accept_q.
Hence added code to unlink from accpept_q by calling teardown
before freeing the socket for channel type L2CAP_CHAN_CONN_ORIENTED.

Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
---
 net/bluetooth/l2cap_core.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 6ba33f9..3e273e6 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -415,6 +415,10 @@ static void l2cap_chan_timeout(struct work_struct *work)
 
 	l2cap_chan_close(chan, reason);
 
+	if ((chan->state == BT_CONNECTED || chan->state == BT_CONFIG) &&
+	    chan->chan_type == L2CAP_CHAN_CONN_ORIENTED)
+		chan->ops->teardown(chan, 0);
+
 	l2cap_chan_unlock(chan);
 
 	chan->ops->close(chan);



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

* Re: [PATCH] Bluetooth: Fix use after free in l2cap_chan_timeout
  2015-03-19  8:25 ` Johan Hedberg
  2015-03-19  8:57   ` Harish Jenny Kandiga Nagaraj
@ 2015-03-19  8:59   ` Harish Jenny Kandiga Nagaraj
  1 sibling, 0 replies; 8+ messages in thread
From: Harish Jenny Kandiga Nagaraj @ 2015-03-19  8:59 UTC (permalink / raw)
  To: linux-bluetooth



On Thursday 19 March 2015 01:55 PM, Johan Hedberg wrote:
> Hi,
>
> On Thu, Mar 19, 2015, Harish Jenny K N wrote:
>> There is a potential use after free in bt_sock_poll when a
>> socket gets killed without getting unlinked from accept_q.
>> Hence added code to unlink from accpept_q by calling teardown
>> before freeing the socket for channel type L2CAP_CHAN_CONN_ORIENTED.
>>
>> Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
>> ---
>>  net/bluetooth/l2cap_core.c |    5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
>> index 6ba33f9..c6955fb 100644
>> --- a/net/bluetooth/l2cap_core.c
>> +++ b/net/bluetooth/l2cap_core.c
>> @@ -415,6 +415,11 @@ static void l2cap_chan_timeout(struct work_struct *work)
>>  
>>  	l2cap_chan_close(chan, reason);
>>  
>> +	if ((chan->state == BT_CONNECTED || chan->state == BT_CONFIG) &&
>> +	    chan->chan_type == L2CAP_CHAN_CONN_ORIENTED) {
>> +		chan->ops->teardown(chan, 0);
>> +	}
> Looks quite ok to me, except for a minor issue: we generally don't use
> {} for single-line branches.
>
> Do you have some simple way to reproduce this? It'd be nice if we could
> add a test case for it to our user space l2cap-tester tool.
>
> Johan
Unfortunately no. The crash happened only once in automated test set-up.
Have given only the proposed solution based on the code flow.
Please check from protocol perspective if this patch is correct and useful.

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

* Re: [PATCH] Bluetooth: Fix use after free in l2cap_chan_timeout
  2015-03-19  8:19 [PATCH] Bluetooth: Fix use after free in l2cap_chan_timeout Harish Jenny K N
  2015-03-19  8:25 ` Johan Hedberg
@ 2015-03-19 14:59 ` Sergei Shtylyov
  1 sibling, 0 replies; 8+ messages in thread
From: Sergei Shtylyov @ 2015-03-19 14:59 UTC (permalink / raw)
  To: Harish Jenny K N, marcel
  Cc: gustavo, johan.hedberg, davem, linux-bluetooth, netdev, linux-kernel

Hello.

On 3/19/2015 11:19 AM, Harish Jenny K N wrote:

> There is a potential use after free in bt_sock_poll when a
> socket gets killed without getting unlinked from accept_q.
> Hence added code to unlink from accpept_q by calling teardown
> before freeing the socket for channel type L2CAP_CHAN_CONN_ORIENTED.

> Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
> ---
>   net/bluetooth/l2cap_core.c |    5 +++++
>   1 file changed, 5 insertions(+)

> diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
> index 6ba33f9..c6955fb 100644
> --- a/net/bluetooth/l2cap_core.c
> +++ b/net/bluetooth/l2cap_core.c
> @@ -415,6 +415,11 @@ static void l2cap_chan_timeout(struct work_struct *work)
>
>   	l2cap_chan_close(chan, reason);
>
> +	if ((chan->state == BT_CONNECTED || chan->state == BT_CONFIG) &&
> +	    chan->chan_type == L2CAP_CHAN_CONN_ORIENTED) {
> +		chan->ops->teardown(chan, 0);
> +	}
> +

    {} not needed here.

[...]

WBR, Sergei


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

* [PATCH] Bluetooth: Fix use after free in l2cap_chan_timeout
@ 2015-03-26  9:10 Harish Jenny K N
  0 siblings, 0 replies; 8+ messages in thread
From: Harish Jenny K N @ 2015-03-26  9:10 UTC (permalink / raw)
  To: marcel; +Cc: gustavo, johan.hedberg, davem, linux-bluetooth, harish_kandiga

There is a potential use after free in bt_sock_poll when a
socket gets killed without getting unlinked from accept_q.
Hence added code to unlink from accpept_q by calling teardown
before freeing the socket for channel type L2CAP_CHAN_CONN_ORIENTED.

Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
---
 net/bluetooth/l2cap_core.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 6ba33f9..3e273e6 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -415,6 +415,10 @@ static void l2cap_chan_timeout(struct work_struct *work)
 
 	l2cap_chan_close(chan, reason);
 
+	if ((chan->state == BT_CONNECTED || chan->state == BT_CONFIG) &&
+	    chan->chan_type == L2CAP_CHAN_CONN_ORIENTED)
+		chan->ops->teardown(chan, 0);
+
 	l2cap_chan_unlock(chan);
 
 	chan->ops->close(chan);
-- 
1.7.9.5

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

* Re: [PATCH] Bluetooth: Fix use after free in l2cap_chan_timeout
  2015-03-18 11:59 Harish Jenny K N
@ 2015-03-18 14:22 ` Sergei Shtylyov
  0 siblings, 0 replies; 8+ messages in thread
From: Sergei Shtylyov @ 2015-03-18 14:22 UTC (permalink / raw)
  To: Harish Jenny K N, marcel
  Cc: gustavo, johan.hedberg, davem, linux-bluetooth, netdev, linux-kernel

Hello.

On 3/18/2015 2:59 PM, Harish Jenny K N wrote:

> There is a potential use after free in bt_sock_poll when a
> socket gets killed without getting unlinked from accept_q.
> Hence added code to unlink from accpept_q by calling teardown
> before freeing the socket for channel type L2CAP_CHAN_CONN_ORIENTED.

> Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
> ---
>   net/bluetooth/l2cap_core.c |    5 +++++
>   1 file changed, 5 insertions(+)

> diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
> index 6ba33f9..3c3421e 100644
> --- a/net/bluetooth/l2cap_core.c
> +++ b/net/bluetooth/l2cap_core.c
> @@ -415,6 +415,11 @@ static void l2cap_chan_timeout(struct work_struct *work)
>
>   	l2cap_chan_close(chan, reason);
>
> +	if (((chan->state == BT_CONNECTED) || (chan->state == BT_CONFIG)) &&

    Note that parens around == are unnecessary.

> +	    chan->chan_type == L2CAP_CHAN_CONN_ORIENTED) {
> +		chan->ops->teardown(chan, 0);
> +	}
> +
[...]

WBR, Sergei


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

* [PATCH] Bluetooth: Fix use after free in l2cap_chan_timeout
@ 2015-03-18 11:59 Harish Jenny K N
  2015-03-18 14:22 ` Sergei Shtylyov
  0 siblings, 1 reply; 8+ messages in thread
From: Harish Jenny K N @ 2015-03-18 11:59 UTC (permalink / raw)
  To: marcel
  Cc: gustavo, johan.hedberg, davem, linux-bluetooth, netdev, linux-kernel

There is a potential use after free in bt_sock_poll when a
socket gets killed without getting unlinked from accept_q.
Hence added code to unlink from accpept_q by calling teardown
before freeing the socket for channel type L2CAP_CHAN_CONN_ORIENTED.

Signed-off-by: Harish Jenny K N <harish_kandiga@mentor.com>
---
 net/bluetooth/l2cap_core.c |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 6ba33f9..3c3421e 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -415,6 +415,11 @@ static void l2cap_chan_timeout(struct work_struct *work)
 
 	l2cap_chan_close(chan, reason);
 
+	if (((chan->state == BT_CONNECTED) || (chan->state == BT_CONFIG)) &&
+	    chan->chan_type == L2CAP_CHAN_CONN_ORIENTED) {
+		chan->ops->teardown(chan, 0);
+	}
+
 	l2cap_chan_unlock(chan);
 
 	chan->ops->close(chan);
-- 
1.7.9.5


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

end of thread, other threads:[~2015-03-26  9:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-19  8:19 [PATCH] Bluetooth: Fix use after free in l2cap_chan_timeout Harish Jenny K N
2015-03-19  8:25 ` Johan Hedberg
2015-03-19  8:57   ` Harish Jenny Kandiga Nagaraj
2015-03-19  8:59   ` Harish Jenny Kandiga Nagaraj
2015-03-19 14:59 ` Sergei Shtylyov
  -- strict thread matches above, loose matches on Subject: below --
2015-03-26  9:10 Harish Jenny K N
2015-03-18 11:59 Harish Jenny K N
2015-03-18 14:22 ` Sergei Shtylyov

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.