|
@@ -334,6 +334,7 @@ int ip_cmsg_send(struct sock *sk, struct msghdr *msg, struct ipcm_cookie *ipc,
|
|
sent to multicast group to reach destination designated router.
|
|
sent to multicast group to reach destination designated router.
|
|
*/
|
|
*/
|
|
struct ip_ra_chain __rcu *ip_ra_chain;
|
|
struct ip_ra_chain __rcu *ip_ra_chain;
|
|
|
|
+static DEFINE_SPINLOCK(ip_ra_lock);
|
|
|
|
|
|
|
|
|
|
static void ip_ra_destroy_rcu(struct rcu_head *head)
|
|
static void ip_ra_destroy_rcu(struct rcu_head *head)
|
|
@@ -355,17 +356,21 @@ int ip_ra_control(struct sock *sk, unsigned char on,
|
|
|
|
|
|
new_ra = on ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL;
|
|
new_ra = on ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL;
|
|
|
|
|
|
|
|
+ spin_lock_bh(&ip_ra_lock);
|
|
for (rap = &ip_ra_chain;
|
|
for (rap = &ip_ra_chain;
|
|
- (ra = rtnl_dereference(*rap)) != NULL;
|
|
|
|
|
|
+ (ra = rcu_dereference_protected(*rap,
|
|
|
|
+ lockdep_is_held(&ip_ra_lock))) != NULL;
|
|
rap = &ra->next) {
|
|
rap = &ra->next) {
|
|
if (ra->sk == sk) {
|
|
if (ra->sk == sk) {
|
|
if (on) {
|
|
if (on) {
|
|
|
|
+ spin_unlock_bh(&ip_ra_lock);
|
|
kfree(new_ra);
|
|
kfree(new_ra);
|
|
return -EADDRINUSE;
|
|
return -EADDRINUSE;
|
|
}
|
|
}
|
|
/* dont let ip_call_ra_chain() use sk again */
|
|
/* dont let ip_call_ra_chain() use sk again */
|
|
ra->sk = NULL;
|
|
ra->sk = NULL;
|
|
RCU_INIT_POINTER(*rap, ra->next);
|
|
RCU_INIT_POINTER(*rap, ra->next);
|
|
|
|
+ spin_unlock_bh(&ip_ra_lock);
|
|
|
|
|
|
if (ra->destructor)
|
|
if (ra->destructor)
|
|
ra->destructor(sk);
|
|
ra->destructor(sk);
|
|
@@ -379,14 +384,17 @@ int ip_ra_control(struct sock *sk, unsigned char on,
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (!new_ra)
|
|
|
|
|
|
+ if (!new_ra) {
|
|
|
|
+ spin_unlock_bh(&ip_ra_lock);
|
|
return -ENOBUFS;
|
|
return -ENOBUFS;
|
|
|
|
+ }
|
|
new_ra->sk = sk;
|
|
new_ra->sk = sk;
|
|
new_ra->destructor = destructor;
|
|
new_ra->destructor = destructor;
|
|
|
|
|
|
RCU_INIT_POINTER(new_ra->next, ra);
|
|
RCU_INIT_POINTER(new_ra->next, ra);
|
|
rcu_assign_pointer(*rap, new_ra);
|
|
rcu_assign_pointer(*rap, new_ra);
|
|
sock_hold(sk);
|
|
sock_hold(sk);
|
|
|
|
+ spin_unlock_bh(&ip_ra_lock);
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|