2013-11-05 07:02:24

by Seung-Woo Kim

[permalink] [raw]
Subject: [PATCH] Bluetooth: Fix RFCOMM bind fail for L2CAP sock

L2CAP socket bind checks its bdaddr type but RFCOMM kernel thread
does not assign proper bdaddr type for L2CAP sock. This can cause
that RFCOMM failure.

Signed-off-by: Seung-Woo Kim <[email protected]>
---
The issue is came from following commit, but it is only in bluetooth-next tree,
so this patch is not needed for stable tree.

commit 80c1a2e76dbb36588facb265ab364b1302f7ef8c
Author: Johan Hedberg <[email protected]>
Date: Mon Oct 14 21:17:52 2013 +0300

Bluetooth: Reject invalid bdaddr types for sockets

This patch is based on commit cca34b785a21d220176038c45071ffe842e99fd3 of
bluetooth-next tree.
---
net/bluetooth/rfcomm/core.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c
index 94d06cb..ca55ea1 100644
--- a/net/bluetooth/rfcomm/core.c
+++ b/net/bluetooth/rfcomm/core.c
@@ -694,6 +694,7 @@ static struct rfcomm_session *rfcomm_session_create(bdaddr_t *src,
addr.l2_family = AF_BLUETOOTH;
addr.l2_psm = 0;
addr.l2_cid = 0;
+ addr.l2_bdaddr_type = BDADDR_BREDR;
*err = kernel_bind(sock, (struct sockaddr *) &addr, sizeof(addr));
if (*err < 0)
goto failed;
@@ -1983,6 +1984,7 @@ static int rfcomm_add_listener(bdaddr_t *ba)
addr.l2_family = AF_BLUETOOTH;
addr.l2_psm = __constant_cpu_to_le16(RFCOMM_PSM);
addr.l2_cid = 0;
+ addr.l2_bdaddr_type = BDADDR_BREDR;
err = kernel_bind(sock, (struct sockaddr *) &addr, sizeof(addr));
if (err < 0) {
BT_ERR("Bind failed %d", err);
--
1.7.4.1


2013-11-05 12:07:43

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH] Bluetooth: Fix to set proper bdaddr_type for RFCOMM connect

Hi Seung-Woo,

> L2CAP socket validates proper bdaddr_type for connect, so this
> patch fixes to set explictly bdaddr_type for RFCOMM connect.
>
> Signed-off-by: Seung-Woo Kim <[email protected]>
> ---
> net/bluetooth/rfcomm/core.c | 1 +
> 1 files changed, 1 insertions(+), 0 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel


2013-11-05 08:15:42

by Seung-Woo Kim

[permalink] [raw]
Subject: [PATCH] Bluetooth: Fix to set proper bdaddr_type for RFCOMM connect

L2CAP socket validates proper bdaddr_type for connect, so this
patch fixes to set explictly bdaddr_type for RFCOMM connect.

Signed-off-by: Seung-Woo Kim <[email protected]>
---
net/bluetooth/rfcomm/core.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c
index ca55ea1..facd8a7 100644
--- a/net/bluetooth/rfcomm/core.c
+++ b/net/bluetooth/rfcomm/core.c
@@ -720,6 +720,7 @@ static struct rfcomm_session *rfcomm_session_create(bdaddr_t *src,
addr.l2_family = AF_BLUETOOTH;
addr.l2_psm = __constant_cpu_to_le16(RFCOMM_PSM);
addr.l2_cid = 0;
+ addr.l2_bdaddr_type = BDADDR_BREDR;
*err = kernel_connect(sock, (struct sockaddr *) &addr, sizeof(addr), O_NONBLOCK);
if (*err == 0 || *err == -EINPROGRESS)
return s;
--
1.7.4.1


2013-11-05 07:58:39

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH] Bluetooth: Fix RFCOMM bind fail for L2CAP sock

Hi Seung-Woo,

>>> L2CAP socket bind checks its bdaddr type but RFCOMM kernel thread
>>> does not assign proper bdaddr type for L2CAP sock. This can cause
>>> that RFCOMM failure.
>>>
>>> Signed-off-by: Seung-Woo Kim <[email protected]>
>>> ---
>>> The issue is came from following commit, but it is only in bluetooth-next tree,
>>> so this patch is not needed for stable tree.
>>>
>>> commit 80c1a2e76dbb36588facb265ab364b1302f7ef8c
>>> Author: Johan Hedberg <[email protected]>
>>> Date: Mon Oct 14 21:17:52 2013 +0300
>>>
>>> Bluetooth: Reject invalid bdaddr types for sockets
>>>
>>> This patch is based on commit cca34b785a21d220176038c45071ffe842e99fd3 of
>>> bluetooth-next tree.
>>> ---
>>> net/bluetooth/rfcomm/core.c | 2 ++
>>> 1 files changed, 2 insertions(+), 0 deletions(-)
>>
>> good catch. Patch has been applied to bluetooth-next tree.
>>
>> You might also want to send a patch that adds the l2_bdaddr_type setting before the connect() call.
>
> Case of kernel_connect() in rfcomm_session_create(), it reuses
> l2_bdaddr_type used for kernel_bind(), so it works fine for me: I tested
> both incoming connection and outgoing connection cases of rfcomm.
> But if you prefer explicit setting for connect(), please let me know.

I realized that it will just work fine. But it is better style to add an explicit setting in the connect() case as well. It is less error prone in the future.

Regards

Marcel


2013-11-05 07:38:14

by Seung-Woo Kim

[permalink] [raw]
Subject: Re: [PATCH] Bluetooth: Fix RFCOMM bind fail for L2CAP sock

Hello Marcel Holtmann,

On 2013년 11월 05일 16:26, Marcel Holtmann wrote:
> Hi Seung-Woo,
>
>> L2CAP socket bind checks its bdaddr type but RFCOMM kernel thread
>> does not assign proper bdaddr type for L2CAP sock. This can cause
>> that RFCOMM failure.
>>
>> Signed-off-by: Seung-Woo Kim <[email protected]>
>> ---
>> The issue is came from following commit, but it is only in bluetooth-next tree,
>> so this patch is not needed for stable tree.
>>
>> commit 80c1a2e76dbb36588facb265ab364b1302f7ef8c
>> Author: Johan Hedberg <[email protected]>
>> Date: Mon Oct 14 21:17:52 2013 +0300
>>
>> Bluetooth: Reject invalid bdaddr types for sockets
>>
>> This patch is based on commit cca34b785a21d220176038c45071ffe842e99fd3 of
>> bluetooth-next tree.
>> ---
>> net/bluetooth/rfcomm/core.c | 2 ++
>> 1 files changed, 2 insertions(+), 0 deletions(-)
>
> good catch. Patch has been applied to bluetooth-next tree.
>
> You might also want to send a patch that adds the l2_bdaddr_type setting before the connect() call.

Case of kernel_connect() in rfcomm_session_create(), it reuses
l2_bdaddr_type used for kernel_bind(), so it works fine for me: I tested
both incoming connection and outgoing connection cases of rfcomm.
But if you prefer explicit setting for connect(), please let me know.

Best Regards,
- Seung-Woo Kim

>
> Regards
>
> Marcel
>
>

--
Seung-Woo Kim
Samsung Software R&D Center
--

2013-11-05 07:26:02

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH] Bluetooth: Fix RFCOMM bind fail for L2CAP sock

Hi Seung-Woo,

> L2CAP socket bind checks its bdaddr type but RFCOMM kernel thread
> does not assign proper bdaddr type for L2CAP sock. This can cause
> that RFCOMM failure.
>
> Signed-off-by: Seung-Woo Kim <[email protected]>
> ---
> The issue is came from following commit, but it is only in bluetooth-next tree,
> so this patch is not needed for stable tree.
>
> commit 80c1a2e76dbb36588facb265ab364b1302f7ef8c
> Author: Johan Hedberg <[email protected]>
> Date: Mon Oct 14 21:17:52 2013 +0300
>
> Bluetooth: Reject invalid bdaddr types for sockets
>
> This patch is based on commit cca34b785a21d220176038c45071ffe842e99fd3 of
> bluetooth-next tree.
> ---
> net/bluetooth/rfcomm/core.c | 2 ++
> 1 files changed, 2 insertions(+), 0 deletions(-)

good catch. Patch has been applied to bluetooth-next tree.

You might also want to send a patch that adds the l2_bdaddr_type setting before the connect() call.

Regards

Marcel