[PATCH] ieee802154: Don't leak memory in ieee802154_nl_fill_phy

Subsystems: ieee 802.15.4 subsystem, networking [general], the rest

STALE5529d

3 messages, 3 authors, 2011-06-13 · open the first message on its own page

[PATCH] ieee802154: Don't leak memory in ieee802154_nl_fill_phy

From: Jesper Juhl <hidden>
Date: 2011-06-12 14:36:43

In net/ieee802154/nl-phy.c::ieee802154_nl_fill_phy() I see two small 
issues.
1) If the allocation of 'buf' fails we may just as well return -EMSGSIZE
   directly rather than jumping to 'out:' and do a pointless kfree(0).
2) We do not free 'buf' unless we jump to one of the error labels and this
   leaks memory.
This patch should address both.

Signed-off-by: Jesper Juhl <redacted>
---
 nl-phy.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

  I have no way to properly test this patch, so it's compile tested only.
diff --git a/net/ieee802154/nl-phy.c b/net/ieee802154/nl-phy.c
index ed0eab3..02548b2 100644
--- a/net/ieee802154/nl-phy.c
+++ b/net/ieee802154/nl-phy.c
@@ -44,7 +44,7 @@ static int ieee802154_nl_fill_phy(struct sk_buff *msg, u32 pid,
 	pr_debug("%s\n", __func__);
 
 	if (!buf)
-		goto out;
+		return -EMSGSIZE;
 
 	hdr = genlmsg_put(msg, 0, seq, &nl802154_family, flags,
 		IEEE802154_LIST_PHY);
@@ -65,6 +65,7 @@ static int ieee802154_nl_fill_phy(struct sk_buff *msg, u32 pid,
 				pages * sizeof(uint32_t), buf);
 
 	mutex_unlock(&phy->pib_lock);
+	kfree(buf);
 	return genlmsg_end(msg, hdr);
 
 nla_put_failure:

-- 
Jesper Juhl <jj@chaosbits.net>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.

Re: [PATCH] ieee802154: Don't leak memory in ieee802154_nl_fill_phy

From: Dmitry Eremin-Solenikov <hidden>
Date: 2011-06-13 20:02:41

On 6/12/11, Jesper Juhl [off-list ref] wrote:
In net/ieee802154/nl-phy.c::ieee802154_nl_fill_phy() I see two small
issues.
1) If the allocation of 'buf' fails we may just as well return -EMSGSIZE
   directly rather than jumping to 'out:' and do a pointless kfree(0).
2) We do not free 'buf' unless we jump to one of the error labels and this
   leaks memory.
This patch should address both.

Signed-off-by: Jesper Juhl <redacted>
Acked-by: Dmitry Eremin-Solenikov <redacted>

David, please commit this.

-- 
With best wishes
Dmitry

Re: [PATCH] ieee802154: Don't leak memory in ieee802154_nl_fill_phy

From: David Miller <davem@davemloft.net>
Date: 2011-06-13 22:06:51

From: Dmitry Eremin-Solenikov <redacted>
Date: Tue, 14 Jun 2011 00:02:38 +0400
On 6/12/11, Jesper Juhl [off-list ref] wrote:
quoted
In net/ieee802154/nl-phy.c::ieee802154_nl_fill_phy() I see two small
issues.
1) If the allocation of 'buf' fails we may just as well return -EMSGSIZE
   directly rather than jumping to 'out:' and do a pointless kfree(0).
2) We do not free 'buf' unless we jump to one of the error labels and this
   leaks memory.
This patch should address both.

Signed-off-by: Jesper Juhl <redacted>
Acked-by: Dmitry Eremin-Solenikov <redacted>

David, please commit this.
Applied, thanks.

------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help