]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
Bluetooth: Assign the channel early when binding HCI sockets
authorMarcel Holtmann <marcel@holtmann.org>
Tue, 30 Aug 2016 03:00:37 +0000 (05:00 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Mon, 19 Sep 2016 18:19:34 +0000 (20:19 +0200)
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: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
net/bluetooth/hci_sock.c

index 0deca758fd9e73e16342e059376929f91fd1dd47..ca13fac1c1324f8a9f05a19afafd8a918ac560ad 100644 (file)
@@ -1045,6 +1045,7 @@ 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;
                break;
 
@@ -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;
+
+               atomic_inc(&hdev->promisc);
                break;
 
        case HCI_CHANNEL_MONITOR:
@@ -1123,6 +1125,8 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
                        goto done;
                }
 
+               hci_pi(sk)->channel = haddr.hci_channel;
+
                /* The monitor interface is restricted to CAP_NET_RAW
                 * capabilities and with that implicitly trusted.
                 */
@@ -1149,6 +1153,8 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
                        err = -EPERM;
                        goto done;
                }
+
+               hci_pi(sk)->channel = haddr.hci_channel;
                break;
 
        default:
@@ -1170,6 +1176,8 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
                if (capable(CAP_NET_ADMIN))
                        hci_sock_set_flag(sk, HCI_SOCK_TRUSTED);
 
+               hci_pi(sk)->channel = haddr.hci_channel;
+
                /* At the moment the index and unconfigured index events
                 * are enabled unconditionally. Setting them on each
                 * socket when binding keeps this functionality. They
@@ -1180,7 +1188,7 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
                 * received by untrusted users. Example for such events
                 * 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;
 
                        hci_sock_gen_cookie(sk);
@@ -1203,8 +1211,6 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
                break;
        }
 
-
-       hci_pi(sk)->channel = haddr.hci_channel;
        sk->sk_state = BT_BOUND;
 
 done: