diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2016-08-27 14:23:38 -0400 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2016-09-19 14:19:34 -0400 |
commit | 70ecce91e3a2d7e332fe56fd065c67d404b8fccf (patch) | |
tree | 3a33a62c593f60583207d8db4a29e68ddea44c98 /net/bluetooth | |
parent | 47b0f573f2fa7634860e16ea31f2bc3057a1022a (diff) |
Bluetooth: Store control socket cookie and comm information
To further allow unique identification and tracking of control socket,
store cookie and comm information when binding the socket.
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Diffstat (limited to 'net/bluetooth')
-rw-r--r-- | net/bluetooth/hci_sock.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c index 99dd1503ef56..4dce6dfdb0f2 100644 --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c | |||
@@ -26,6 +26,7 @@ | |||
26 | 26 | ||
27 | #include <linux/export.h> | 27 | #include <linux/export.h> |
28 | #include <linux/utsname.h> | 28 | #include <linux/utsname.h> |
29 | #include <linux/sched.h> | ||
29 | #include <asm/unaligned.h> | 30 | #include <asm/unaligned.h> |
30 | 31 | ||
31 | #include <net/bluetooth/bluetooth.h> | 32 | #include <net/bluetooth/bluetooth.h> |
@@ -38,6 +39,8 @@ | |||
38 | static LIST_HEAD(mgmt_chan_list); | 39 | static LIST_HEAD(mgmt_chan_list); |
39 | static DEFINE_MUTEX(mgmt_chan_list_lock); | 40 | static DEFINE_MUTEX(mgmt_chan_list_lock); |
40 | 41 | ||
42 | static DEFINE_IDA(sock_cookie_ida); | ||
43 | |||
41 | static atomic_t monitor_promisc = ATOMIC_INIT(0); | 44 | static atomic_t monitor_promisc = ATOMIC_INIT(0); |
42 | 45 | ||
43 | /* ----- HCI socket interface ----- */ | 46 | /* ----- HCI socket interface ----- */ |
@@ -52,6 +55,8 @@ struct hci_pinfo { | |||
52 | __u32 cmsg_mask; | 55 | __u32 cmsg_mask; |
53 | unsigned short channel; | 56 | unsigned short channel; |
54 | unsigned long flags; | 57 | unsigned long flags; |
58 | __u32 cookie; | ||
59 | char comm[TASK_COMM_LEN]; | ||
55 | }; | 60 | }; |
56 | 61 | ||
57 | void hci_sock_set_flag(struct sock *sk, int nr) | 62 | void hci_sock_set_flag(struct sock *sk, int nr) |
@@ -74,6 +79,11 @@ unsigned short hci_sock_get_channel(struct sock *sk) | |||
74 | return hci_pi(sk)->channel; | 79 | return hci_pi(sk)->channel; |
75 | } | 80 | } |
76 | 81 | ||
82 | u32 hci_sock_get_cookie(struct sock *sk) | ||
83 | { | ||
84 | return hci_pi(sk)->cookie; | ||
85 | } | ||
86 | |||
77 | static inline int hci_test_bit(int nr, const void *addr) | 87 | static inline int hci_test_bit(int nr, const void *addr) |
78 | { | 88 | { |
79 | return *((const __u32 *) addr + (nr >> 5)) & ((__u32) 1 << (nr & 31)); | 89 | return *((const __u32 *) addr + (nr >> 5)) & ((__u32) 1 << (nr & 31)); |
@@ -585,6 +595,7 @@ static int hci_sock_release(struct socket *sock) | |||
585 | { | 595 | { |
586 | struct sock *sk = sock->sk; | 596 | struct sock *sk = sock->sk; |
587 | struct hci_dev *hdev; | 597 | struct hci_dev *hdev; |
598 | int id; | ||
588 | 599 | ||
589 | BT_DBG("sock %p sk %p", sock, sk); | 600 | BT_DBG("sock %p sk %p", sock, sk); |
590 | 601 | ||
@@ -593,8 +604,17 @@ static int hci_sock_release(struct socket *sock) | |||
593 | 604 | ||
594 | hdev = hci_pi(sk)->hdev; | 605 | hdev = hci_pi(sk)->hdev; |
595 | 606 | ||
596 | if (hci_pi(sk)->channel == HCI_CHANNEL_MONITOR) | 607 | switch (hci_pi(sk)->channel) { |
608 | case HCI_CHANNEL_MONITOR: | ||
597 | atomic_dec(&monitor_promisc); | 609 | atomic_dec(&monitor_promisc); |
610 | break; | ||
611 | case HCI_CHANNEL_CONTROL: | ||
612 | id = hci_pi(sk)->cookie; | ||
613 | |||
614 | hci_pi(sk)->cookie = 0xffffffff; | ||
615 | ida_simple_remove(&sock_cookie_ida, id); | ||
616 | break; | ||
617 | } | ||
598 | 618 | ||
599 | bt_sock_unlink(&hci_sk_list, sk); | 619 | bt_sock_unlink(&hci_sk_list, sk); |
600 | 620 | ||
@@ -957,6 +977,15 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, | |||
957 | * are changes to settings, class of device, name etc. | 977 | * are changes to settings, class of device, name etc. |
958 | */ | 978 | */ |
959 | if (haddr.hci_channel == HCI_CHANNEL_CONTROL) { | 979 | if (haddr.hci_channel == HCI_CHANNEL_CONTROL) { |
980 | int id; | ||
981 | |||
982 | id = ida_simple_get(&sock_cookie_ida, 1, 0, GFP_KERNEL); | ||
983 | if (id < 0) | ||
984 | id = 0xffffffff; | ||
985 | |||
986 | hci_pi(sk)->cookie = id; | ||
987 | get_task_comm(hci_pi(sk)->comm, current); | ||
988 | |||
960 | hci_sock_set_flag(sk, HCI_MGMT_INDEX_EVENTS); | 989 | hci_sock_set_flag(sk, HCI_MGMT_INDEX_EVENTS); |
961 | hci_sock_set_flag(sk, HCI_MGMT_UNCONF_INDEX_EVENTS); | 990 | hci_sock_set_flag(sk, HCI_MGMT_UNCONF_INDEX_EVENTS); |
962 | hci_sock_set_flag(sk, HCI_MGMT_GENERIC_EVENTS); | 991 | hci_sock_set_flag(sk, HCI_MGMT_GENERIC_EVENTS); |