genetlink: make multicast groups const, prevent abuse
Register generic netlink multicast groups as an array with
the family and give them contiguous group IDs. Then instead
of passing the global group ID to the various functions that
send messages, pass the ID relative to the family - for most
families that's just 0 because the only have one group.
This avoids the list_head and ID in each group, adding a new
field for the mcast group ID offset to the family.
At the same time, this allows us to prevent abusing groups
again like the quota and dropmon code did, since we can now
check that a family only uses a group it owns.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
index 3092df31..a9b2342 100644
--- a/net/nfc/netlink.c
+++ b/net/nfc/netlink.c
@@ -30,8 +30,8 @@
#include "nfc.h"
#include "llcp.h"
-static struct genl_multicast_group nfc_genl_event_mcgrp = {
- .name = NFC_GENL_MCAST_EVENT_NAME,
+static const struct genl_multicast_group nfc_genl_mcgrps[] = {
+ { .name = NFC_GENL_MCAST_EVENT_NAME, },
};
static struct genl_family nfc_genl_family = {
@@ -194,8 +194,7 @@
genlmsg_end(msg, hdr);
- return genlmsg_multicast(&nfc_genl_family, msg, 0,
- nfc_genl_event_mcgrp.id, GFP_ATOMIC);
+ return genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
nla_put_failure:
genlmsg_cancel(msg, hdr);
@@ -224,8 +223,7 @@
genlmsg_end(msg, hdr);
- genlmsg_multicast(&nfc_genl_family, msg, 0,
- nfc_genl_event_mcgrp.id, GFP_KERNEL);
+ genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
return 0;
@@ -257,8 +255,7 @@
genlmsg_end(msg, hdr);
- genlmsg_multicast(&nfc_genl_family, msg, 0,
- nfc_genl_event_mcgrp.id, GFP_KERNEL);
+ genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
return 0;
@@ -288,8 +285,7 @@
genlmsg_end(msg, hdr);
- genlmsg_multicast(&nfc_genl_family, msg, 0,
- nfc_genl_event_mcgrp.id, GFP_KERNEL);
+ genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
return 0;
@@ -322,8 +318,7 @@
genlmsg_end(msg, hdr);
- genlmsg_multicast(&nfc_genl_family, msg, 0,
- nfc_genl_event_mcgrp.id, GFP_KERNEL);
+ genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
return 0;
@@ -353,8 +348,7 @@
genlmsg_end(msg, hdr);
- genlmsg_multicast(&nfc_genl_family, msg, 0,
- nfc_genl_event_mcgrp.id, GFP_KERNEL);
+ genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
return 0;
@@ -420,8 +414,7 @@
genlmsg_end(msg, hdr);
- return genlmsg_multicast(&nfc_genl_family, msg, 0,
- nfc_genl_event_mcgrp.id, GFP_ATOMIC);
+ return genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
nla_put_failure:
genlmsg_cancel(msg, hdr);
@@ -455,8 +448,7 @@
genlmsg_end(msg, hdr);
- genlmsg_multicast(&nfc_genl_family, msg, 0,
- nfc_genl_event_mcgrp.id, GFP_KERNEL);
+ genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
return 0;
@@ -487,8 +479,7 @@
genlmsg_end(msg, hdr);
- genlmsg_multicast(&nfc_genl_family, msg, 0,
- nfc_genl_event_mcgrp.id, GFP_KERNEL);
+ genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
return 0;
@@ -609,8 +600,7 @@
dev->dep_link_up = true;
- genlmsg_multicast(&nfc_genl_family, msg, 0,
- nfc_genl_event_mcgrp.id, GFP_ATOMIC);
+ genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
return 0;
@@ -642,8 +632,7 @@
genlmsg_end(msg, hdr);
- genlmsg_multicast(&nfc_genl_family, msg, 0,
- nfc_genl_event_mcgrp.id, GFP_ATOMIC);
+ genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
return 0;
@@ -1148,8 +1137,7 @@
genlmsg_end(msg, hdr);
- genlmsg_multicast(&nfc_genl_family, msg, 0,
- nfc_genl_event_mcgrp.id, GFP_KERNEL);
+ genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
return 0;
@@ -1320,8 +1308,7 @@
genlmsg_end(msg, hdr);
- genlmsg_multicast(&nfc_genl_family, msg, 0,
- nfc_genl_event_mcgrp.id, GFP_KERNEL);
+ genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
kfree(ctx);
@@ -1549,15 +1536,15 @@
{
int rc;
- rc = genl_register_family_with_ops(&nfc_genl_family, nfc_genl_ops);
+ rc = genl_register_family_with_ops_groups(&nfc_genl_family,
+ nfc_genl_ops,
+ nfc_genl_mcgrps);
if (rc)
return rc;
- rc = genl_register_mc_group(&nfc_genl_family, &nfc_genl_event_mcgrp);
-
netlink_register_notifier(&nl_notifier);
- return rc;
+ return 0;
}
/**