Skip to content

Commit ae811e2

Browse files
committed
nl80211: check nla_parse() return values
If there's a policy, then nla_parse() return values must be checked, otherwise the policy is useless and there's nothing that ensures the attributes are actually what we expect them to be. Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent c6e1332 commit ae811e2

1 file changed

Lines changed: 23 additions & 14 deletions

File tree

‎net/wireless/nl80211.c‎

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,10 +2055,12 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
20552055
nla_for_each_nested(nl_txq_params,
20562056
info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
20572057
rem_txq_params) {
2058-
nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2059-
nla_data(nl_txq_params),
2060-
nla_len(nl_txq_params),
2061-
txq_params_policy);
2058+
result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2059+
nla_data(nl_txq_params),
2060+
nla_len(nl_txq_params),
2061+
txq_params_policy);
2062+
if (result)
2063+
return result;
20622064
result = parse_txq_params(tb, &txq_params);
20632065
if (result)
20642066
return result;
@@ -5198,9 +5200,11 @@ static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
51985200

51995201
nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
52005202
rem_reg_rules) {
5201-
nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5202-
nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5203-
reg_rule_policy);
5203+
r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5204+
nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5205+
reg_rule_policy);
5206+
if (r)
5207+
goto bad_reg;
52045208
r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
52055209
if (r)
52065210
goto bad_reg;
@@ -5622,9 +5626,11 @@ static int nl80211_start_sched_scan(struct sk_buff *skb,
56225626
tmp) {
56235627
struct nlattr *ssid, *rssi;
56245628

5625-
nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5626-
nla_data(attr), nla_len(attr),
5627-
nl80211_match_policy);
5629+
err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5630+
nla_data(attr), nla_len(attr),
5631+
nl80211_match_policy);
5632+
if (err)
5633+
goto out_free;
56285634
ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
56295635
if (ssid) {
56305636
if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
@@ -7499,16 +7505,19 @@ static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
74997505
* directly to the enum ieee80211_band values used in cfg80211.
75007506
*/
75017507
BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
7502-
nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem)
7503-
{
7508+
nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
75047509
enum ieee80211_band band = nla_type(tx_rates);
7510+
int err;
7511+
75057512
if (band < 0 || band >= IEEE80211_NUM_BANDS)
75067513
return -EINVAL;
75077514
sband = rdev->wiphy.bands[band];
75087515
if (sband == NULL)
75097516
return -EINVAL;
7510-
nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7511-
nla_len(tx_rates), nl80211_txattr_policy);
7517+
err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7518+
nla_len(tx_rates), nl80211_txattr_policy);
7519+
if (err)
7520+
return err;
75127521
if (tb[NL80211_TXRATE_LEGACY]) {
75137522
mask.control[band].legacy = rateset_to_mask(
75147523
sband,

0 commit comments

Comments
 (0)