From patchwork Sun Jun 12 14:28:16 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jesper Juhl X-Patchwork-Id: 100098 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 60D66B70A7 for ; Mon, 13 Jun 2011 00:36:52 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753995Ab1FLOgo (ORCPT ); Sun, 12 Jun 2011 10:36:44 -0400 Received: from swampdragon.chaosbits.net ([90.184.90.115]:13639 "EHLO swampdragon.chaosbits.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752630Ab1FLOgm (ORCPT ); Sun, 12 Jun 2011 10:36:42 -0400 Received: by swampdragon.chaosbits.net (Postfix, from userid 1000) id CF6899403D; Sun, 12 Jun 2011 16:28:16 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by swampdragon.chaosbits.net (Postfix) with ESMTP id C72199403B; Sun, 12 Jun 2011 16:28:16 +0200 (CEST) Date: Sun, 12 Jun 2011 16:28:16 +0200 (CEST) From: Jesper Juhl To: linux-kernel@vger.kernel.org cc: netdev@vger.kernel.org, linux-zigbee-devel@lists.sourceforge.net, "David S. Miller" , Sergey Lapin , Dmitry Eremin-Solenikov , Maxim Osipov Subject: [PATCH] ieee802154: Don't leak memory in ieee802154_nl_fill_phy Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 Acked-by: Dmitry Eremin-Solenikov --- 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: