diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2006-10-15 11:31:14 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-10-16 02:14:34 -0400 |
commit | 74da626a1098640ddc40c0e3481c0cd41e8ec1e9 (patch) | |
tree | 65e6f72f07c0cccbb37b3b079d93276b061d9ade /net | |
parent | cb19d9ea2ce2bcbe291d3d48e3501dc4f33ba627 (diff) |
[Bluetooth] Add locking for bt_proto array manipulation
The bt_proto array needs to be protected by some kind of locking to
prevent a race condition between bt_sock_create and bt_sock_register.
And in addition all calls to sk_alloc need to be made GFP_ATOMIC now.
Signed-off-by: Masatake YAMATO <jet@gyve.org>
Signed-off-by: Frederik Deweerdt <frederik.deweerdt@gmail.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net')
-rw-r--r-- | net/bluetooth/af_bluetooth.c | 36 | ||||
-rw-r--r-- | net/bluetooth/bnep/sock.c | 2 | ||||
-rw-r--r-- | net/bluetooth/cmtp/sock.c | 2 | ||||
-rw-r--r-- | net/bluetooth/hci_sock.c | 2 | ||||
-rw-r--r-- | net/bluetooth/hidp/sock.c | 2 | ||||
-rw-r--r-- | net/bluetooth/l2cap.c | 2 | ||||
-rw-r--r-- | net/bluetooth/rfcomm/sock.c | 3 | ||||
-rw-r--r-- | net/bluetooth/sco.c | 3 |
8 files changed, 38 insertions, 14 deletions
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c index a91fee4f2705..67df99e2e5c8 100644 --- a/net/bluetooth/af_bluetooth.c +++ b/net/bluetooth/af_bluetooth.c | |||
@@ -53,36 +53,51 @@ | |||
53 | /* Bluetooth sockets */ | 53 | /* Bluetooth sockets */ |
54 | #define BT_MAX_PROTO 8 | 54 | #define BT_MAX_PROTO 8 |
55 | static struct net_proto_family *bt_proto[BT_MAX_PROTO]; | 55 | static struct net_proto_family *bt_proto[BT_MAX_PROTO]; |
56 | static DEFINE_RWLOCK(bt_proto_lock); | ||
56 | 57 | ||
57 | int bt_sock_register(int proto, struct net_proto_family *ops) | 58 | int bt_sock_register(int proto, struct net_proto_family *ops) |
58 | { | 59 | { |
60 | int err = 0; | ||
61 | |||
59 | if (proto < 0 || proto >= BT_MAX_PROTO) | 62 | if (proto < 0 || proto >= BT_MAX_PROTO) |
60 | return -EINVAL; | 63 | return -EINVAL; |
61 | 64 | ||
65 | write_lock(&bt_proto_lock); | ||
66 | |||
62 | if (bt_proto[proto]) | 67 | if (bt_proto[proto]) |
63 | return -EEXIST; | 68 | err = -EEXIST; |
69 | else | ||
70 | bt_proto[proto] = ops; | ||
64 | 71 | ||
65 | bt_proto[proto] = ops; | 72 | write_unlock(&bt_proto_lock); |
66 | return 0; | 73 | |
74 | return err; | ||
67 | } | 75 | } |
68 | EXPORT_SYMBOL(bt_sock_register); | 76 | EXPORT_SYMBOL(bt_sock_register); |
69 | 77 | ||
70 | int bt_sock_unregister(int proto) | 78 | int bt_sock_unregister(int proto) |
71 | { | 79 | { |
80 | int err = 0; | ||
81 | |||
72 | if (proto < 0 || proto >= BT_MAX_PROTO) | 82 | if (proto < 0 || proto >= BT_MAX_PROTO) |
73 | return -EINVAL; | 83 | return -EINVAL; |
74 | 84 | ||
85 | write_lock(&bt_proto_lock); | ||
86 | |||
75 | if (!bt_proto[proto]) | 87 | if (!bt_proto[proto]) |
76 | return -ENOENT; | 88 | err = -ENOENT; |
89 | else | ||
90 | bt_proto[proto] = NULL; | ||
77 | 91 | ||
78 | bt_proto[proto] = NULL; | 92 | write_unlock(&bt_proto_lock); |
79 | return 0; | 93 | |
94 | return err; | ||
80 | } | 95 | } |
81 | EXPORT_SYMBOL(bt_sock_unregister); | 96 | EXPORT_SYMBOL(bt_sock_unregister); |
82 | 97 | ||
83 | static int bt_sock_create(struct socket *sock, int proto) | 98 | static int bt_sock_create(struct socket *sock, int proto) |
84 | { | 99 | { |
85 | int err = 0; | 100 | int err; |
86 | 101 | ||
87 | if (proto < 0 || proto >= BT_MAX_PROTO) | 102 | if (proto < 0 || proto >= BT_MAX_PROTO) |
88 | return -EINVAL; | 103 | return -EINVAL; |
@@ -92,11 +107,18 @@ static int bt_sock_create(struct socket *sock, int proto) | |||
92 | request_module("bt-proto-%d", proto); | 107 | request_module("bt-proto-%d", proto); |
93 | } | 108 | } |
94 | #endif | 109 | #endif |
110 | |||
95 | err = -EPROTONOSUPPORT; | 111 | err = -EPROTONOSUPPORT; |
112 | |||
113 | read_lock(&bt_proto_lock); | ||
114 | |||
96 | if (bt_proto[proto] && try_module_get(bt_proto[proto]->owner)) { | 115 | if (bt_proto[proto] && try_module_get(bt_proto[proto]->owner)) { |
97 | err = bt_proto[proto]->create(sock, proto); | 116 | err = bt_proto[proto]->create(sock, proto); |
98 | module_put(bt_proto[proto]->owner); | 117 | module_put(bt_proto[proto]->owner); |
99 | } | 118 | } |
119 | |||
120 | read_unlock(&bt_proto_lock); | ||
121 | |||
100 | return err; | 122 | return err; |
101 | } | 123 | } |
102 | 124 | ||
diff --git a/net/bluetooth/bnep/sock.c b/net/bluetooth/bnep/sock.c index 5d9d6f14b310..5563db1bf526 100644 --- a/net/bluetooth/bnep/sock.c +++ b/net/bluetooth/bnep/sock.c | |||
@@ -214,7 +214,7 @@ static int bnep_sock_create(struct socket *sock, int protocol) | |||
214 | if (sock->type != SOCK_RAW) | 214 | if (sock->type != SOCK_RAW) |
215 | return -ESOCKTNOSUPPORT; | 215 | return -ESOCKTNOSUPPORT; |
216 | 216 | ||
217 | sk = sk_alloc(PF_BLUETOOTH, GFP_KERNEL, &bnep_proto, 1); | 217 | sk = sk_alloc(PF_BLUETOOTH, GFP_ATOMIC, &bnep_proto, 1); |
218 | if (!sk) | 218 | if (!sk) |
219 | return -ENOMEM; | 219 | return -ENOMEM; |
220 | 220 | ||
diff --git a/net/bluetooth/cmtp/sock.c b/net/bluetooth/cmtp/sock.c index 0547edd57734..53295d33dc5c 100644 --- a/net/bluetooth/cmtp/sock.c +++ b/net/bluetooth/cmtp/sock.c | |||
@@ -205,7 +205,7 @@ static int cmtp_sock_create(struct socket *sock, int protocol) | |||
205 | if (sock->type != SOCK_RAW) | 205 | if (sock->type != SOCK_RAW) |
206 | return -ESOCKTNOSUPPORT; | 206 | return -ESOCKTNOSUPPORT; |
207 | 207 | ||
208 | sk = sk_alloc(PF_BLUETOOTH, GFP_KERNEL, &cmtp_proto, 1); | 208 | sk = sk_alloc(PF_BLUETOOTH, GFP_ATOMIC, &cmtp_proto, 1); |
209 | if (!sk) | 209 | if (!sk) |
210 | return -ENOMEM; | 210 | return -ENOMEM; |
211 | 211 | ||
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c index 1a35d343e08a..f26a9eb49945 100644 --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c | |||
@@ -618,7 +618,7 @@ static int hci_sock_create(struct socket *sock, int protocol) | |||
618 | 618 | ||
619 | sock->ops = &hci_sock_ops; | 619 | sock->ops = &hci_sock_ops; |
620 | 620 | ||
621 | sk = sk_alloc(PF_BLUETOOTH, GFP_KERNEL, &hci_sk_proto, 1); | 621 | sk = sk_alloc(PF_BLUETOOTH, GFP_ATOMIC, &hci_sk_proto, 1); |
622 | if (!sk) | 622 | if (!sk) |
623 | return -ENOMEM; | 623 | return -ENOMEM; |
624 | 624 | ||
diff --git a/net/bluetooth/hidp/sock.c b/net/bluetooth/hidp/sock.c index 6242446aa270..407fba43c1b9 100644 --- a/net/bluetooth/hidp/sock.c +++ b/net/bluetooth/hidp/sock.c | |||
@@ -256,7 +256,7 @@ static int hidp_sock_create(struct socket *sock, int protocol) | |||
256 | if (sock->type != SOCK_RAW) | 256 | if (sock->type != SOCK_RAW) |
257 | return -ESOCKTNOSUPPORT; | 257 | return -ESOCKTNOSUPPORT; |
258 | 258 | ||
259 | sk = sk_alloc(PF_BLUETOOTH, GFP_KERNEL, &hidp_proto, 1); | 259 | sk = sk_alloc(PF_BLUETOOTH, GFP_ATOMIC, &hidp_proto, 1); |
260 | if (!sk) | 260 | if (!sk) |
261 | return -ENOMEM; | 261 | return -ENOMEM; |
262 | 262 | ||
diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c index 66fc621a077c..2b3dcb8f90fa 100644 --- a/net/bluetooth/l2cap.c +++ b/net/bluetooth/l2cap.c | |||
@@ -559,7 +559,7 @@ static int l2cap_sock_create(struct socket *sock, int protocol) | |||
559 | 559 | ||
560 | sock->ops = &l2cap_sock_ops; | 560 | sock->ops = &l2cap_sock_ops; |
561 | 561 | ||
562 | sk = l2cap_sock_alloc(sock, protocol, GFP_KERNEL); | 562 | sk = l2cap_sock_alloc(sock, protocol, GFP_ATOMIC); |
563 | if (!sk) | 563 | if (!sk) |
564 | return -ENOMEM; | 564 | return -ENOMEM; |
565 | 565 | ||
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c index 530cc41f3a22..544d65b7baa7 100644 --- a/net/bluetooth/rfcomm/sock.c +++ b/net/bluetooth/rfcomm/sock.c | |||
@@ -336,7 +336,8 @@ static int rfcomm_sock_create(struct socket *sock, int protocol) | |||
336 | 336 | ||
337 | sock->ops = &rfcomm_sock_ops; | 337 | sock->ops = &rfcomm_sock_ops; |
338 | 338 | ||
339 | if (!(sk = rfcomm_sock_alloc(sock, protocol, GFP_KERNEL))) | 339 | sk = rfcomm_sock_alloc(sock, protocol, GFP_ATOMIC); |
340 | if (!sk) | ||
340 | return -ENOMEM; | 341 | return -ENOMEM; |
341 | 342 | ||
342 | rfcomm_sock_init(sk, NULL); | 343 | rfcomm_sock_init(sk, NULL); |
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c index 14b0f6930637..5d13d4f31753 100644 --- a/net/bluetooth/sco.c +++ b/net/bluetooth/sco.c | |||
@@ -452,7 +452,8 @@ static int sco_sock_create(struct socket *sock, int protocol) | |||
452 | 452 | ||
453 | sock->ops = &sco_sock_ops; | 453 | sock->ops = &sco_sock_ops; |
454 | 454 | ||
455 | if (!(sk = sco_sock_alloc(sock, protocol, GFP_KERNEL))) | 455 | sk = sco_sock_alloc(sock, protocol, GFP_ATOMIC); |
456 | if (!sk) | ||
456 | return -ENOMEM; | 457 | return -ENOMEM; |
457 | 458 | ||
458 | sco_sock_init(sk, NULL); | 459 | sco_sock_init(sk, NULL); |