aboutsummaryrefslogtreecommitdiffstats
path: root/net/nfc
diff options
context:
space:
mode:
authorJohannes Berg <johannes.berg@intel.com>2013-11-19 09:19:39 -0500
committerDavid S. Miller <davem@davemloft.net>2013-11-19 16:39:06 -0500
commit2a94fe48f32ccf7321450a2cc07f2b724a444e5b (patch)
treee5a066d8f83d8822d448421019a4503f361295f9 /net/nfc
parent68eb55031da7c967d954e5f9415cd05f4abdb692 (diff)
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>
Diffstat (limited to 'net/nfc')
-rw-r--r--net/nfc/netlink.c51
1 files changed, 19 insertions, 32 deletions
diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
index 3092df313fb1..a9b2342d5253 100644
--- a/net/nfc/netlink.c
+++ b/net/nfc/netlink.c
@@ -30,8 +30,8 @@
30#include "nfc.h" 30#include "nfc.h"
31#include "llcp.h" 31#include "llcp.h"
32 32
33static struct genl_multicast_group nfc_genl_event_mcgrp = { 33static const struct genl_multicast_group nfc_genl_mcgrps[] = {
34 .name = NFC_GENL_MCAST_EVENT_NAME, 34 { .name = NFC_GENL_MCAST_EVENT_NAME, },
35}; 35};
36 36
37static struct genl_family nfc_genl_family = { 37static struct genl_family nfc_genl_family = {
@@ -194,8 +194,7 @@ int nfc_genl_targets_found(struct nfc_dev *dev)
194 194
195 genlmsg_end(msg, hdr); 195 genlmsg_end(msg, hdr);
196 196
197 return genlmsg_multicast(&nfc_genl_family, msg, 0, 197 return genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
198 nfc_genl_event_mcgrp.id, GFP_ATOMIC);
199 198
200nla_put_failure: 199nla_put_failure:
201 genlmsg_cancel(msg, hdr); 200 genlmsg_cancel(msg, hdr);
@@ -224,8 +223,7 @@ int nfc_genl_target_lost(struct nfc_dev *dev, u32 target_idx)
224 223
225 genlmsg_end(msg, hdr); 224 genlmsg_end(msg, hdr);
226 225
227 genlmsg_multicast(&nfc_genl_family, msg, 0, 226 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
228 nfc_genl_event_mcgrp.id, GFP_KERNEL);
229 227
230 return 0; 228 return 0;
231 229
@@ -257,8 +255,7 @@ int nfc_genl_tm_activated(struct nfc_dev *dev, u32 protocol)
257 255
258 genlmsg_end(msg, hdr); 256 genlmsg_end(msg, hdr);
259 257
260 genlmsg_multicast(&nfc_genl_family, msg, 0, 258 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
261 nfc_genl_event_mcgrp.id, GFP_KERNEL);
262 259
263 return 0; 260 return 0;
264 261
@@ -288,8 +285,7 @@ int nfc_genl_tm_deactivated(struct nfc_dev *dev)
288 285
289 genlmsg_end(msg, hdr); 286 genlmsg_end(msg, hdr);
290 287
291 genlmsg_multicast(&nfc_genl_family, msg, 0, 288 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
292 nfc_genl_event_mcgrp.id, GFP_KERNEL);
293 289
294 return 0; 290 return 0;
295 291
@@ -322,8 +318,7 @@ int nfc_genl_device_added(struct nfc_dev *dev)
322 318
323 genlmsg_end(msg, hdr); 319 genlmsg_end(msg, hdr);
324 320
325 genlmsg_multicast(&nfc_genl_family, msg, 0, 321 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
326 nfc_genl_event_mcgrp.id, GFP_KERNEL);
327 322
328 return 0; 323 return 0;
329 324
@@ -353,8 +348,7 @@ int nfc_genl_device_removed(struct nfc_dev *dev)
353 348
354 genlmsg_end(msg, hdr); 349 genlmsg_end(msg, hdr);
355 350
356 genlmsg_multicast(&nfc_genl_family, msg, 0, 351 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
357 nfc_genl_event_mcgrp.id, GFP_KERNEL);
358 352
359 return 0; 353 return 0;
360 354
@@ -420,8 +414,7 @@ int nfc_genl_llc_send_sdres(struct nfc_dev *dev, struct hlist_head *sdres_list)
420 414
421 genlmsg_end(msg, hdr); 415 genlmsg_end(msg, hdr);
422 416
423 return genlmsg_multicast(&nfc_genl_family, msg, 0, 417 return genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
424 nfc_genl_event_mcgrp.id, GFP_ATOMIC);
425 418
426nla_put_failure: 419nla_put_failure:
427 genlmsg_cancel(msg, hdr); 420 genlmsg_cancel(msg, hdr);
@@ -455,8 +448,7 @@ int nfc_genl_se_added(struct nfc_dev *dev, u32 se_idx, u16 type)
455 448
456 genlmsg_end(msg, hdr); 449 genlmsg_end(msg, hdr);
457 450
458 genlmsg_multicast(&nfc_genl_family, msg, 0, 451 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
459 nfc_genl_event_mcgrp.id, GFP_KERNEL);
460 452
461 return 0; 453 return 0;
462 454
@@ -487,8 +479,7 @@ int nfc_genl_se_removed(struct nfc_dev *dev, u32 se_idx)
487 479
488 genlmsg_end(msg, hdr); 480 genlmsg_end(msg, hdr);
489 481
490 genlmsg_multicast(&nfc_genl_family, msg, 0, 482 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
491 nfc_genl_event_mcgrp.id, GFP_KERNEL);
492 483
493 return 0; 484 return 0;
494 485
@@ -609,8 +600,7 @@ int nfc_genl_dep_link_up_event(struct nfc_dev *dev, u32 target_idx,
609 600
610 dev->dep_link_up = true; 601 dev->dep_link_up = true;
611 602
612 genlmsg_multicast(&nfc_genl_family, msg, 0, 603 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
613 nfc_genl_event_mcgrp.id, GFP_ATOMIC);
614 604
615 return 0; 605 return 0;
616 606
@@ -642,8 +632,7 @@ int nfc_genl_dep_link_down_event(struct nfc_dev *dev)
642 632
643 genlmsg_end(msg, hdr); 633 genlmsg_end(msg, hdr);
644 634
645 genlmsg_multicast(&nfc_genl_family, msg, 0, 635 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_ATOMIC);
646 nfc_genl_event_mcgrp.id, GFP_ATOMIC);
647 636
648 return 0; 637 return 0;
649 638
@@ -1148,8 +1137,7 @@ int nfc_genl_fw_download_done(struct nfc_dev *dev, const char *firmware_name,
1148 1137
1149 genlmsg_end(msg, hdr); 1138 genlmsg_end(msg, hdr);
1150 1139
1151 genlmsg_multicast(&nfc_genl_family, msg, 0, 1140 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
1152 nfc_genl_event_mcgrp.id, GFP_KERNEL);
1153 1141
1154 return 0; 1142 return 0;
1155 1143
@@ -1320,8 +1308,7 @@ static void se_io_cb(void *context, u8 *apdu, size_t apdu_len, int err)
1320 1308
1321 genlmsg_end(msg, hdr); 1309 genlmsg_end(msg, hdr);
1322 1310
1323 genlmsg_multicast(&nfc_genl_family, msg, 0, 1311 genlmsg_multicast(&nfc_genl_family, msg, 0, 0, GFP_KERNEL);
1324 nfc_genl_event_mcgrp.id, GFP_KERNEL);
1325 1312
1326 kfree(ctx); 1313 kfree(ctx);
1327 1314
@@ -1549,15 +1536,15 @@ int __init nfc_genl_init(void)
1549{ 1536{
1550 int rc; 1537 int rc;
1551 1538
1552 rc = genl_register_family_with_ops(&nfc_genl_family, nfc_genl_ops); 1539 rc = genl_register_family_with_ops_groups(&nfc_genl_family,
1540 nfc_genl_ops,
1541 nfc_genl_mcgrps);
1553 if (rc) 1542 if (rc)
1554 return rc; 1543 return rc;
1555 1544
1556 rc = genl_register_mc_group(&nfc_genl_family, &nfc_genl_event_mcgrp);
1557
1558 netlink_register_notifier(&nl_notifier); 1545 netlink_register_notifier(&nl_notifier);
1559 1546
1560 return rc; 1547 return 0;
1561} 1548}
1562 1549
1563/** 1550/**