Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: Fix potential NULL dereference
@ 2015-02-03  8:01 Johan Hedberg
  2015-02-03  8:03 ` Marcel Holtmann
  0 siblings, 1 reply; 8+ messages in thread
From: Johan Hedberg @ 2015-02-03  8:01 UTC (permalink / raw)
  To: linux-bluetooth

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

The bnep_get_device function may be triggered by an ioctl just after a
connection has gone down. In such a case the respective L2CAP chan->conn
pointer will get set to NULL (by l2cap_chan_del). This patch adds a
missing NULL check for this case in the bnep_get_device() function.

Reported-by: Patrik Flykt <patrik.flykt@linux.intel.com>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/bnep/core.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
index ce82722d049b..05f57e491ccb 100644
--- a/net/bluetooth/bnep/core.c
+++ b/net/bluetooth/bnep/core.c
@@ -511,13 +511,12 @@ static int bnep_session(void *arg)
 
 static struct device *bnep_get_device(struct bnep_session *session)
 {
-	struct hci_conn *conn;
+	struct l2cap_conn *conn = l2cap_pi(session->sock->sk)->chan->conn;
 
-	conn = l2cap_pi(session->sock->sk)->chan->conn->hcon;
-	if (!conn)
+	if (!conn || !conn->hcon)
 		return NULL;
 
-	return &conn->dev;
+	return &conn->hcon->dev;
 }
 
 static struct device_type bnep_type = {
-- 
2.1.0


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

* Re: [PATCH] Bluetooth: Fix potential NULL dereference
  2015-02-03  8:01 [PATCH] Bluetooth: Fix potential NULL dereference Johan Hedberg
@ 2015-02-03  8:03 ` Marcel Holtmann
  0 siblings, 0 replies; 8+ messages in thread
From: Marcel Holtmann @ 2015-02-03  8:03 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth

Hi Johan,

> The bnep_get_device function may be triggered by an ioctl just after a
> connection has gone down. In such a case the respective L2CAP chan->conn
> pointer will get set to NULL (by l2cap_chan_del). This patch adds a
> missing NULL check for this case in the bnep_get_device() function.
> 
> Reported-by: Patrik Flykt <patrik.flykt@linux.intel.com>
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> net/bluetooth/bnep/core.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel


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

* [PATCH] Bluetooth: Fix potential NULL dereference
@ 2015-05-13 12:14 Jaganath Kanakkassery
  2015-05-13 20:34 ` Marcel Holtmann
  0 siblings, 1 reply; 8+ messages in thread
From: Jaganath Kanakkassery @ 2015-05-13 12:14 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jaganath Kanakkassery

addr can be NULL and it should not be dereferenced before NULL checking.

Signed-off-by: Jaganath Kanakkassery <jaganath.k@samsung.com>
---
 net/bluetooth/rfcomm/sock.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index 825e8fb..e576374 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -336,14 +336,16 @@ static int rfcomm_sock_bind(struct socket *sock, struct sockaddr *addr, int addr
 {
 	struct sockaddr_rc *sa = (struct sockaddr_rc *) addr;
 	struct sock *sk = sock->sk;
-	int chan = sa->rc_channel;
+	int chan;
 	int err = 0;
 
-	BT_DBG("sk %p %pMR", sk, &sa->rc_bdaddr);
-
 	if (!addr || addr->sa_family != AF_BLUETOOTH)
 		return -EINVAL;
 
+	BT_DBG("sk %p %pMR", sk, &sa->rc_bdaddr);
+
+	chan = sa->rc_channel;
+
 	lock_sock(sk);
 
 	if (sk->sk_state != BT_OPEN) {
-- 
1.7.9.5


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

* Re: [PATCH] Bluetooth: Fix potential NULL dereference
  2015-05-13 12:14 Jaganath Kanakkassery
@ 2015-05-13 20:34 ` Marcel Holtmann
  0 siblings, 0 replies; 8+ messages in thread
From: Marcel Holtmann @ 2015-05-13 20:34 UTC (permalink / raw)
  To: Jaganath Kanakkassery; +Cc: linux-bluetooth

Hi Jaganath,

> addr can be NULL and it should not be dereferenced before NULL checking.
> 
> Signed-off-by: Jaganath Kanakkassery <jaganath.k@samsung.com>
> ---
> net/bluetooth/rfcomm/sock.c |    8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
> index 825e8fb..e576374 100644
> --- a/net/bluetooth/rfcomm/sock.c
> +++ b/net/bluetooth/rfcomm/sock.c
> @@ -336,14 +336,16 @@ static int rfcomm_sock_bind(struct socket *sock, struct sockaddr *addr, int addr
> {
> 	struct sockaddr_rc *sa = (struct sockaddr_rc *) addr;
> 	struct sock *sk = sock->sk;
> -	int chan = sa->rc_channel;
> +	int chan;
> 	int err = 0;
> 
> -	BT_DBG("sk %p %pMR", sk, &sa->rc_bdaddr);
> -
> 	if (!addr || addr->sa_family != AF_BLUETOOTH)
> 		return -EINVAL;
> 
> +	BT_DBG("sk %p %pMR", sk, &sa->rc_bdaddr);
> +
> +	chan = sa->rc_channel;
> +

if we start changing things here, then we better change the code into something that all the other socket handling code is doing anyway. So do the min comparison and copy the data into a local copy of the sockaddr_rc.

And on a side note, I wonder if addr can actually be NULL. It might be interesting to check the generic socket code if this really can happen if you provide no address structure to the bind() system call or if this gets filtered out by the core socket code.

Regards

Marcel


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

* Re: [PATCH] Bluetooth: Fix potential NULL dereference
  2015-05-14  6:13 JAGANATH KANAKKASSERY
@ 2015-05-14  6:34 ` Marcel Holtmann
  2015-06-06 15:35   ` chanyeol
  0 siblings, 1 reply; 8+ messages in thread
From: Marcel Holtmann @ 2015-05-14  6:34 UTC (permalink / raw)
  To: jaganath.k; +Cc: linux-bluetooth@vger.kernel.org

Hi Jaganath,

>>> addr can be NULL and it should not be dereferenced before NULL checking.
>>> 
>>> Signed-off-by: Jaganath Kanakkassery <jaganath.k@samsung.com>
>>> ---
>> 
>> if we start changing things here, then we better change the code into something that all the other socket handling code is doing anyway>y. So do the min comparison and copy the data into a local copy of the sockaddr_rc.
>> 
>> And on a side note, I wonder if addr can actually be NULL. It might be interesting to check the generic socket code if this really can happe>n if you provide no address structure to the bind() system call or if this gets filtered out by the core socket code.
> 
> I checked generic socket code and it looks like addr will never be NULL when user space calls bind.
> But this can be called from kernel_bind() also which I think will never be called for RFCOMM.
> So this patch is not required? 

that is what I thought. However converting it to the same handling using min and copying into local storage might be a good idea. The more pieces in HCI, L2CAP, SCO and RFCOMM sockets that are similar, the better.

Regards

Marcel


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

* Re: [PATCH] Bluetooth: Fix potential NULL dereference
  2015-06-02  8:28 ` Jaganath K
@ 2015-06-06  5:02   ` Marcel Holtmann
  0 siblings, 0 replies; 8+ messages in thread
From: Marcel Holtmann @ 2015-06-06  5:02 UTC (permalink / raw)
  To: Jaganath K; +Cc: linux-bluetooth@vger.kernel.org

Hi Jaganath,

> Ping.

so we agreed to not apply this patch. I might have missed your other patch. So just resend that one.

Regards

Marcel


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

* Re: [PATCH] Bluetooth: Fix potential NULL dereference
  2015-05-14  6:34 ` Marcel Holtmann
@ 2015-06-06 15:35   ` chanyeol
  2015-06-06 15:46     ` Marcel Holtmann
  0 siblings, 1 reply; 8+ messages in thread
From: chanyeol @ 2015-06-06 15:35 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: jaganath.k, linux-bluetooth@vger.kernel.org

Hi Marcel,

On Thu, 2015-05-14 at 08:34 +0200, Marcel Holtmann wrote:
> Hi Jaganath,
> 
> > > > addr can be NULL and it should not be dereferenced before NULL 
> > > > checking.
> > > > 
> > > > Signed-off-by: Jaganath Kanakkassery <jaganath.k@samsung.com>
> > > > ---
> > > 
> > > if we start changing things here, then we better change the code 
> > > into something that all the other socket handling code is doing 
> > > anyway>y. So do the min comparison and copy the data into a local 
> > > copy of the sockaddr_rc.
> > > 
> > > And on a side note, I wonder if addr can actually be NULL. It 
> > > might be interesting to check the generic socket code if this 
> > > really can happe>n if you provide no address structure to the 
> > > bind() system call or if this gets filtered out by the core 
> > > socket code.
> > 
> > I checked generic socket code and it looks like addr will never be 
> > NULL when user space calls bind.
> > But this can be called from kernel_bind() also which I think will 
> > never be called for RFCOMM.
> > So this patch is not required? 
> 
> that is what I thought. However converting it to the same handling 
> using min and copying into local storage might be a good idea.
Could you tell us why this is good idea? I failed to find it in git
history/mailing list.

In addition to RFCOMM connect that you mentioned, I found out SCO
connect/bind still use the old style in Bluetooth unlikely HCI,L2CAP.

Regards
Chanyeol

>  The more pieces in HCI, L2CAP, SCO and RFCOMM sockets that are 
> similar, the better.
> 
> Regards
> 
> Marcel
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux
> -bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH] Bluetooth: Fix potential NULL dereference
  2015-06-06 15:35   ` chanyeol
@ 2015-06-06 15:46     ` Marcel Holtmann
  0 siblings, 0 replies; 8+ messages in thread
From: Marcel Holtmann @ 2015-06-06 15:46 UTC (permalink / raw)
  To: chanyeol; +Cc: JAGANATH KANAKKASSERY, linux-bluetooth@vger.kernel.org

Hi Chanyeol,

>>>>> addr can be NULL and it should not be dereferenced before NULL 
>>>>> checking.
>>>>> 
>>>>> Signed-off-by: Jaganath Kanakkassery <jaganath.k@samsung.com>
>>>>> ---
>>>> 
>>>> if we start changing things here, then we better change the code 
>>>> into something that all the other socket handling code is doing 
>>>> anyway>y. So do the min comparison and copy the data into a local 
>>>> copy of the sockaddr_rc.
>>>> 
>>>> And on a side note, I wonder if addr can actually be NULL. It 
>>>> might be interesting to check the generic socket code if this 
>>>> really can happe>n if you provide no address structure to the 
>>>> bind() system call or if this gets filtered out by the core 
>>>> socket code.
>>> 
>>> I checked generic socket code and it looks like addr will never be 
>>> NULL when user space calls bind.
>>> But this can be called from kernel_bind() also which I think will 
>>> never be called for RFCOMM.
>>> So this patch is not required? 
>> 
>> that is what I thought. However converting it to the same handling 
>> using min and copying into local storage might be a good idea.
> Could you tell us why this is good idea? I failed to find it in git
> history/mailing list.
> 
> In addition to RFCOMM connect that you mentioned, I found out SCO
> connect/bind still use the old style in Bluetooth unlikely HCI,L2CAP.

it avoids any kind of leakage and allows for an easy extension of the socket data structures if we ever have to.

Regards

Marcel


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

end of thread, other threads:[~2015-06-06 15:46 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-03  8:01 [PATCH] Bluetooth: Fix potential NULL dereference Johan Hedberg
2015-02-03  8:03 ` Marcel Holtmann
  -- strict thread matches above, loose matches on Subject: below --
2015-05-13 12:14 Jaganath Kanakkassery
2015-05-13 20:34 ` Marcel Holtmann
2015-05-14  6:13 JAGANATH KANAKKASSERY
2015-05-14  6:34 ` Marcel Holtmann
2015-06-06 15:35   ` chanyeol
2015-06-06 15:46     ` Marcel Holtmann
2015-05-15  5:37 JAGANATH KANAKKASSERY
2015-06-02  8:28 ` Jaganath K
2015-06-06  5:02   ` Marcel Holtmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox