Return-Path: Received: from fldsmtpe03.verizon.com ([140.108.26.142]:57343 "EHLO fldsmtpe03.verizon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752418AbdLBPx4 (ORCPT ); Sat, 2 Dec 2017 10:53:56 -0500 From: alexander.levin@verizon.com Cc: Ben Hutchings , Johannes Berg , alexander.levin@verizon.com To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" Subject: [PATCH AUTOSEL for 4.4 02/20] mac80211_hwsim: Fix memory leak in hwsim_new_radio_nl() Date: Sat, 2 Dec 2017 15:52:51 +0000 Message-ID: <20171202155243.7774-2-alexander.levin@verizon.com> References: <20171202155243.7774-1-alexander.levin@verizon.com> In-Reply-To: <20171202155243.7774-1-alexander.levin@verizon.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Ben Hutchings [ Upstream commit 67bd52386125ce1159c0581cbcd2740addf33cd4 ] hwsim_new_radio_nl() now copies the name attribute in order to add a null-terminator. mac80211_hwsim_new_radio() (indirectly) copies it again into the net_device structure, so the first copy is not used or freed later. Free the first copy before returning. Fixes: ff4dd73dd2b4 ("mac80211_hwsim: check HWSIM_ATTR_RADIO_NAME length") Signed-off-by: Ben Hutchings Signed-off-by: Johannes Berg Signed-off-by: Sasha Levin --- drivers/net/wireless/mac80211_hwsim.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/m= ac80211_hwsim.c index 2a996a68fc2b..f877fbc7d7af 100644 --- a/drivers/net/wireless/mac80211_hwsim.c +++ b/drivers/net/wireless/mac80211_hwsim.c @@ -2885,6 +2885,7 @@ static int hwsim_new_radio_nl(struct sk_buff *msg, st= ruct genl_info *info) { struct hwsim_new_radio_params param =3D { 0 }; const char *hwname =3D NULL; + int ret; =20 param.reg_strict =3D info->attrs[HWSIM_ATTR_REG_STRICT_REG]; param.p2p_device =3D info->attrs[HWSIM_ATTR_SUPPORT_P2P_DEVICE]; @@ -2924,7 +2925,9 @@ static int hwsim_new_radio_nl(struct sk_buff *msg, st= ruct genl_info *info) param.regd =3D hwsim_world_regdom_custom[idx]; } =20 - return mac80211_hwsim_new_radio(info, ¶m); + ret =3D mac80211_hwsim_new_radio(info, ¶m); + kfree(hwname); + return ret; } =20 static int hwsim_del_radio_nl(struct sk_buff *msg, struct genl_info *info) --=20 2.11.0