Path: csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!bofh.it!news.nic.it!robomod From: "Levin, Alexander (Sasha Levin)" Newsgroups: linux.kernel Subject: [PATCH review for 4.9 06/50] mac80211_hwsim: check HWSIM_ATTR_RADIO_NAME length Date: Mon, 25 Sep 2017 03:40:03 +0200 Message-ID: References: Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1506302045; x=1537838045; h=from:cc:to:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=trthQ9M3SiyP8qgRnLHJvLzL2B+y2WyA3bWTVRcksGs=; b=NXsVyuNNPKBOhQJRGg8OQ5ZAY8aSZmJyeyB6B7du5i/Mvm/Xg99W4ILb 0SPRpkTSYveUj7fT8m1Gqh+SQojTt4/va0xOZWVLrEGHWHobn1MgUWWVp x0m72bF43wLZaazFwmkqvzXBFnVMc59f4wIqbRDVVTfIlyOGefX5sn1QX Y=; Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1506301966; x=1537837966; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=trthQ9M3SiyP8qgRnLHJvLzL2B+y2WyA3bWTVRcksGs=; b=fZ30KfkZ7gU30+Ayt8SkEOBR8Pg7blx+Czkc9J95LnLTDgVJ9vk7EtIi 2hwzRNktv4eO1CinPyYPxzcE1p3kit6UCArM4xuRLFHO3emJDQ0R9e43l Go8JOz6LQkAn+v4eQBiTi3kDsa3HsGVDV3NpoLowxhy3FmPmN8zjCHj22 c=; Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=verizon.com; i=@verizon.com; q=dns/txt; s=corp; t=1506301966; x=1537837966; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=trthQ9M3SiyP8qgRnLHJvLzL2B+y2WyA3bWTVRcksGs=; b=fZ30KfkZ7gU30+Ayt8SkEOBR8Pg7blx+Czkc9J95LnLTDgVJ9vk7EtIi 2hwzRNktv4eO1CinPyYPxzcE1p3kit6UCArM4xuRLFHO3emJDQ0R9e43l Go8JOz6LQkAn+v4eQBiTi3kDsa3HsGVDV3NpoLowxhy3FmPmN8zjCHj22 c=; X-Host: ranger.odc.vzwcorp.com Thread-Topic: [PATCH review for 4.9 06/50] mac80211_hwsim: check HWSIM_ATTR_RADIO_NAME length Thread-Index: AQHTNZtis1qt0peKC0OXVfJUrjr4Cw== Accept-Language: en-US Content-Language: en-US X-Ms-Exchange-Messagesentrepresentingtype: 1 X-Ms-Exchange-Transport-Fromentityheader: Hosted X-Originating-IP: [10.144.60.250] Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: robomod@news.nic.it List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Approved: robomod@news.nic.it Lines: 98 Organization: linux.* mail to news gateway X-Original-Cc: Johannes Berg , "Levin, Alexander (Sasha Levin)" X-Original-Date: Mon, 25 Sep 2017 01:12:41 +0000 X-Original-Message-ID: <20170925011225.10029-6-alexander.levin@verizon.com> X-Original-References: <20170925011225.10029-1-alexander.levin@verizon.com> X-Original-Sender: linux-kernel-owner@vger.kernel.org Xref: csiph.com linux.kernel:1738699 From: Johannes Berg [ Upstream commit ff4dd73dd2b4806419f8ff65cbce11d5019548d0 ] Unfortunately, the nla policy was defined to have HWSIM_ATTR_RADIO_NAME as an NLA_STRING, rather than NLA_NUL_STRING, so we can't use it as a NUL-terminated string in the kernel. Rather than break the API, kasprintf() the string to a new buffer to guarantee NUL termination. Reported-by: Andrew Zaborowski Signed-off-by: Johannes Berg Signed-off-by: Sasha Levin --- drivers/net/wireless/mac80211_hwsim.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/m= ac80211_hwsim.c index 0fd7d7ed07ce..77528d647b6e 100644 --- a/drivers/net/wireless/mac80211_hwsim.c +++ b/drivers/net/wireless/mac80211_hwsim.c @@ -3048,6 +3048,7 @@ static int hwsim_register_received_nl(struct sk_buff = *skb_2, static int hwsim_new_radio_nl(struct sk_buff *msg, struct genl_info *info) { struct hwsim_new_radio_params param =3D { 0 }; + const char *hwname =3D NULL; =20 param.reg_strict =3D info->attrs[HWSIM_ATTR_REG_STRICT_REG]; param.p2p_device =3D info->attrs[HWSIM_ATTR_SUPPORT_P2P_DEVICE]; @@ -3061,8 +3062,14 @@ static int hwsim_new_radio_nl(struct sk_buff *msg, s= truct genl_info *info) if (info->attrs[HWSIM_ATTR_NO_VIF]) param.no_vif =3D true; =20 - if (info->attrs[HWSIM_ATTR_RADIO_NAME]) - param.hwname =3D nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]); + if (info->attrs[HWSIM_ATTR_RADIO_NAME]) { + hwname =3D kasprintf(GFP_KERNEL, "%.*s", + nla_len(info->attrs[HWSIM_ATTR_RADIO_NAME]), + (char *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME])); + if (!hwname) + return -ENOMEM; + param.hwname =3D hwname; + } =20 if (info->attrs[HWSIM_ATTR_USE_CHANCTX]) param.use_chanctx =3D true; @@ -3090,11 +3097,15 @@ static int hwsim_del_radio_nl(struct sk_buff *msg, = struct genl_info *info) s64 idx =3D -1; const char *hwname =3D NULL; =20 - if (info->attrs[HWSIM_ATTR_RADIO_ID]) + if (info->attrs[HWSIM_ATTR_RADIO_ID]) { idx =3D nla_get_u32(info->attrs[HWSIM_ATTR_RADIO_ID]); - else if (info->attrs[HWSIM_ATTR_RADIO_NAME]) - hwname =3D (void *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]); - else + } else if (info->attrs[HWSIM_ATTR_RADIO_NAME]) { + hwname =3D kasprintf(GFP_KERNEL, "%.*s", + nla_len(info->attrs[HWSIM_ATTR_RADIO_NAME]), + (char *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME])); + if (!hwname) + return -ENOMEM; + } else return -EINVAL; =20 spin_lock_bh(&hwsim_radio_lock); @@ -3103,7 +3114,8 @@ static int hwsim_del_radio_nl(struct sk_buff *msg, st= ruct genl_info *info) if (data->idx !=3D idx) continue; } else { - if (strcmp(hwname, wiphy_name(data->hw->wiphy))) + if (!hwname || + strcmp(hwname, wiphy_name(data->hw->wiphy))) continue; } =20 @@ -3114,10 +3126,12 @@ static int hwsim_del_radio_nl(struct sk_buff *msg, = struct genl_info *info) spin_unlock_bh(&hwsim_radio_lock); mac80211_hwsim_del_radio(data, wiphy_name(data->hw->wiphy), info); + kfree(hwname); return 0; } spin_unlock_bh(&hwsim_radio_lock); =20 + kfree(hwname); return -ENODEV; } =20 --=20 2.11.0