Return-Path: Received: from mail-co1nam03on0118.outbound.protection.outlook.com ([104.47.40.118]:42464 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932586AbeARVEd (ORCPT ); Thu, 18 Jan 2018 16:04:33 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Ben Hutchings , Johannes Berg , Sasha Levin Subject: [added to the 4.1 stable tree] mac80211_hwsim: Fix memory leak in hwsim_new_radio_nl() Date: Thu, 18 Jan 2018 21:01:05 +0000 Message-ID: <20180118205908.3220-189-alexander.levin@microsoft.com> References: <20180118205908.3220-1-alexander.levin@microsoft.com> In-Reply-To: <20180118205908.3220-1-alexander.levin@microsoft.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 This patch has been added to the stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ 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 03097016fd43..aafb97ce080d 100644 --- a/drivers/net/wireless/mac80211_hwsim.c +++ b/drivers/net/wireless/mac80211_hwsim.c @@ -2884,6 +2884,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]; @@ -2923,7 +2924,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