]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: ipa: fix ipa_cmd_table_valid()
authorAlex Elder <elder@linaro.org>
Mon, 26 Jul 2021 17:40:07 +0000 (12:40 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 18 Sep 2021 11:42:04 +0000 (13:42 +0200)
[ 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
drivers/net/ipa/ipa_cmd.h
drivers/net/ipa/ipa_table.c

index 525cdf28d9ea70ca433d92818b793d6eedf79429..1e43748dcb4015ab580915e8fd2b57485d429ca1 100644 (file)
@@ -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)
 {
index b99262281f41c55dc6f90a9395d6a5db433b3143..ea723419c826ba8ed77d34923951f415eed3cc87 100644 (file)
@@ -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;
index 3168d72f42450cf8a42715ea03008b0f49887d86..618a84cf669ac0362a886cb25c5a42c7b9b547cb 100644 (file)
@@ -174,7 +174,7 @@ ipa_table_valid_one(struct ipa *ipa, bool route, bool ipv6, bool hashed)
                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 */