linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] Bluetooth: Fix possible NULL pointer derefence in l2cap code
@ 2011-11-16  8:32 Szymon Janc
  2011-11-16  8:32 ` [PATCH 2/5] Bluetooth: Simplify l2cap_add_to_srej_queue Szymon Janc
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Szymon Janc @ 2011-11-16  8:32 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: ulrik.lauren, kanak.gupta, Szymon Janc

Due to ERTM reliability L2CAP channel needs to be disconnected if
adding to srej list failed.

Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
---
 net/bluetooth/l2cap_core.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 1790ce3..276817a 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -3788,7 +3788,7 @@ static void l2cap_resend_srejframe(struct l2cap_chan *chan, u16 tx_seq)
 	}
 }
 
-static void l2cap_send_srejframe(struct l2cap_chan *chan, u16 tx_seq)
+static int l2cap_send_srejframe(struct l2cap_chan *chan, u16 tx_seq)
 {
 	struct srej_list *new;
 	u32 control;
@@ -3799,6 +3799,9 @@ static void l2cap_send_srejframe(struct l2cap_chan *chan, u16 tx_seq)
 		l2cap_send_sframe(chan, control);
 
 		new = kzalloc(sizeof(struct srej_list), GFP_ATOMIC);
+		if (!new)
+			return -ENOMEM;
+
 		new->tx_seq = chan->expected_tx_seq;
 
 		chan->expected_tx_seq = __next_seq(chan, chan->expected_tx_seq);
@@ -3807,6 +3810,8 @@ static void l2cap_send_srejframe(struct l2cap_chan *chan, u16 tx_seq)
 	}
 
 	chan->expected_tx_seq = __next_seq(chan, chan->expected_tx_seq);
+
+	return 0;
 }
 
 static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u32 rx_control, struct sk_buff *skb)
@@ -3877,7 +3882,12 @@ static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u32 rx_cont
 					return 0;
 				}
 			}
-			l2cap_send_srejframe(chan, tx_seq);
+
+			err = l2cap_send_srejframe(chan, tx_seq);
+			if (err < 0) {
+				l2cap_send_disconn_req(chan->conn, chan, -err);
+				return err;
+			}
 		}
 	} else {
 		expected_tx_seq_offset = __seq_offset(chan,
@@ -3899,7 +3909,11 @@ static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u32 rx_cont
 
 		set_bit(CONN_SEND_PBIT, &chan->conn_state);
 
-		l2cap_send_srejframe(chan, tx_seq);
+		err = l2cap_send_srejframe(chan, tx_seq);
+		if (err < 0) {
+			l2cap_send_disconn_req(chan->conn, chan, -err);
+			return err;
+		}
 
 		__clear_ack_timer(chan);
 	}
-- 
on behalf of ST-Ericsson


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

* [PATCH 2/5] Bluetooth: Simplify l2cap_add_to_srej_queue
  2011-11-16  8:32 [PATCH 1/5] Bluetooth: Fix possible NULL pointer derefence in l2cap code Szymon Janc
@ 2011-11-16  8:32 ` Szymon Janc
  2011-11-16  8:32 ` [PATCH 3/5] Bluetooth: Refactor loop in l2cap_retransmit_one_frame Szymon Janc
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2011-11-16  8:32 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: ulrik.lauren, kanak.gupta, Szymon Janc

Make it easier to see what is loop break condition.
skb_queue_next return valid skb or garbage, not NULL.

Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
---
 net/bluetooth/l2cap_core.c |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 276817a..bd65b3e 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -3562,14 +3562,10 @@ static int l2cap_add_to_srej_queue(struct l2cap_chan *chan, struct sk_buff *skb,
 	bt_cb(skb)->sar = sar;
 
 	next_skb = skb_peek(&chan->srej_q);
-	if (!next_skb) {
-		__skb_queue_tail(&chan->srej_q, skb);
-		return 0;
-	}
 
 	tx_seq_offset = __seq_offset(chan, tx_seq, chan->buffer_seq);
 
-	do {
+	while (next_skb) {
 		if (bt_cb(next_skb)->tx_seq == tx_seq)
 			return -EINVAL;
 
@@ -3582,9 +3578,10 @@ static int l2cap_add_to_srej_queue(struct l2cap_chan *chan, struct sk_buff *skb,
 		}
 
 		if (skb_queue_is_last(&chan->srej_q, next_skb))
-			break;
-
-	} while ((next_skb = skb_queue_next(&chan->srej_q, next_skb)));
+			next_skb = NULL;
+		else
+			next_skb = skb_queue_next(&chan->srej_q, next_skb);
+	}
 
 	__skb_queue_tail(&chan->srej_q, skb);
 
-- 
on behalf of ST-Ericsson


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

* [PATCH 3/5] Bluetooth: Refactor loop in l2cap_retransmit_one_frame
  2011-11-16  8:32 [PATCH 1/5] Bluetooth: Fix possible NULL pointer derefence in l2cap code Szymon Janc
  2011-11-16  8:32 ` [PATCH 2/5] Bluetooth: Simplify l2cap_add_to_srej_queue Szymon Janc
@ 2011-11-16  8:32 ` Szymon Janc
  2011-11-16  8:32 ` [PATCH 4/5] Bluetooth: Fix some checkpatch.pl errors and warnings Szymon Janc
  2011-11-16  8:32 ` [PATCH 5/5] Bluetooth: Simplify __l2cap_global_chan_by_addr Szymon Janc
  3 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2011-11-16  8:32 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: ulrik.lauren, kanak.gupta, Szymon Janc

This make it easier to see what is the real reason for loop to exit.
skb_queue_next return valid skb or garbage, not NULL.

Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
---
 net/bluetooth/l2cap_core.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index bd65b3e..26925a8 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1318,14 +1318,12 @@ static void l2cap_retransmit_one_frame(struct l2cap_chan *chan, u16 tx_seq)
 	if (!skb)
 		return;
 
-	do {
-		if (bt_cb(skb)->tx_seq == tx_seq)
-			break;
-
+	while (bt_cb(skb)->tx_seq != tx_seq) {
 		if (skb_queue_is_last(&chan->tx_q, skb))
 			return;
 
-	} while ((skb = skb_queue_next(&chan->tx_q, skb)));
+		skb = skb_queue_next(&chan->tx_q, skb);
+	}
 
 	if (chan->remote_max_tx &&
 			bt_cb(skb)->retries == chan->remote_max_tx) {
-- 
on behalf of ST-Ericsson


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

* [PATCH 4/5] Bluetooth: Fix some checkpatch.pl errors and warnings
  2011-11-16  8:32 [PATCH 1/5] Bluetooth: Fix possible NULL pointer derefence in l2cap code Szymon Janc
  2011-11-16  8:32 ` [PATCH 2/5] Bluetooth: Simplify l2cap_add_to_srej_queue Szymon Janc
  2011-11-16  8:32 ` [PATCH 3/5] Bluetooth: Refactor loop in l2cap_retransmit_one_frame Szymon Janc
@ 2011-11-16  8:32 ` Szymon Janc
  2011-11-16  8:32 ` [PATCH 5/5] Bluetooth: Simplify __l2cap_global_chan_by_addr Szymon Janc
  3 siblings, 0 replies; 6+ messages in thread
From: Szymon Janc @ 2011-11-16  8:32 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: ulrik.lauren, kanak.gupta, Szymon Janc

Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
---
 net/bluetooth/hci_core.c   |    6 ++----
 net/bluetooth/l2cap_core.c |    5 ++---
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index fb3feeb..6e4e446 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1336,14 +1336,12 @@ int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr)
 {
 	struct bdaddr_list *entry;
 
-	if (bacmp(bdaddr, BDADDR_ANY) == 0) {
+	if (bacmp(bdaddr, BDADDR_ANY) == 0)
 		return hci_blacklist_clear(hdev);
-	}
 
 	entry = hci_blacklist_lookup(hdev, bdaddr);
-	if (!entry) {
+	if (!entry)
 		return -ENOENT;
-	}
 
 	list_del(&entry->list);
 	kfree(entry);
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 26925a8..f79dbe8 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -97,7 +97,6 @@ static struct l2cap_chan *__l2cap_get_chan_by_dcid(struct l2cap_conn *conn, u16
 			return c;
 	}
 	return NULL;
-
 }
 
 static struct l2cap_chan *__l2cap_get_chan_by_scid(struct l2cap_conn *conn, u16 cid)
@@ -1904,7 +1903,7 @@ static void l2cap_add_opt_efs(void **ptr, struct l2cap_chan *chan)
 {
 	struct l2cap_conf_efs efs;
 
-	switch(chan->mode) {
+	switch (chan->mode) {
 	case L2CAP_MODE_ERTM:
 		efs.id		= chan->local_id;
 		efs.stype	= chan->local_stype;
@@ -3017,7 +3016,7 @@ static inline int l2cap_disconnect_rsp(struct l2cap_conn *conn, struct l2cap_cmd
 
 	/* don't delete l2cap channel if sk is owned by user */
 	if (sock_owned_by_user(sk)) {
-		l2cap_state_change(chan,BT_DISCONN);
+		l2cap_state_change(chan, BT_DISCONN);
 		__clear_chan_timer(chan);
 		__set_chan_timer(chan, L2CAP_DISC_TIMEOUT);
 		bh_unlock_sock(sk);
-- 
on behalf of ST-Ericsson


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

* [PATCH 5/5] Bluetooth: Simplify __l2cap_global_chan_by_addr
  2011-11-16  8:32 [PATCH 1/5] Bluetooth: Fix possible NULL pointer derefence in l2cap code Szymon Janc
                   ` (2 preceding siblings ...)
  2011-11-16  8:32 ` [PATCH 4/5] Bluetooth: Fix some checkpatch.pl errors and warnings Szymon Janc
@ 2011-11-16  8:32 ` Szymon Janc
  2011-11-16 20:31   ` Gustavo Padovan
  3 siblings, 1 reply; 6+ messages in thread
From: Szymon Janc @ 2011-11-16  8:32 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: ulrik.lauren, kanak.gupta, Szymon Janc

Make __l2cap_global_chan_by_addr similar to other find functions.

Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
---
 net/bluetooth/l2cap_core.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index f79dbe8..d63e670 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -153,12 +153,9 @@ static struct l2cap_chan *__l2cap_global_chan_by_addr(__le16 psm, bdaddr_t *src)
 
 	list_for_each_entry(c, &chan_list, global_l) {
 		if (c->sport == psm && !bacmp(&bt_sk(c->sk)->src, src))
-			goto found;
+			return c;
 	}
-
-	c = NULL;
-found:
-	return c;
+	return NULL;
 }
 
 int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm)
-- 
on behalf of ST-Ericsson


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

* Re: [PATCH 5/5] Bluetooth: Simplify __l2cap_global_chan_by_addr
  2011-11-16  8:32 ` [PATCH 5/5] Bluetooth: Simplify __l2cap_global_chan_by_addr Szymon Janc
@ 2011-11-16 20:31   ` Gustavo Padovan
  0 siblings, 0 replies; 6+ messages in thread
From: Gustavo Padovan @ 2011-11-16 20:31 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth, ulrik.lauren, kanak.gupta

Hi Szymon,

* Szymon Janc <szymon.janc@tieto.com> [2011-11-16 09:32:22 +0100]:

> Make __l2cap_global_chan_by_addr similar to other find functions.
> 
> Signed-off-by: Szymon Janc <szymon.janc@tieto.com>
> ---
>  net/bluetooth/l2cap_core.c |    7 ++-----
>  1 files changed, 2 insertions(+), 5 deletions(-)

all five patches have been applied. thanks.

	Gustavo

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

end of thread, other threads:[~2011-11-16 20:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-16  8:32 [PATCH 1/5] Bluetooth: Fix possible NULL pointer derefence in l2cap code Szymon Janc
2011-11-16  8:32 ` [PATCH 2/5] Bluetooth: Simplify l2cap_add_to_srej_queue Szymon Janc
2011-11-16  8:32 ` [PATCH 3/5] Bluetooth: Refactor loop in l2cap_retransmit_one_frame Szymon Janc
2011-11-16  8:32 ` [PATCH 4/5] Bluetooth: Fix some checkpatch.pl errors and warnings Szymon Janc
2011-11-16  8:32 ` [PATCH 5/5] Bluetooth: Simplify __l2cap_global_chan_by_addr Szymon Janc
2011-11-16 20:31   ` Gustavo Padovan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).