Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1165930AbdDXHGI (ORCPT ); Mon, 24 Apr 2017 03:06:08 -0400 Received: from m12-16.163.com ([220.181.12.16]:44072 "EHLO m12-16.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1165702AbdDXHFt (ORCPT ); Mon, 24 Apr 2017 03:05:49 -0400 From: Pan Bian To: Jiri Pirko , netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Pan Bian Subject: [PATCH 2/2] net: team: fix memory leak in team_nl_send_options_get Date: Mon, 24 Apr 2017 15:04:55 +0800 Message-Id: <1493017495-3578-1-git-send-email-bianpan2016@163.com> X-Mailer: git-send-email 1.9.1 X-CM-TRANSID: EMCowABXr_OXo_1Y0VYgAg--.45780S3 X-Coremail-Antispam: 1Uf129KBjvdXoWrurWrtFyxurykGFy8CryUZFb_yoWDXFX_Ww 4Ivrs7XwnYkFsFk3W0kw4rXryfKF43Z3WkuFyIk34fta4YyrnFyw1kZr1DAFZ7Kr4xCFZx Gw1DXFyrA34ftjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUn7KsUUUUUU== X-Originating-IP: [106.120.213.67] X-CM-SenderInfo: held01tdqsiiqw6rljoofrz/1tbiQBrDclSISv2snAAAsw Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 972 Lines: 31 In function team_nl_send_options_get(), pointer skb keeps the return value of function nlmsg_new(). When the call to genlmsg_put() fails, the control flow directly returns and does not free skb. This will result in a memory leak bug. This patch fixes it. Fixes: 8ea7fd0d8792 ("team: fix memory leak") Signed-off-by: Pan Bian --- drivers/net/team/team.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c index dd3a2e9..85c0124 100644 --- a/drivers/net/team/team.c +++ b/drivers/net/team/team.c @@ -2361,8 +2361,10 @@ static int team_nl_send_options_get(struct team *team, u32 portid, u32 seq, hdr = genlmsg_put(skb, portid, seq, &team_nl_family, flags | NLM_F_MULTI, TEAM_CMD_OPTIONS_GET); - if (!hdr) + if (!hdr) { + nlmsg_free(skb); return -EMSGSIZE; + } if (nla_put_u32(skb, TEAM_ATTR_TEAM_IFINDEX, team->dev->ifindex)) goto nla_put_failure; -- 1.9.1