Skip to content

Commit

Permalink
genetlink: hold read cb_lock during iteration of genl_fam_idr in genl…
Browse files Browse the repository at this point in the history
…_bind()

In genl_bind(), currently genl_lock and write cb_lock are taken
for iteration of genl_fam_idr and processing of static values
stored in struct genl_family. Take just read cb_lock for this task
as it is sufficient to guard the idr and the struct against
concurrent genl_register/unregister_family() calls.

This will allow to run genl command processing in genl_rcv() and
mnl_socket_setsockopt(.., NETLINK_ADD_MEMBERSHIP, ..) in parallel.

Reported-by: Vikas Gupta <[email protected]>
Signed-off-by: Jiri Pirko <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
Jiri Pirko authored and kuba-moo committed Aug 27, 2022
1 parent 0c1f77d commit 8f1948b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions net/netlink/genetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ static int genl_bind(struct net *net, int group)
unsigned int id;
int ret = 0;

genl_lock_all();
down_read(&cb_lock);

idr_for_each_entry(&genl_fam_idr, family, id) {
const struct genl_multicast_group *grp;
Expand All @@ -1383,7 +1383,7 @@ static int genl_bind(struct net *net, int group)
break;
}

genl_unlock_all();
up_read(&cb_lock);
return ret;
}

Expand Down

0 comments on commit 8f1948b

Please sign in to comment.