Skip to content

Commit

Permalink
[GENETLINK]: Fix race in genl_unregister_mc_groups()
Browse files Browse the repository at this point in the history
family->mcast_groups is protected by genl_lock so it must
be held while accessing the list in genl_unregister_mc_groups().
Requires adding a non-locking variant of genl_unregister_mc_group().

Signed-off-by: Thomas Graf <tgraf@suug.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Thomas Graf authored and David S. Miller committed Jul 24, 2007
1 parent 85ccc36 commit 79dc438
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions net/netlink/genetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,18 @@ int genl_register_mc_group(struct genl_family *family,
}
EXPORT_SYMBOL(genl_register_mc_group);

static void __genl_unregister_mc_group(struct genl_family *family,
struct genl_multicast_group *grp)
{
BUG_ON(grp->family != family);
netlink_clear_multicast_users(genl_sock, grp->id);
clear_bit(grp->id, mc_groups);
list_del(&grp->list);
genl_ctrl_event(CTRL_CMD_DELMCAST_GRP, grp);
grp->id = 0;
grp->family = NULL;
}

/**
* genl_unregister_mc_group - unregister a multicast group
*
Expand All @@ -217,23 +229,19 @@ EXPORT_SYMBOL(genl_register_mc_group);
void genl_unregister_mc_group(struct genl_family *family,
struct genl_multicast_group *grp)
{
BUG_ON(grp->family != family);
genl_lock();
netlink_clear_multicast_users(genl_sock, grp->id);
clear_bit(grp->id, mc_groups);
list_del(&grp->list);
genl_ctrl_event(CTRL_CMD_DELMCAST_GRP, grp);
grp->id = 0;
grp->family = NULL;
__genl_unregister_mc_group(family, grp);
genl_unlock();
}

static void genl_unregister_mc_groups(struct genl_family *family)
{
struct genl_multicast_group *grp, *tmp;

genl_lock();
list_for_each_entry_safe(grp, tmp, &family->mcast_groups, list)
genl_unregister_mc_group(family, grp);
__genl_unregister_mc_group(family, grp);
genl_unlock();
}

/**
Expand Down

0 comments on commit 79dc438

Please sign in to comment.