aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohannes Berg <johannes.berg@intel.com>2013-11-21 12:17:04 -0500
committerDavid S. Miller <davem@davemloft.net>2013-11-21 13:09:43 -0500
commit220815a9665f7deca98a09ecca655044f94cfa44 (patch)
tree9708d1e73ac82cb2514a1f3305695962281c8852
parente40526cb20b5ee53419452e1f03d97092f144418 (diff)
genetlink: fix genlmsg_multicast() bug
Unfortunately, I introduced a tremendously stupid bug into genlmsg_multicast() when doing all those multicast group changes: it adjusts the group number, but then passes it to genlmsg_multicast_netns() which does that again. Somehow, my tests failed to catch this, so add a warning into genlmsg_multicast_netns() and remove the offending group ID adjustment. Also add a warning to the similar code in other functions so people who misuse them are more loudly warned. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/genetlink.h5
-rw-r--r--net/netlink/genetlink.c4
2 files changed, 3 insertions, 6 deletions
diff --git a/include/net/genetlink.h b/include/net/genetlink.h
index ace4abf118d7..771af09e90eb 100644
--- a/include/net/genetlink.h
+++ b/include/net/genetlink.h
@@ -265,7 +265,7 @@ static inline int genlmsg_multicast_netns(struct genl_family *family,
265 struct net *net, struct sk_buff *skb, 265 struct net *net, struct sk_buff *skb,
266 u32 portid, unsigned int group, gfp_t flags) 266 u32 portid, unsigned int group, gfp_t flags)
267{ 267{
268 if (group >= family->n_mcgrps) 268 if (WARN_ON_ONCE(group >= family->n_mcgrps))
269 return -EINVAL; 269 return -EINVAL;
270 group = family->mcgrp_offset + group; 270 group = family->mcgrp_offset + group;
271 return nlmsg_multicast(net->genl_sock, skb, portid, group, flags); 271 return nlmsg_multicast(net->genl_sock, skb, portid, group, flags);
@@ -283,9 +283,6 @@ static inline int genlmsg_multicast(struct genl_family *family,
283 struct sk_buff *skb, u32 portid, 283 struct sk_buff *skb, u32 portid,
284 unsigned int group, gfp_t flags) 284 unsigned int group, gfp_t flags)
285{ 285{
286 if (group >= family->n_mcgrps)
287 return -EINVAL;
288 group = family->mcgrp_offset + group;
289 return genlmsg_multicast_netns(family, &init_net, skb, 286 return genlmsg_multicast_netns(family, &init_net, skb,
290 portid, group, flags); 287 portid, group, flags);
291} 288}
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index 7dbc4f732c75..4518a57aa5fe 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -1045,7 +1045,7 @@ static int genlmsg_mcast(struct sk_buff *skb, u32 portid, unsigned long group,
1045int genlmsg_multicast_allns(struct genl_family *family, struct sk_buff *skb, 1045int genlmsg_multicast_allns(struct genl_family *family, struct sk_buff *skb,
1046 u32 portid, unsigned int group, gfp_t flags) 1046 u32 portid, unsigned int group, gfp_t flags)
1047{ 1047{
1048 if (group >= family->n_mcgrps) 1048 if (WARN_ON_ONCE(group >= family->n_mcgrps))
1049 return -EINVAL; 1049 return -EINVAL;
1050 group = family->mcgrp_offset + group; 1050 group = family->mcgrp_offset + group;
1051 return genlmsg_mcast(skb, portid, group, flags); 1051 return genlmsg_mcast(skb, portid, group, flags);
@@ -1062,7 +1062,7 @@ void genl_notify(struct genl_family *family,
1062 if (nlh) 1062 if (nlh)
1063 report = nlmsg_report(nlh); 1063 report = nlmsg_report(nlh);
1064 1064
1065 if (group >= family->n_mcgrps) 1065 if (WARN_ON_ONCE(group >= family->n_mcgrps))
1066 return; 1066 return;
1067 group = family->mcgrp_offset + group; 1067 group = family->mcgrp_offset + group;
1068 nlmsg_notify(sk, skb, portid, group, report, flags); 1068 nlmsg_notify(sk, skb, portid, group, report, flags);