Skip to content

Commit ff4dd73

Browse files
committed
mac80211_hwsim: check HWSIM_ATTR_RADIO_NAME length
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 <[email protected]> Signed-off-by: Johannes Berg <[email protected]>
1 parent 09e0a2f commit ff4dd73

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

drivers/net/wireless/mac80211_hwsim.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3056,6 +3056,7 @@ static int hwsim_register_received_nl(struct sk_buff *skb_2,
30563056
static int hwsim_new_radio_nl(struct sk_buff *msg, struct genl_info *info)
30573057
{
30583058
struct hwsim_new_radio_params param = { 0 };
3059+
const char *hwname = NULL;
30593060

30603061
param.reg_strict = info->attrs[HWSIM_ATTR_REG_STRICT_REG];
30613062
param.p2p_device = info->attrs[HWSIM_ATTR_SUPPORT_P2P_DEVICE];
@@ -3069,8 +3070,14 @@ static int hwsim_new_radio_nl(struct sk_buff *msg, struct genl_info *info)
30693070
if (info->attrs[HWSIM_ATTR_NO_VIF])
30703071
param.no_vif = true;
30713072

3072-
if (info->attrs[HWSIM_ATTR_RADIO_NAME])
3073-
param.hwname = nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]);
3073+
if (info->attrs[HWSIM_ATTR_RADIO_NAME]) {
3074+
hwname = kasprintf(GFP_KERNEL, "%.*s",
3075+
nla_len(info->attrs[HWSIM_ATTR_RADIO_NAME]),
3076+
(char *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]));
3077+
if (!hwname)
3078+
return -ENOMEM;
3079+
param.hwname = hwname;
3080+
}
30743081

30753082
if (info->attrs[HWSIM_ATTR_USE_CHANCTX])
30763083
param.use_chanctx = true;
@@ -3098,11 +3105,15 @@ static int hwsim_del_radio_nl(struct sk_buff *msg, struct genl_info *info)
30983105
s64 idx = -1;
30993106
const char *hwname = NULL;
31003107

3101-
if (info->attrs[HWSIM_ATTR_RADIO_ID])
3108+
if (info->attrs[HWSIM_ATTR_RADIO_ID]) {
31023109
idx = nla_get_u32(info->attrs[HWSIM_ATTR_RADIO_ID]);
3103-
else if (info->attrs[HWSIM_ATTR_RADIO_NAME])
3104-
hwname = (void *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]);
3105-
else
3110+
} else if (info->attrs[HWSIM_ATTR_RADIO_NAME]) {
3111+
hwname = kasprintf(GFP_KERNEL, "%.*s",
3112+
nla_len(info->attrs[HWSIM_ATTR_RADIO_NAME]),
3113+
(char *)nla_data(info->attrs[HWSIM_ATTR_RADIO_NAME]));
3114+
if (!hwname)
3115+
return -ENOMEM;
3116+
} else
31063117
return -EINVAL;
31073118

31083119
spin_lock_bh(&hwsim_radio_lock);
@@ -3111,7 +3122,8 @@ static int hwsim_del_radio_nl(struct sk_buff *msg, struct genl_info *info)
31113122
if (data->idx != idx)
31123123
continue;
31133124
} else {
3114-
if (strcmp(hwname, wiphy_name(data->hw->wiphy)))
3125+
if (!hwname ||
3126+
strcmp(hwname, wiphy_name(data->hw->wiphy)))
31153127
continue;
31163128
}
31173129

@@ -3122,10 +3134,12 @@ static int hwsim_del_radio_nl(struct sk_buff *msg, struct genl_info *info)
31223134
spin_unlock_bh(&hwsim_radio_lock);
31233135
mac80211_hwsim_del_radio(data, wiphy_name(data->hw->wiphy),
31243136
info);
3137+
kfree(hwname);
31253138
return 0;
31263139
}
31273140
spin_unlock_bh(&hwsim_radio_lock);
31283141

3142+
kfree(hwname);
31293143
return -ENODEV;
31303144
}
31313145

0 commit comments

Comments
 (0)