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/bluetooth/af_bluetooth.c | |
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/bluetooth/af_bluetooth.c')
-rw-r--r-- | net/bluetooth/af_bluetooth.c | 36 |
1 files changed, 29 insertions, 7 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 | ||