Skip to contentSkip to conversation

Bluetooth: Reintroduce socket restrictions for LE sockets

PATCH Superseded [email protected] 2 participants 3 messages Oct 16, 2013

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Bluetooth: Reintroduce socket restrictions for LE sockets

From: Johan Hedberg <[email protected]>

Right now we do not allow user space to use connection oriented channels on LE, and the only CID that can be used is the Attribute Protocol one. These restrictions went away together with the recent refactoring of the L2CAP code, but this patch puts them back to their appropriate places.

---
 net/bluetooth/l2cap_sock.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
net/bluetooth/l2cap_sock.c +20 -0
index 68f486a..bda52d7 100644
@@ -72,6 +72,16 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
 	if (!bdaddr_type_is_valid(la.l2_bdaddr_type))
 		return -EINVAL;
 
+	if (la.l2_bdaddr_type == BDADDR_LE_PUBLIC ||
+	    la.l2_bdaddr_type == BDADDR_LE_RANDOM) {
+		/* Connection oriented channels are not supported on LE */
+		if (la.l2_psm)
+			return -EINVAL;
+		/* We only allow ATT user space socket */
+		if (la.l2_cid != L2CAP_CID_ATT)
+			return -EINVAL;
+	}
+
 	lock_sock(sk);
 
 	if (sk->sk_state != BT_OPEN) {
@@ -156,6 +166,16 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr,
 	if (chan->src_type != BDADDR_BREDR && la.l2_bdaddr_type == BDADDR_BREDR)
 		return -EINVAL;
 
+	if (la.l2_bdaddr_type == BDADDR_LE_PUBLIC ||
+	    la.l2_bdaddr_type == BDADDR_LE_RANDOM) {
+		/* Connection oriented channels are not supported on LE */
+		if (la.l2_psm)
+			return -EINVAL;
+		/* We only allow ATT user space socket */
+		if (la.l2_cid != L2CAP_CID_ATT)
+			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
#1 lore raw

Hi Johan,

Quoted 15 lines

Right now we do not allow user space to use connection oriented channels on LE, and the only CID that can be used is the Attribute Protocol one. These restrictions went away together with the recent refactoring of the L2CAP code, but this patch puts them back to their appropriate places.

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

1 file changed, 20 insertions(+)
net/bluetooth/l2cap_sock.c +0 -0
index 68f486a..bda52d7 100644

net/bluetooth/l2cap_sock.c static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen) · line 76

Quoted 5 lines
net/bluetooth/l2cap_sock.c +2 -0
@@ -72,6 +72,16 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
 	if (!bdaddr_type_is_valid(la.l2_bdaddr_type))
 		return -EINVAL;
 
+	if (la.l2_bdaddr_type == BDADDR_LE_PUBLIC ||
+	    la.l2_bdaddr_type == BDADDR_LE_RANDOM) {

can we use bdaddr_type_is_le() here instead.

Regards

Marcel

#2 lore raw

Hi Marcel,

Quoted 18 lines · Marcel Holtmann
Quoted 18 lines

Right now we do not allow user space to use connection oriented channels on LE, and the only CID that can be used is the Attribute Protocol one. These restrictions went away together with the recent refactoring of the L2CAP code, but this patch puts them back to their appropriate places.

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

1 file changed, 20 insertions(+)
net/bluetooth/l2cap_sock.c +0 -0
index 68f486a..bda52d7 100644
@@ -72,6 +72,16 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
 	if (!bdaddr_type_is_valid(la.l2_bdaddr_type))
 		return -EINVAL;
 
Quoted 4 lines

net/bluetooth/l2cap_sock.c static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen) · line 76

Quoted 2 lines
net/bluetooth/l2cap_sock.c +2 -0
+	if (la.l2_bdaddr_type == BDADDR_LE_PUBLIC ||
+	    la.l2_bdaddr_type == BDADDR_LE_RANDOM) {

can we use bdaddr_type_is_le() here instead.

I forgot that we had that helper. A v2 has been sent.

Johan