diff mbox

[1/1] nl80211: check return code for genlmsg_end

Message ID 1305555848-17609-1-git-send-email-wey-yi.w.guy@intel.com (mailing list archive)
State Not Applicable, archived
Headers show

Commit Message

Guy, Wey-Yi W May 16, 2011, 2:24 p.m. UTC
Check the return value for genlmsg_end and handle it.

Signed-off-by: Wey-Yi Guy <wey-yi.w.guy@intel.com>
---
 net/wireless/nl80211.c |   40 +++++++++++++++++++++++++++++++---------
 1 files changed, 31 insertions(+), 9 deletions(-)

Comments

Johannes Berg May 18, 2011, 11:04 p.m. UTC | #1
On Mon, 2011-05-16 at 07:24 -0700, Wey-Yi Guy wrote:
> Check the return value for genlmsg_end and handle it.

It can never return < 0:

/**
 * nlmsg_end - Finalize a netlink message
 * @skb: socket buffer the message is stored in
 * @nlh: netlink message header
 *
 * Corrects the netlink message header to include the appeneded
 * attributes. Only necessary if attributes have been added to
 * the message.
 *
 * Returns the total data length of the skb.


johannes

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Guy, Wey-Yi W May 19, 2011, 12:10 a.m. UTC | #2
On Wed, 2011-05-18 at 16:04 -0700, Johannes Berg wrote:
> On Mon, 2011-05-16 at 07:24 -0700, Wey-Yi Guy wrote:
> > Check the return value for genlmsg_end and handle it.
> 
> It can never return < 0:
> 
> /**
>  * nlmsg_end - Finalize a netlink message
>  * @skb: socket buffer the message is stored in
>  * @nlh: netlink message header
>  *
>  * Corrects the netlink message header to include the appeneded
>  * attributes. Only necessary if attributes have been added to
>  * the message.
>  *
>  * Returns the total data length of the skb.
> 

do we should remove all the checking all together?

Wey
> 


--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 9ef8e28..51ffb8d 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -1686,7 +1686,9 @@  static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
 	if (cookie.error)
 		goto nla_put_failure;
 
-	genlmsg_end(msg, hdr);
+	if (genlmsg_end(msg, hdr) < 0)
+		goto free_msg;
+
 	return genlmsg_reply(msg, info);
 
  nla_put_failure:
@@ -2851,7 +2853,9 @@  static int nl80211_get_mesh_config(struct sk_buff *skb,
 	NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
 			cur_params.dot11MeshHWMPRootMode);
 	nla_nest_end(msg, pinfoattr);
-	genlmsg_end(msg, hdr);
+	if (genlmsg_end(msg, hdr) < 0)
+		goto out;
+
 	return genlmsg_reply(msg, info);
 
  nla_put_failure:
@@ -3098,7 +3102,9 @@  static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
 
 	nla_nest_end(msg, nl_reg_rules);
 
-	genlmsg_end(msg, hdr);
+	if (genlmsg_end(msg, hdr) < 0)
+		goto put_failure;
+
 	err = genlmsg_reply(msg, info);
 	goto out;
 
@@ -4347,8 +4353,13 @@  int cfg80211_testmode_reply(struct sk_buff *skb)
 	}
 
 	nla_nest_end(skb, data);
-	genlmsg_end(skb, hdr);
+	if (genlmsg_end(skb, hdr) < 0)
+		goto out;
+
 	return genlmsg_reply(skb, rdev->testmode_info);
+out:
+	kfree_skb(skb);
+	return -ENOBUFS;
 }
 EXPORT_SYMBOL(cfg80211_testmode_reply);
 
@@ -4367,8 +4378,12 @@  void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
 	struct nlattr *data = ((void **)skb->cb)[2];
 
 	nla_nest_end(skb, data);
-	genlmsg_end(skb, hdr);
+	if (genlmsg_end(skb, hdr) < 0) {
+		kfree_skb(skb);
+		return;
+	}
 	genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
+
 }
 EXPORT_SYMBOL(cfg80211_testmode_event);
 #endif
@@ -4612,7 +4627,8 @@  static int nl80211_remain_on_channel(struct sk_buff *skb,
 
 	NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
 
-	genlmsg_end(msg, hdr);
+	if (genlmsg_end(msg, hdr) < 0)
+		goto free_msg;
 
 	return genlmsg_reply(msg, info);
 
@@ -4829,7 +4845,9 @@  static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
 
 	NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie);
 
-	genlmsg_end(msg, hdr);
+	if (genlmsg_end(msg, hdr) < 0)
+		goto free_msg;
+
 	return genlmsg_reply(msg, info);
 
  nla_put_failure:
@@ -4931,7 +4949,9 @@  static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
 
 	NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state);
 
-	genlmsg_end(msg, hdr);
+	if (genlmsg_end(msg, hdr) < 0)
+		goto free_msg;
+
 	return genlmsg_reply(msg, info);
 
  nla_put_failure:
@@ -5105,7 +5125,9 @@  static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
 		nla_nest_end(msg, nl_wowlan);
 	}
 
-	genlmsg_end(msg, hdr);
+	if (genlmsg_end(msg, hdr) < 0)
+		goto nla_put_failure;
+
 	return genlmsg_reply(msg, info);
 
 nla_put_failure: