Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit b827357

Browse files
jmbergdavem330
authored andcommitted
genetlink: fix netns vs. netlink table locking (2)
Similar to commit d136f1b, there's a bug when unregistering a generic netlink family, which is caught by the might_sleep() added in that commit: BUG: sleeping function called from invalid context at net/netlink/af_netlink.c:183 in_atomic(): 1, irqs_disabled(): 0, pid: 1510, name: rmmod 2 locks held by rmmod/1510: #0: (genl_mutex){+.+.+.}, at: [<ffffffff8138283b>] genl_unregister_family+0x2b/0x130 #1: (rcu_read_lock){.+.+..}, at: [<ffffffff8138270c>] __genl_unregister_mc_group+0x1c/0x120 Pid: 1510, comm: rmmod Not tainted 2.6.31-wl #444 Call Trace: [<ffffffff81044ff9>] __might_sleep+0x119/0x150 [<ffffffff81380501>] netlink_table_grab+0x21/0x100 [<ffffffff813813a3>] netlink_clear_multicast_users+0x23/0x60 [<ffffffff81382761>] __genl_unregister_mc_group+0x71/0x120 [<ffffffff81382866>] genl_unregister_family+0x56/0x130 [<ffffffffa0007d85>] nl80211_exit+0x15/0x20 [cfg80211] [<ffffffffa000005a>] cfg80211_exit+0x1a/0x40 [cfg80211] Fix in the same way by grabbing the netlink table lock before doing rcu_read_lock(). Signed-off-by: Johannes Berg <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 704cc92 commit b827357

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

include/linux/netlink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ extern struct sock *netlink_kernel_create(struct net *net,
187187
extern void netlink_kernel_release(struct sock *sk);
188188
extern int __netlink_change_ngroups(struct sock *sk, unsigned int groups);
189189
extern int netlink_change_ngroups(struct sock *sk, unsigned int groups);
190+
extern void __netlink_clear_multicast_users(struct sock *sk, unsigned int group);
190191
extern void netlink_clear_multicast_users(struct sock *sk, unsigned int group);
191192
extern void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err);
192193
extern int netlink_has_listeners(struct sock *sk, unsigned int group);

net/netlink/af_netlink.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,16 @@ int netlink_change_ngroups(struct sock *sk, unsigned int groups)
16091609
return err;
16101610
}
16111611

1612+
void __netlink_clear_multicast_users(struct sock *ksk, unsigned int group)
1613+
{
1614+
struct sock *sk;
1615+
struct hlist_node *node;
1616+
struct netlink_table *tbl = &nl_table[ksk->sk_protocol];
1617+
1618+
sk_for_each_bound(sk, node, &tbl->mc_list)
1619+
netlink_update_socket_mc(nlk_sk(sk), group, 0);
1620+
}
1621+
16121622
/**
16131623
* netlink_clear_multicast_users - kick off multicast listeners
16141624
*
@@ -1619,15 +1629,8 @@ int netlink_change_ngroups(struct sock *sk, unsigned int groups)
16191629
*/
16201630
void netlink_clear_multicast_users(struct sock *ksk, unsigned int group)
16211631
{
1622-
struct sock *sk;
1623-
struct hlist_node *node;
1624-
struct netlink_table *tbl = &nl_table[ksk->sk_protocol];
1625-
16261632
netlink_table_grab();
1627-
1628-
sk_for_each_bound(sk, node, &tbl->mc_list)
1629-
netlink_update_socket_mc(nlk_sk(sk), group, 0);
1630-
1633+
__netlink_clear_multicast_users(ksk, group);
16311634
netlink_table_ungrab();
16321635
}
16331636

net/netlink/genetlink.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,12 @@ static void __genl_unregister_mc_group(struct genl_family *family,
220220
struct net *net;
221221
BUG_ON(grp->family != family);
222222

223+
netlink_table_grab();
223224
rcu_read_lock();
224225
for_each_net_rcu(net)
225-
netlink_clear_multicast_users(net->genl_sock, grp->id);
226+
__netlink_clear_multicast_users(net->genl_sock, grp->id);
226227
rcu_read_unlock();
228+
netlink_table_ungrab();
227229

228230
clear_bit(grp->id, mc_groups);
229231
list_del(&grp->list);

0 commit comments

Comments
 (0)