Skip to contentSkip to conversation

Bluetooth: Reject invalid bdaddr types for sockets

PATCH In review [email protected] 2 participants 4 messages Oct 14, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Bluetooth: Reject invalid bdaddr types for sockets

From: Johan Hedberg <[email protected]>

We need to verify that the bdaddr type passed to connect() and bind() is within the set of valid values. If it is not we need to cleanly fail with EINVAL.

---
 net/bluetooth/l2cap_sock.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/bluetooth/l2cap_sock.c +6 -0
index f1b462f..982915d 100644
@@ -69,6 +69,9 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
 	if (la.l2_cid && la.l2_psm)
 		return -EINVAL;
 
+	if (!bdaddr_type_is_valid(la.l2_bdaddr_type))
+		return -EINVAL;
+
 	lock_sock(sk);
 
 	if (sk->sk_state != BT_OPEN) {
@@ -144,6 +147,9 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr,
 	if (la.l2_cid && la.l2_psm)
 		return -EINVAL;
 
+	if (!bdaddr_type_is_valid(la.l2_bdaddr_type))
+		return -EINVAL;
+
 	err = l2cap_chan_connect(chan, la.l2_psm, __le16_to_cpu(la.l2_cid),
 				 &la.l2_bdaddr, la.l2_bdaddr_type);
 	if (err)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 2/2 Bluetooth: Check that bind() bdaddr type matches connect()

From: Johan Hedberg <[email protected]>

If a socket was bound to an address type other than BR/EDR (such as LE) we should reject trying to connect it to a BR/EDR address. The same applies for binding to BR/EDR and trying to connect to non-BR/EDR.

---
 net/bluetooth/l2cap_sock.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/bluetooth/l2cap_sock.c +6 -0
index 982915d..87e17b7 100644
@@ -150,6 +150,12 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr,
 	if (!bdaddr_type_is_valid(la.l2_bdaddr_type))
 		return -EINVAL;
 
+	if (chan->src_type == BDADDR_BREDR && la.l2_bdaddr_type != BDADDR_BREDR)
+		return -EINVAL;
+
+	if (chan->src_type != BDADDR_BREDR && la.l2_bdaddr_type == BDADDR_BREDR)
+		return -EINVAL;
+
 	err = l2cap_chan_connect(chan, la.l2_psm, __le16_to_cpu(la.l2_cid),
 				 &la.l2_bdaddr, la.l2_bdaddr_type);
 	if (err)
Signature · 1 line
1.8.3.1
maintainer
#2 lore raw

Re: [PATCH 2/2] Bluetooth: Check that bind() bdaddr type matches connect()

Hi Johan,

Quoted 8 lines

If a socket was bound to an address type other than BR/EDR (such as LE) we should reject trying to connect it to a BR/EDR address. The same applies for binding to BR/EDR and trying to connect to non-BR/EDR.

---
net/bluetooth/l2cap_sock.c | 6 ++++++

1 file changed, 6 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel

maintainer
#3 lore raw
In reply to [email protected]

Hi Johan,

Quoted 8 lines

We need to verify that the bdaddr type passed to connect() and bind() is within the set of valid values. If it is not we need to cleanly fail with EINVAL.

---
net/bluetooth/l2cap_sock.c | 6 ++++++

1 file changed, 6 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel