Commit 5a6d2cf5 authored by Marcel Holtmann's avatar Marcel Holtmann

Bluetooth: Assign the channel early when binding HCI sockets

Assignment of the hci_pi(sk)->channel should be done early when binding
the HCI socket. This avoids confusion with the RAW channel that is used
for legacy access.
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
parent 0ef2c42f
...@@ -1045,6 +1045,7 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, ...@@ -1045,6 +1045,7 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
atomic_inc(&hdev->promisc); atomic_inc(&hdev->promisc);
} }
hci_pi(sk)->channel = haddr.hci_channel;
hci_pi(sk)->hdev = hdev; hci_pi(sk)->hdev = hdev;
break; break;
...@@ -1107,9 +1108,10 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, ...@@ -1107,9 +1108,10 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
} }
} }
atomic_inc(&hdev->promisc); hci_pi(sk)->channel = haddr.hci_channel;
hci_pi(sk)->hdev = hdev; hci_pi(sk)->hdev = hdev;
atomic_inc(&hdev->promisc);
break; break;
case HCI_CHANNEL_MONITOR: case HCI_CHANNEL_MONITOR:
...@@ -1123,6 +1125,8 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, ...@@ -1123,6 +1125,8 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
goto done; goto done;
} }
hci_pi(sk)->channel = haddr.hci_channel;
/* The monitor interface is restricted to CAP_NET_RAW /* The monitor interface is restricted to CAP_NET_RAW
* capabilities and with that implicitly trusted. * capabilities and with that implicitly trusted.
*/ */
...@@ -1149,6 +1153,8 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, ...@@ -1149,6 +1153,8 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
err = -EPERM; err = -EPERM;
goto done; goto done;
} }
hci_pi(sk)->channel = haddr.hci_channel;
break; break;
default: default:
...@@ -1170,6 +1176,8 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, ...@@ -1170,6 +1176,8 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
if (capable(CAP_NET_ADMIN)) if (capable(CAP_NET_ADMIN))
hci_sock_set_flag(sk, HCI_SOCK_TRUSTED); hci_sock_set_flag(sk, HCI_SOCK_TRUSTED);
hci_pi(sk)->channel = haddr.hci_channel;
/* At the moment the index and unconfigured index events /* At the moment the index and unconfigured index events
* are enabled unconditionally. Setting them on each * are enabled unconditionally. Setting them on each
* socket when binding keeps this functionality. They * socket when binding keeps this functionality. They
...@@ -1180,7 +1188,7 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, ...@@ -1180,7 +1188,7 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
* received by untrusted users. Example for such events * received by untrusted users. Example for such events
* are changes to settings, class of device, name etc. * are changes to settings, class of device, name etc.
*/ */
if (haddr.hci_channel == HCI_CHANNEL_CONTROL) { if (hci_pi(sk)->channel == HCI_CHANNEL_CONTROL) {
struct sk_buff *skb; struct sk_buff *skb;
hci_sock_gen_cookie(sk); hci_sock_gen_cookie(sk);
...@@ -1203,8 +1211,6 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, ...@@ -1203,8 +1211,6 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
break; break;
} }
hci_pi(sk)->channel = haddr.hci_channel;
sk->sk_state = BT_BOUND; sk->sk_state = BT_BOUND;
done: done:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment