Skip to content

Commit 3e8c1a0

Browse files
jmberg-intelgregkh
authored andcommitted
mac80211_hwsim: check HWSIM_ATTR_RADIO_NAME length
[ 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 <andrew.zaborowski@intel.com> Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4a464da commit 3e8c1a0

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

drivers/net/wireless/mac80211_hwsim.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2884,6 +2884,7 @@ static int hwsim_register_received_nl(struct sk_buff *skb_2,
28842884
static int hwsim_new_radio_nl(struct sk_buff *msg, struct genl_info *info)
28852885
{
28862886
struct hwsim_new_radio_params param = { 0 };
2887+
const char *hwname = NULL;
28872888

28882889
param.reg_strict = info->attrs[HWSIM_ATTR_REG_STRICT_REG];
28892890
param.p2p_device = info->attrs[HWSIM_ATTR_SUPPORT_P2P_DEVICE];
@@ -2897,8 +2898,14 @@ static int hwsim_new_radio_nl(struct sk_buff *msg, struct genl_info *info)
28972898
if (info->attrs[HWSIM_ATTR_NO_VIF])
28982899
param.no_vif = true;
28992900

2900-
if (info->attrs[HWSIM_ATTR_RADIO_NAME])
2901-
param.hwname = nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]);
2901+
if (info->attrs[HWSIM_ATTR_RADIO_NAME]) {
2902+
hwname = kasprintf(GFP_KERNEL, "%.*s",
2903+
nla_len(info->attrs[HWSIM_ATTR_RADIO_NAME]),
2904+
(char *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]));
2905+
if (!hwname)
2906+
return -ENOMEM;
2907+
param.hwname = hwname;
2908+
}
29022909

29032910
if (info->attrs[HWSIM_ATTR_USE_CHANCTX])
29042911
param.use_chanctx = true;
@@ -2926,11 +2933,15 @@ static int hwsim_del_radio_nl(struct sk_buff *msg, struct genl_info *info)
29262933
s64 idx = -1;
29272934
const char *hwname = NULL;
29282935

2929-
if (info->attrs[HWSIM_ATTR_RADIO_ID])
2936+
if (info->attrs[HWSIM_ATTR_RADIO_ID]) {
29302937
idx = nla_get_u32(info->attrs[HWSIM_ATTR_RADIO_ID]);
2931-
else if (info->attrs[HWSIM_ATTR_RADIO_NAME])
2932-
hwname = (void *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]);
2933-
else
2938+
} else if (info->attrs[HWSIM_ATTR_RADIO_NAME]) {
2939+
hwname = kasprintf(GFP_KERNEL, "%.*s",
2940+
nla_len(info->attrs[HWSIM_ATTR_RADIO_NAME]),
2941+
(char *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]));
2942+
if (!hwname)
2943+
return -ENOMEM;
2944+
} else
29342945
return -EINVAL;
29352946

29362947
spin_lock_bh(&hwsim_radio_lock);
@@ -2939,18 +2950,21 @@ static int hwsim_del_radio_nl(struct sk_buff *msg, struct genl_info *info)
29392950
if (data->idx != idx)
29402951
continue;
29412952
} else {
2942-
if (strcmp(hwname, wiphy_name(data->hw->wiphy)))
2953+
if (!hwname ||
2954+
strcmp(hwname, wiphy_name(data->hw->wiphy)))
29432955
continue;
29442956
}
29452957

29462958
list_del(&data->list);
29472959
spin_unlock_bh(&hwsim_radio_lock);
29482960
mac80211_hwsim_del_radio(data, wiphy_name(data->hw->wiphy),
29492961
info);
2962+
kfree(hwname);
29502963
return 0;
29512964
}
29522965
spin_unlock_bh(&hwsim_radio_lock);
29532966

2967+
kfree(hwname);
29542968
return -ENODEV;
29552969
}
29562970

0 commit comments

Comments
 (0)