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: Alex Elder <elder@linaro.org>,
	"David S . Miller" <davem@davemloft.net>,
	Sasha Levin <sashal@kernel.org>,
	netdev@vger.kernel.org
Subject: [PATCH AUTOSEL 5.14 071/252] net: ipa: fix ipa_cmd_table_valid()
Date: Thu,  9 Sep 2021 07:38:05 -0400	[thread overview]
Message-ID: <20210909114106.141462-71-sashal@kernel.org> (raw)
In-Reply-To: <20210909114106.141462-1-sashal@kernel.org>

From: Alex Elder <elder@linaro.org>

[ Upstream commit f2c1dac0abcfa93e8b20065b8d6b4b2b6f9990aa ]

Stop supporting different sizes for hashed and non-hashed filter or
route tables.  Add BUILD_BUG_ON() calls to verify the sizes of the
fields in the filter/route table initialization immediate command
are the same.

Add a check to ipa_cmd_table_valid() to ensure the size of the
memory region being checked fits within the immediate command field
that must hold it.

Remove two Boolean parameters used only for error reporting.  This
actually fixes a bug that would only show up if IPA_VALIDATE were
defined.  Define ipa_cmd_table_valid() unconditionally (no longer
dependent on IPA_VALIDATE).

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/net/ipa/ipa_cmd.c   | 38 ++++++++++++++++++++++++-------------
 drivers/net/ipa/ipa_cmd.h   | 15 +++------------
 drivers/net/ipa/ipa_table.c |  2 +-
 3 files changed, 29 insertions(+), 26 deletions(-)

diff --git a/drivers/net/ipa/ipa_cmd.c b/drivers/net/ipa/ipa_cmd.c
index af44ca41189e..bda8677eae88 100644
--- a/drivers/net/ipa/ipa_cmd.c
+++ b/drivers/net/ipa/ipa_cmd.c
@@ -159,35 +159,45 @@ static void ipa_cmd_validate_build(void)
 	BUILD_BUG_ON(TABLE_SIZE > field_max(IP_FLTRT_FLAGS_NHASH_SIZE_FMASK));
 #undef TABLE_COUNT_MAX
 #undef TABLE_SIZE
-}
 
-#ifdef IPA_VALIDATE
+	/* Hashed and non-hashed fields are assumed to be the same size */
+	BUILD_BUG_ON(field_max(IP_FLTRT_FLAGS_HASH_SIZE_FMASK) !=
+		     field_max(IP_FLTRT_FLAGS_NHASH_SIZE_FMASK));
+	BUILD_BUG_ON(field_max(IP_FLTRT_FLAGS_HASH_ADDR_FMASK) !=
+		     field_max(IP_FLTRT_FLAGS_NHASH_ADDR_FMASK));
+}
 
 /* Validate a memory region holding a table */
-bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem,
-			 bool route, bool ipv6, bool hashed)
+bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, bool route)
 {
+	u32 offset_max = field_max(IP_FLTRT_FLAGS_NHASH_ADDR_FMASK);
+	u32 size_max = field_max(IP_FLTRT_FLAGS_NHASH_SIZE_FMASK);
+	const char *table = route ? "route" : "filter";
 	struct device *dev = &ipa->pdev->dev;
-	u32 offset_max;
 
-	offset_max = hashed ? field_max(IP_FLTRT_FLAGS_HASH_ADDR_FMASK)
-			    : field_max(IP_FLTRT_FLAGS_NHASH_ADDR_FMASK);
+	/* Size must fit in the immediate command field that holds it */
+	if (mem->size > size_max) {
+		dev_err(dev, "%s table region size too large\n", table);
+		dev_err(dev, "    (0x%04x > 0x%04x)\n",
+			mem->size, size_max);
+
+		return false;
+	}
+
+	/* Offset must fit in the immediate command field that holds it */
 	if (mem->offset > offset_max ||
 	    ipa->mem_offset > offset_max - mem->offset) {
-		dev_err(dev, "IPv%c %s%s table region offset too large\n",
-			ipv6 ? '6' : '4', hashed ? "hashed " : "",
-			route ? "route" : "filter");
+		dev_err(dev, "%s table region offset too large\n", table);
 		dev_err(dev, "    (0x%04x + 0x%04x > 0x%04x)\n",
 			ipa->mem_offset, mem->offset, offset_max);
 
 		return false;
 	}
 
+	/* Entire memory range must fit within IPA-local memory */
 	if (mem->offset > ipa->mem_size ||
 	    mem->size > ipa->mem_size - mem->offset) {
-		dev_err(dev, "IPv%c %s%s table region out of range\n",
-			ipv6 ? '6' : '4', hashed ? "hashed " : "",
-			route ? "route" : "filter");
+		dev_err(dev, "%s table region out of range\n", table);
 		dev_err(dev, "    (0x%04x + 0x%04x > 0x%04x)\n",
 			mem->offset, mem->size, ipa->mem_size);
 
@@ -197,6 +207,8 @@ bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem,
 	return true;
 }
 
+#ifdef IPA_VALIDATE
+
 /* Validate the memory region that holds headers */
 static bool ipa_cmd_header_valid(struct ipa *ipa)
 {
diff --git a/drivers/net/ipa/ipa_cmd.h b/drivers/net/ipa/ipa_cmd.h
index b99262281f41..ea723419c826 100644
--- a/drivers/net/ipa/ipa_cmd.h
+++ b/drivers/net/ipa/ipa_cmd.h
@@ -57,20 +57,18 @@ struct ipa_cmd_info {
 	enum dma_data_direction direction;
 };
 
-#ifdef IPA_VALIDATE
-
 /**
  * ipa_cmd_table_valid() - Validate a memory region holding a table
  * @ipa:	- IPA pointer
  * @mem:	- IPA memory region descriptor
  * @route:	- Whether the region holds a route or filter table
- * @ipv6:	- Whether the table is for IPv6 or IPv4
- * @hashed:	- Whether the table is hashed or non-hashed
  *
  * Return:	true if region is valid, false otherwise
  */
 bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem,
-			    bool route, bool ipv6, bool hashed);
+			    bool route);
+
+#ifdef IPA_VALIDATE
 
 /**
  * ipa_cmd_data_valid() - Validate command-realted configuration is valid
@@ -82,13 +80,6 @@ bool ipa_cmd_data_valid(struct ipa *ipa);
 
 #else /* !IPA_VALIDATE */
 
-static inline bool ipa_cmd_table_valid(struct ipa *ipa,
-				       const struct ipa_mem *mem, bool route,
-				       bool ipv6, bool hashed)
-{
-	return true;
-}
-
 static inline bool ipa_cmd_data_valid(struct ipa *ipa)
 {
 	return true;
diff --git a/drivers/net/ipa/ipa_table.c b/drivers/net/ipa/ipa_table.c
index c617a9156f26..4f5b6749f6aa 100644
--- a/drivers/net/ipa/ipa_table.c
+++ b/drivers/net/ipa/ipa_table.c
@@ -161,7 +161,7 @@ ipa_table_valid_one(struct ipa *ipa, enum ipa_mem_id mem_id, bool route)
 	else
 		size = (1 + IPA_FILTER_COUNT_MAX) * sizeof(__le64);
 
-	if (!ipa_cmd_table_valid(ipa, mem, route, ipv6, hashed))
+	if (!ipa_cmd_table_valid(ipa, mem, route))
 		return false;
 
 	/* mem->size >= size is sufficient, but we'll demand more */
-- 
2.30.2


  parent reply	other threads:[~2021-09-09 11:45 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210909114106.141462-1-sashal@kernel.org>
2021-09-09 11:37 ` [PATCH AUTOSEL 5.14 017/252] libbpf: Fix reuse of pinned map on older kernel Sasha Levin
2021-09-09 11:37 ` [PATCH AUTOSEL 5.14 022/252] tipc: keep the skb in rcv queue until the whole data is read Sasha Levin
2021-09-09 11:37 ` [PATCH AUTOSEL 5.14 023/252] net: phy: Fix data type in DP83822 dp8382x_disable_wol() Sasha Levin
2021-09-09 11:37 ` [PATCH AUTOSEL 5.14 025/252] iavf: do not override the adapter state in the watchdog task Sasha Levin
2021-09-09 11:37 ` [PATCH AUTOSEL 5.14 026/252] iavf: fix locking of critical sections Sasha Levin
2021-09-09 11:37 ` [PATCH AUTOSEL 5.14 030/252] netlink: Deal with ESRCH error in nlmsg_notify() Sasha Levin
2021-09-09 11:37 ` [PATCH AUTOSEL 5.14 032/252] net: ipa: fix IPA v4.11 interconnect data Sasha Levin
2021-09-09 11:37 ` [PATCH AUTOSEL 5.14 038/252] igc: Check if num of q_vectors is smaller than max before array access Sasha Levin
2021-09-09 11:37 ` [PATCH AUTOSEL 5.14 057/252] nfp: fix return statement in nfp_net_parse_meta() Sasha Levin
2021-09-09 11:37 ` [PATCH AUTOSEL 5.14 060/252] ethtool: improve compat ioctl handling Sasha Levin
2021-09-09 11:37 ` [PATCH AUTOSEL 5.14 064/252] bpf/tests: Fix copy-and-paste error in double word test Sasha Levin
2021-09-09 11:37 ` [PATCH AUTOSEL 5.14 065/252] bpf/tests: Do not PASS tests without actually testing the result Sasha Levin
2021-09-09 11:38 ` Sasha Levin [this message]
2021-09-09 11:38 ` [PATCH AUTOSEL 5.14 072/252] net: ipa: always validate filter and route tables Sasha Levin
2021-09-09 11:38 ` [PATCH AUTOSEL 5.14 073/252] ipv4: ip_output.c: Fix out-of-bounds warning in ip_copy_addrs() Sasha Levin
2021-09-09 11:38 ` [PATCH AUTOSEL 5.14 074/252] flow_dissector: Fix out-of-bounds warnings Sasha Levin
2021-09-09 11:38 ` [PATCH AUTOSEL 5.14 085/252] samples: bpf: Fix tracex7 error raised on the missing argument Sasha Levin
2021-09-09 11:38 ` [PATCH AUTOSEL 5.14 086/252] libbpf: Fix race when pinning maps in parallel Sasha Levin
2021-09-09 11:38 ` [PATCH AUTOSEL 5.14 090/252] Bluetooth: skip invalid hci_sync_conn_complete_evt Sasha Levin
2021-09-09 11:38 ` [PATCH AUTOSEL 5.14 096/252] netfilter: nft_compat: use nfnetlink_unicast() Sasha Levin
2021-09-09 11:38 ` [PATCH AUTOSEL 5.14 097/252] bonding: 3ad: fix the concurrency between __bond_release_one() and bond_3ad_state_machine_handler() Sasha Levin
2021-09-09 11:38 ` [PATCH AUTOSEL 5.14 101/252] bpf: Fix off-by-one in tail call count limiting Sasha Levin
2021-09-14  4:08   ` Johan Almbladh
2021-09-09 11:38 ` [PATCH AUTOSEL 5.14 103/252] Bluetooth: Fix not generating RPA when required Sasha Levin
2021-09-09 11:38 ` [PATCH AUTOSEL 5.14 104/252] dpaa2-switch: do not enable the DPSW at probe time Sasha Levin
2021-09-09 11:38 ` [PATCH AUTOSEL 5.14 114/252] net: ipa: fix IPA v4.9 interconnects Sasha Levin
2021-09-09 11:39 ` [PATCH AUTOSEL 5.14 126/252] net: ethernet: stmmac: Do not use unreachable() in ipq806x_gmac_probe() Sasha Levin
2021-09-09 11:39 ` [PATCH AUTOSEL 5.14 137/252] selftests/bpf: Fix xdp_tx.c prog section name Sasha Levin
2021-09-09 11:39 ` [PATCH AUTOSEL 5.14 140/252] Bluetooth: schedule SCO timeouts with delayed_work Sasha Levin
2021-09-09 11:39 ` [PATCH AUTOSEL 5.14 141/252] Bluetooth: avoid circular locks in sco_sock_connect Sasha Levin
2021-09-09 11:39 ` [PATCH AUTOSEL 5.14 146/252] net/mlx5: Fix variable type to match 64bit Sasha Levin
2021-09-09 11:39 ` [PATCH AUTOSEL 5.14 149/252] mac80211: Fix monitor MTU limit so that A-MSDUs get through Sasha Levin
2021-09-09 11:39 ` [PATCH AUTOSEL 5.14 160/252] Bluetooth: Fix handling of LE Enhanced Connection Complete Sasha Levin
2021-09-09 11:39 ` [PATCH AUTOSEL 5.14 161/252] Bluetooth: Fix race condition in handling NOP command Sasha Levin
2021-09-09 11:39 ` [PATCH AUTOSEL 5.14 165/252] tcp: enable data-less, empty-cookie SYN with TFO_SERVER_COOKIE_NOT_REQD Sasha Levin
2021-09-09 11:39 ` [PATCH AUTOSEL 5.14 168/252] rpc: fix gss_svc_init cleanup on failure Sasha Levin
2021-09-09 11:39 ` [PATCH AUTOSEL 5.14 169/252] iavf: use mutexes for locking of critical sections Sasha Levin
2021-09-09 11:39 ` [PATCH AUTOSEL 5.14 170/252] selftests/bpf: Correctly display subtest skip status Sasha Levin
2021-09-09 11:39 ` [PATCH AUTOSEL 5.14 171/252] selftests/bpf: Fix flaky send_signal test Sasha Levin
2021-09-09 11:39 ` [PATCH AUTOSEL 5.14 174/252] selftests: nci: Fix the code for next nlattr offset Sasha Levin
2021-09-09 11:39 ` [PATCH AUTOSEL 5.14 175/252] selftests: nci: Fix the wrong condition Sasha Levin
2021-09-09 11:39 ` [PATCH AUTOSEL 5.14 176/252] net: Fix offloading indirect devices dependency on qdisc order creation Sasha Levin
2021-09-09 11:39 ` [PATCH AUTOSEL 5.14 184/252] rtl8xxxu: Fix the handling of TX A-MPDU aggregation Sasha Levin
2021-09-09 11:39 ` [PATCH AUTOSEL 5.14 185/252] rtw88: use read_poll_timeout instead of fixed sleep Sasha Levin
2021-09-09 11:40 ` [PATCH AUTOSEL 5.14 186/252] rtw88: wow: build wow function only if CONFIG_PM is on Sasha Levin
2021-09-09 11:40 ` [PATCH AUTOSEL 5.14 187/252] rtw88: wow: fix size access error of probe request Sasha Levin
2021-09-09 11:40 ` [PATCH AUTOSEL 5.14 188/252] octeontx2-pf: Fix NIX1_RX interface backpressure Sasha Levin
2021-09-09 11:40 ` [PATCH AUTOSEL 5.14 209/252] mptcp: fix ADD_ADDR and RM_ADDR maybe flush addr_signal each other Sasha Levin
2021-09-09 22:33   ` Mat Martineau
2021-09-11 14:37     ` Sasha Levin
2021-09-09 11:40 ` [PATCH AUTOSEL 5.14 210/252] selftests/bpf: Enlarge select() timeout for test_maps Sasha Levin
2021-09-09 11:40 ` [PATCH AUTOSEL 5.14 212/252] octeontx2-pf: cleanup transmit link deriving logic Sasha Levin
2021-09-09 11:40 ` [PATCH AUTOSEL 5.14 228/252] iwlwifi: pcie: free RBs during configure Sasha Levin
2021-09-09 11:40 ` [PATCH AUTOSEL 5.14 229/252] iwlwifi: mvm: Do not use full SSIDs in 6GHz scan Sasha Levin
2021-09-09 11:40 ` [PATCH AUTOSEL 5.14 230/252] iwlwifi: mvm: fix a memory leak in iwl_mvm_mac_ctxt_beacon_changed Sasha Levin
2021-09-09 11:40 ` [PATCH AUTOSEL 5.14 231/252] iwlwifi: mvm: avoid static queue number aliasing Sasha Levin
2021-09-09 11:40 ` [PATCH AUTOSEL 5.14 232/252] iwlwifi: mvm: Fix umac scan request probe parameters Sasha Levin
2021-09-09 11:40 ` [PATCH AUTOSEL 5.14 233/252] iwlwifi: mvm: fix access to BSS elements Sasha Levin
2021-09-09 11:40 ` [PATCH AUTOSEL 5.14 234/252] iwlwifi: fw: correctly limit to monitor dump Sasha Levin
2021-09-09 11:40 ` [PATCH AUTOSEL 5.14 235/252] iwlwifi: mvm: don't schedule the roc_done_wk if it is already running Sasha Levin
2021-09-09 11:40 ` [PATCH AUTOSEL 5.14 236/252] iwlwifi: mvm: Fix scan channel flags settings Sasha Levin
2021-09-09 11:40 ` [PATCH AUTOSEL 5.14 237/252] net/mlx5: DR, fix a potential use-after-free bug Sasha Levin
2021-09-09 11:40 ` [PATCH AUTOSEL 5.14 238/252] net/mlx5: DR, Enable QP retransmission Sasha Levin
2021-09-09 11:40 ` [PATCH AUTOSEL 5.14 245/252] selftests/bpf: Fix potential unreleased lock Sasha Levin
2021-09-09 11:41 ` [PATCH AUTOSEL 5.14 246/252] wcn36xx: Fix missing frame timestamp for beacon/probe-resp Sasha Levin
2021-09-09 11:41 ` [PATCH AUTOSEL 5.14 247/252] ath9k: fix OOB read ar9300_eeprom_restore_internal Sasha Levin
2021-09-09 11:41 ` [PATCH AUTOSEL 5.14 248/252] ath9k: fix sleeping in atomic context Sasha Levin
2021-09-09 11:41 ` [PATCH AUTOSEL 5.14 249/252] net: fix NULL pointer reference in cipso_v4_doi_free Sasha Levin
2021-09-09 11:41 ` [PATCH AUTOSEL 5.14 250/252] fix array-index-out-of-bounds in taprio_change Sasha Levin
2021-09-09 11:41 ` [PATCH AUTOSEL 5.14 251/252] net: w5100: check return value after calling platform_get_resource() Sasha Levin
2021-09-09 11:41 ` [PATCH AUTOSEL 5.14 252/252] net: hns3: clean up a type mismatch warning 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=20210909114106.141462-71-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=davem@davemloft.net \
    --cc=elder@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --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).