Skip to content

Commit

Permalink
net: ipa: fix ipa_cmd_table_valid()
Browse files Browse the repository at this point in the history
[ Upstream commit f2c1dac ]

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>
  • Loading branch information
alexelder authored and gregkh committed Sep 18, 2021
1 parent aba16e2 commit 8c09385
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
38 changes: 25 additions & 13 deletions drivers/net/ipa/ipa_cmd.c
Expand Up @@ -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);

Expand All @@ -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)
{
Expand Down
15 changes: 3 additions & 12 deletions drivers/net/ipa/ipa_cmd.h
Expand Up @@ -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
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ipa/ipa_table.c
Expand Up @@ -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 */
Expand Down

0 comments on commit 8c09385

Please sign in to comment.