Commit 5444b0ea authored by Alex Elder's avatar Alex Elder Committed by Paolo Abeni

net: ipa: verify table sizes fit in commands early

We currently verify the table size and offset fit in the immediate
command fields that must encode them in ipa_table_valid_one().  We
can now make this check earlier, in ipa_table_mem_valid().

The non-hashed IPv4 filter and route tables will always exist, and
their sizes will match the IPv6 tables, as well as the hashed tables
(if supported).  So it's sufficient to verify the offset and size of
the IPv4 non-hashed tables fit into these fields.

Rename the function ipa_cmd_table_init_valid(), to reinforce that
it is the TABLE_INIT immediate command fields we're checking.
Signed-off-by: default avatarAlex Elder <elder@linaro.org>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent cf139196
...@@ -171,7 +171,8 @@ static void ipa_cmd_validate_build(void) ...@@ -171,7 +171,8 @@ static void ipa_cmd_validate_build(void)
} }
/* Validate a memory region holding a table */ /* Validate a memory region holding a table */
bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, bool route) bool ipa_cmd_table_init_valid(struct ipa *ipa, const struct ipa_mem *mem,
bool route)
{ {
u32 offset_max = field_max(IP_FLTRT_FLAGS_NHASH_ADDR_FMASK); u32 offset_max = field_max(IP_FLTRT_FLAGS_NHASH_ADDR_FMASK);
u32 size_max = field_max(IP_FLTRT_FLAGS_NHASH_SIZE_FMASK); u32 size_max = field_max(IP_FLTRT_FLAGS_NHASH_SIZE_FMASK);
......
...@@ -47,15 +47,15 @@ enum ipa_cmd_opcode { ...@@ -47,15 +47,15 @@ enum ipa_cmd_opcode {
}; };
/** /**
* ipa_cmd_table_valid() - Validate a memory region holding a table * ipa_cmd_table_init_valid() - Validate a memory region holding a table
* @ipa: - IPA pointer * @ipa: - IPA pointer
* @mem: - IPA memory region descriptor * @mem: - IPA memory region descriptor
* @route: - Whether the region holds a route or filter table * @route: - Whether the region holds a route or filter table
* *
* Return: true if region is valid, false otherwise * Return: true if region is valid, false otherwise
*/ */
bool ipa_cmd_table_valid(struct ipa *ipa, const struct ipa_mem *mem, bool ipa_cmd_table_init_valid(struct ipa *ipa, const struct ipa_mem *mem,
bool route); bool route);
/** /**
* ipa_cmd_data_valid() - Validate command-realted configuration is valid * ipa_cmd_data_valid() - Validate command-realted configuration is valid
......
...@@ -166,10 +166,6 @@ ipa_table_valid_one(struct ipa *ipa, enum ipa_mem_id mem_id, bool route) ...@@ -166,10 +166,6 @@ ipa_table_valid_one(struct ipa *ipa, enum ipa_mem_id mem_id, bool route)
size = IPA_ROUTE_COUNT_MAX * sizeof(__le64); size = IPA_ROUTE_COUNT_MAX * sizeof(__le64);
else else
size = (1 + IPA_FILTER_COUNT_MAX) * sizeof(__le64); size = (1 + IPA_FILTER_COUNT_MAX) * sizeof(__le64);
if (!ipa_cmd_table_valid(ipa, mem, route))
return false;
/* mem->size >= size is sufficient, but we'll demand more */ /* mem->size >= size is sufficient, but we'll demand more */
if (mem->size == size) if (mem->size == size)
return true; return true;
...@@ -645,6 +641,10 @@ static bool ipa_table_mem_valid(struct ipa *ipa, bool modem_route_count) ...@@ -645,6 +641,10 @@ static bool ipa_table_mem_valid(struct ipa *ipa, bool modem_route_count)
if (mem_ipv4->size != mem_ipv6->size) if (mem_ipv4->size != mem_ipv6->size)
return false; return false;
/* Table offset and size must fit in TABLE_INIT command fields */
if (!ipa_cmd_table_init_valid(ipa, mem_ipv4, !filter))
return false;
/* Make sure the regions are big enough */ /* Make sure the regions are big enough */
count = mem_ipv4->size / sizeof(__le64); count = mem_ipv4->size / sizeof(__le64);
if (count < 2) if (count < 2)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment