netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Stanislaw Gruszka <sgruszka@redhat.com>,
	Johannes Berg <johannes.berg@intel.com>,
	Sasha Levin <sashal@kernel.org>,
	linux-wireless@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 4.19 087/205] cfg80211: validate wmm rule when setting
Date: Fri,  8 Nov 2019 06:35:54 -0500	[thread overview]
Message-ID: <20191108113752.12502-87-sashal@kernel.org> (raw)
In-Reply-To: <20191108113752.12502-1-sashal@kernel.org>

From: Stanislaw Gruszka <sgruszka@redhat.com>

[ Upstream commit 014f5a250fc49fa8c6cd50093e725e71f3ae52da ]

Add validation check for wmm rule when copy rules from fwdb and print
error when rule is invalid.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 net/wireless/reg.c | 64 +++++++++++++++++++++++++---------------------
 1 file changed, 35 insertions(+), 29 deletions(-)

diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 68ae97ef8bf0b..64841238df855 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -847,22 +847,36 @@ static bool valid_regdb(const u8 *data, unsigned int size)
 	return true;
 }
 
-static void set_wmm_rule(struct ieee80211_reg_rule *rrule,
-			 struct fwdb_wmm_rule *wmm)
-{
-	struct ieee80211_wmm_rule *rule = &rrule->wmm_rule;
-	unsigned int i;
+static void set_wmm_rule(const struct fwdb_header *db,
+			 const struct fwdb_country *country,
+			 const struct fwdb_rule *rule,
+			 struct ieee80211_reg_rule *rrule)
+{
+	struct ieee80211_wmm_rule *wmm_rule = &rrule->wmm_rule;
+	struct fwdb_wmm_rule *wmm;
+	unsigned int i, wmm_ptr;
+
+	wmm_ptr = be16_to_cpu(rule->wmm_ptr) << 2;
+	wmm = (void *)((u8 *)db + wmm_ptr);
+
+	if (!valid_wmm(wmm)) {
+		pr_err("Invalid regulatory WMM rule %u-%u in domain %c%c\n",
+		       be32_to_cpu(rule->start), be32_to_cpu(rule->end),
+		       country->alpha2[0], country->alpha2[1]);
+		return;
+	}
 
 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
-		rule->client[i].cw_min =
+		wmm_rule->client[i].cw_min =
 			ecw2cw((wmm->client[i].ecw & 0xf0) >> 4);
-		rule->client[i].cw_max = ecw2cw(wmm->client[i].ecw & 0x0f);
-		rule->client[i].aifsn =  wmm->client[i].aifsn;
-		rule->client[i].cot = 1000 * be16_to_cpu(wmm->client[i].cot);
-		rule->ap[i].cw_min = ecw2cw((wmm->ap[i].ecw & 0xf0) >> 4);
-		rule->ap[i].cw_max = ecw2cw(wmm->ap[i].ecw & 0x0f);
-		rule->ap[i].aifsn = wmm->ap[i].aifsn;
-		rule->ap[i].cot = 1000 * be16_to_cpu(wmm->ap[i].cot);
+		wmm_rule->client[i].cw_max = ecw2cw(wmm->client[i].ecw & 0x0f);
+		wmm_rule->client[i].aifsn =  wmm->client[i].aifsn;
+		wmm_rule->client[i].cot =
+			1000 * be16_to_cpu(wmm->client[i].cot);
+		wmm_rule->ap[i].cw_min = ecw2cw((wmm->ap[i].ecw & 0xf0) >> 4);
+		wmm_rule->ap[i].cw_max = ecw2cw(wmm->ap[i].ecw & 0x0f);
+		wmm_rule->ap[i].aifsn = wmm->ap[i].aifsn;
+		wmm_rule->ap[i].cot = 1000 * be16_to_cpu(wmm->ap[i].cot);
 	}
 
 	rrule->has_wmm = true;
@@ -870,7 +884,7 @@ static void set_wmm_rule(struct ieee80211_reg_rule *rrule,
 
 static int __regdb_query_wmm(const struct fwdb_header *db,
 			     const struct fwdb_country *country, int freq,
-			     struct ieee80211_reg_rule *rule)
+			     struct ieee80211_reg_rule *rrule)
 {
 	unsigned int ptr = be16_to_cpu(country->coll_ptr) << 2;
 	struct fwdb_collection *coll = (void *)((u8 *)db + ptr);
@@ -879,18 +893,14 @@ static int __regdb_query_wmm(const struct fwdb_header *db,
 	for (i = 0; i < coll->n_rules; i++) {
 		__be16 *rules_ptr = (void *)((u8 *)coll + ALIGN(coll->len, 2));
 		unsigned int rule_ptr = be16_to_cpu(rules_ptr[i]) << 2;
-		struct fwdb_rule *rrule = (void *)((u8 *)db + rule_ptr);
-		struct fwdb_wmm_rule *wmm;
-		unsigned int wmm_ptr;
+		struct fwdb_rule *rule = (void *)((u8 *)db + rule_ptr);
 
-		if (rrule->len < offsetofend(struct fwdb_rule, wmm_ptr))
+		if (rule->len < offsetofend(struct fwdb_rule, wmm_ptr))
 			continue;
 
-		if (freq >= KHZ_TO_MHZ(be32_to_cpu(rrule->start)) &&
-		    freq <= KHZ_TO_MHZ(be32_to_cpu(rrule->end))) {
-			wmm_ptr = be16_to_cpu(rrule->wmm_ptr) << 2;
-			wmm = (void *)((u8 *)db + wmm_ptr);
-			set_wmm_rule(rule, wmm);
+		if (freq >= KHZ_TO_MHZ(be32_to_cpu(rule->start)) &&
+		    freq <= KHZ_TO_MHZ(be32_to_cpu(rule->end))) {
+			set_wmm_rule(db, country, rule, rrule);
 			return 0;
 		}
 	}
@@ -972,12 +982,8 @@ static int regdb_query_country(const struct fwdb_header *db,
 		if (rule->len >= offsetofend(struct fwdb_rule, cac_timeout))
 			rrule->dfs_cac_ms =
 				1000 * be16_to_cpu(rule->cac_timeout);
-		if (rule->len >= offsetofend(struct fwdb_rule, wmm_ptr)) {
-			u32 wmm_ptr = be16_to_cpu(rule->wmm_ptr) << 2;
-			struct fwdb_wmm_rule *wmm = (void *)((u8 *)db + wmm_ptr);
-
-			set_wmm_rule(rrule, wmm);
-		}
+		if (rule->len >= offsetofend(struct fwdb_rule, wmm_ptr))
+			set_wmm_rule(db, country, rule, rrule);
 	}
 
 	return reg_schedule_apply(regdom);
-- 
2.20.1


  parent reply	other threads:[~2019-11-08 11:40 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20191108113752.12502-1-sashal@kernel.org>
2019-11-08 11:34 ` [PATCH AUTOSEL 4.19 003/205] ath10k: fix kernel panic by moving pci flush after napi_disable Sasha Levin
2019-11-08 11:34 ` [PATCH AUTOSEL 4.19 021/205] cfg80211: Avoid regulatory restore when COUNTRY_IE_IGNORE is set Sasha Levin
2019-11-08 11:34 ` [PATCH AUTOSEL 4.19 023/205] ath10k: skip resetting rx filter for WCN3990 Sasha Levin
2019-11-08 11:34 ` [PATCH AUTOSEL 4.19 024/205] ath9k: fix tx99 with monitor mode interface Sasha Levin
2019-11-08 11:34 ` [PATCH AUTOSEL 4.19 025/205] wil6210: drop Rx multicast packets that are looped-back to STA Sasha Levin
2019-11-08 11:34 ` [PATCH AUTOSEL 4.19 026/205] wil6210: set edma variables only for Talyn-MB devices Sasha Levin
2019-11-08 11:34 ` [PATCH AUTOSEL 4.19 027/205] wil6210: prevent usage of tx ring 0 for eDMA Sasha Levin
2019-11-08 11:34 ` [PATCH AUTOSEL 4.19 028/205] wil6210: fix invalid memory access for rx_buff_mgmt debugfs Sasha Levin
2019-11-08 11:34 ` [PATCH AUTOSEL 4.19 029/205] ath10k: limit available channels via DT ieee80211-freq-limit Sasha Levin
2019-11-08 11:34 ` [PATCH AUTOSEL 4.19 030/205] ice: Update request resource command to latest specification Sasha Levin
2019-11-08 11:34 ` [PATCH AUTOSEL 4.19 031/205] ice: Prevent control queue operations during reset Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 033/205] ice: Fix and update driver version string Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 043/205] liquidio: fix race condition in instruction completion processing Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 046/205] i40evf: Validate the number of queues a PF sends Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 047/205] i40e: use correct length for strncpy Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 048/205] i40evf: set IFF_UNICAST_FLT flag for the VF Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 049/205] i40e: Check and correct speed values for link on open Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 050/205] i40evf: Don't enable vlan stripping when rx offload is turned on Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 051/205] i40e: hold the rtnl lock on clearing interrupt scheme Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 052/205] i40evf: cancel workqueue sync for adminq when a VF is removed Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 053/205] i40e: Prevent deleting MAC address from VF when set by PF Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 056/205] iwlwifi: drop packets with bad status in CD Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 057/205] iwlwifi: don't WARN on trying to dump dead firmware Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 058/205] iwlwifi: mvm: avoid sending too many BARs Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 064/205] rtl8187: Fix warning generated when strncpy() destination length matches the sixe argument Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 065/205] mwifiex: do no submit URB in suspended state Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 066/205] mwifex: free rx_cmd skb " Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 067/205] brcmfmac: fix wrong strnchr usage Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 068/205] mt76: Fix comparisons with invalid hardware key index Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 071/205] net: hns3: Fix for multicast failure Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 072/205] net: hns3: Fix error of checking used vlan id Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 073/205] net: hns3: Fix for loopback selftest failed problem Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 074/205] net: hns3: Change the dst mac addr of loopback packet Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 075/205] net/mlx5: Fix atomic_mode enum values Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 076/205] net: phy: mscc: read 'vsc8531,vddmac' as an u32 Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 077/205] net: phy: mscc: read 'vsc8531, edge-slowdown' " Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 086/205] mac80211: fix saving a few HE values Sasha Levin
2019-11-08 11:35 ` Sasha Levin [this message]
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 089/205] net: lan78xx: Bail out if lan78xx_get_endpoints fails Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 090/205] rtnetlink: move type calculation out of loop Sasha Levin
2019-11-08 11:35 ` [PATCH AUTOSEL 4.19 092/205] ath10k: avoid possible memory access violation Sasha Levin
2019-11-08 11:36 ` [PATCH AUTOSEL 4.19 094/205] ath10k: wmi: disable softirq's while calling ieee80211_rx Sasha Levin
2019-11-08 11:36 ` [PATCH AUTOSEL 4.19 113/205] failover: Fix error return code in net_failover_create Sasha Levin
2019-11-08 11:36 ` [PATCH AUTOSEL 4.19 127/205] ath9k: add back support for using active monitor interfaces for tx99 Sasha Levin
2019-11-08 11:37 ` [PATCH AUTOSEL 4.19 155/205] net: aquantia: fix hw_atl_utils_fw_upload_dwords Sasha Levin
2019-11-08 11:37 ` [PATCH AUTOSEL 4.19 162/205] net: bcmgenet: Fix speed selection for reverse MII Sasha Levin
2019-11-08 11:37 ` [PATCH AUTOSEL 4.19 171/205] MIPS: lantiq: Do not enable IRQs in dma open Sasha Levin
2019-11-08 11:37 ` [PATCH AUTOSEL 4.19 172/205] llc: avoid blocking in llc_sap_close() Sasha Levin
2019-11-08 11:37 ` [PATCH AUTOSEL 4.19 188/205] cxgb4: Fix endianness issue in t4_fwcache() Sasha Levin
2019-11-08 11:37 ` [PATCH AUTOSEL 4.19 198/205] ip_gre: fix parsing gre header in ipgre_err Sasha Levin
2019-11-08 11:37 ` [PATCH AUTOSEL 4.19 203/205] netfilter: nf_tables: avoid BUG_ON usage Sasha Levin
2019-11-08 11:37 ` [PATCH AUTOSEL 4.19 205/205] ath9k: Fix a locking bug in ath9k_add_interface() Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191108113752.12502-87-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=johannes.berg@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sgruszka@redhat.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).