soc: qcom: smem: verify partition offset_free_uncached

Add verification in qcom_smem_partition_header() that the
offset_free_uncached field in a partition's header structure does
not exceed the partition's size.

Signed-off-by: Alex Elder <elder@linaro.org>
Signed-off-by: Andy Gross <andy.gross@linaro.org>
This commit is contained in:
Alex Elder 2018-06-25 19:58:53 -05:00 committed by Andy Gross
parent 190b216c15
commit 380dc4af50
1 changed files with 7 additions and 14 deletions

View File

@ -751,6 +751,12 @@ qcom_smem_partition_header(struct qcom_smem *smem,
return NULL; return NULL;
} }
if (le32_to_cpu(header->offset_free_uncached) > size) {
dev_err(smem->dev, "bad partition free uncached (%u > %u)\n",
le32_to_cpu(header->offset_free_uncached), size);
return NULL;
}
return header; return header;
} }
@ -759,7 +765,7 @@ static int qcom_smem_set_global_partition(struct qcom_smem *smem)
struct smem_partition_header *header; struct smem_partition_header *header;
struct smem_ptable_entry *entry; struct smem_ptable_entry *entry;
struct smem_ptable *ptable; struct smem_ptable *ptable;
u32 host0, host1, size; u32 host0, host1;
bool found = false; bool found = false;
int i; int i;
@ -804,13 +810,6 @@ static int qcom_smem_set_global_partition(struct qcom_smem *smem)
return -EINVAL; return -EINVAL;
} }
size = le32_to_cpu(header->offset_free_uncached);
if (size > le32_to_cpu(header->size)) {
dev_err(smem->dev,
"Global partition has invalid free pointer\n");
return -EINVAL;
}
smem->global_partition = header; smem->global_partition = header;
smem->global_cacheline = le32_to_cpu(entry->cacheline); smem->global_cacheline = le32_to_cpu(entry->cacheline);
@ -874,12 +873,6 @@ static int qcom_smem_enumerate_partitions(struct qcom_smem *smem,
return -EINVAL; return -EINVAL;
} }
if (le32_to_cpu(header->offset_free_uncached) > le32_to_cpu(header->size)) {
dev_err(smem->dev,
"Partition %d has invalid free pointer\n", i);
return -EINVAL;
}
smem->partitions[remote_host] = header; smem->partitions[remote_host] = header;
smem->cacheline[remote_host] = le32_to_cpu(entry->cacheline); smem->cacheline[remote_host] = le32_to_cpu(entry->cacheline);
} }