From: Alex Elder <elder@linaro.org>
To: andy.gross@linaro.org
Cc: clew@codeaurora.org, aneela@codeaurora.org,
david.brown@linaro.org, linux-arm-msm@vger.kernel.org,
linux-soc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 11/12] soc: qcom: smem: verify partition host ids match
Date: Tue, 1 May 2018 20:10:18 -0500 [thread overview]
Message-ID: <20180502011019.22812-12-elder@linaro.org> (raw)
In-Reply-To: <20180502011019.22812-1-elder@linaro.org>
Add verification in qcom_smem_partition_header() that the host ids
found in a partition's header structure match those in its partition
table entry.
Signed-off-by: Alex Elder <elder@linaro.org>
---
drivers/soc/qcom/smem.c | 34 +++++++++++++++-------------------
1 file changed, 15 insertions(+), 19 deletions(-)
diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c
index 54c504e41508..7383a0e1b468 100644
--- a/drivers/soc/qcom/smem.c
+++ b/drivers/soc/qcom/smem.c
@@ -734,7 +734,7 @@ static u32 qcom_smem_get_item_count(struct qcom_smem *smem)
*/
static struct smem_partition_header *
qcom_smem_partition_header(struct qcom_smem *smem,
- struct smem_ptable_entry *entry)
+ struct smem_ptable_entry *entry, u16 host0, u16 host1)
{
struct smem_partition_header *header;
u32 size;
@@ -748,6 +748,17 @@ qcom_smem_partition_header(struct qcom_smem *smem,
return NULL;
}
+ if (host0 != le16_to_cpu(header->host0)) {
+ dev_err(smem->dev, "bad host0 (%hu != %hu)\n",
+ host0, le16_to_cpu(header->host0));
+ return NULL;
+ }
+ if (host1 != le16_to_cpu(header->host1)) {
+ dev_err(smem->dev, "bad host1 (%hu != %hu)\n",
+ host1, le16_to_cpu(header->host1));
+ return NULL;
+ }
+
size = le32_to_cpu(header->size);
if (size != le32_to_cpu(entry->size)) {
dev_err(smem->dev, "bad partition size (%u != %u)\n",
@@ -769,7 +780,6 @@ static int qcom_smem_set_global_partition(struct qcom_smem *smem)
struct smem_partition_header *header;
struct smem_ptable_entry *entry;
struct smem_ptable *ptable;
- u32 host0, host1;
bool found = false;
int i;
@@ -798,18 +808,11 @@ static int qcom_smem_set_global_partition(struct qcom_smem *smem)
return -EINVAL;
}
- header = qcom_smem_partition_header(smem, entry);
+ header = qcom_smem_partition_header(smem, entry,
+ SMEM_GLOBAL_HOST, SMEM_GLOBAL_HOST);
if (!header)
return -EINVAL;
- host0 = le16_to_cpu(header->host0);
- host1 = le16_to_cpu(header->host1);
-
- if (host0 != SMEM_GLOBAL_HOST || host1 != SMEM_GLOBAL_HOST) {
- dev_err(smem->dev, "Global partition hosts are invalid\n");
- return -EINVAL;
- }
-
smem->global_partition = header;
smem->global_cacheline = le32_to_cpu(entry->cacheline);
@@ -860,17 +863,10 @@ static int qcom_smem_enumerate_partitions(struct qcom_smem *smem,
return -EINVAL;
}
- header = qcom_smem_partition_header(smem, entry);
+ header = qcom_smem_partition_header(smem, entry, host0, host1);
if (!header)
return -EINVAL;
- if (host0 != le16_to_cpu(header->host0) ||
- host1 != le16_to_cpu(header->host1)) {
- dev_err(smem->dev,
- "Partition %d hosts don't match\n", i);
- return -EINVAL;
- }
-
smem->partitions[remote_host] = header;
smem->cacheline[remote_host] = le32_to_cpu(entry->cacheline);
}
--
2.14.1
next prev parent reply other threads:[~2018-05-02 1:10 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-02 1:10 [PATCH 00/12] soc: qcom: smem: some refactoring Alex Elder
2018-05-02 1:10 ` [PATCH 01/12] soc: qcom: smem: rename variable in qcom_smem_get_global() Alex Elder
2018-05-02 1:10 ` [PATCH 02/12] soc: qcom: smem: initialize region struct only when successful Alex Elder
2018-05-02 1:10 ` [PATCH 03/12] soc: qcom: smem: always ignore partitions with 0 offset or size Alex Elder
2018-05-02 1:10 ` [PATCH 04/12] soc: qcom: smem: small refactor in qcom_smem_enumerate_partitions() Alex Elder
2018-05-02 1:10 ` [PATCH 05/12] soc: qcom: smem: verify both host ids in partition header Alex Elder
2018-05-02 1:10 ` [PATCH 06/12] soc: qcom: smem: require order of host ids to match Alex Elder
2018-05-02 1:10 ` [PATCH 07/12] soc: qcom: smem: introduce qcom_smem_partition_header() Alex Elder
2018-05-02 1:10 ` [PATCH 08/12] soc: qcom: smem: verify partition header size Alex Elder
2018-05-02 1:10 ` [PATCH 09/12] soc: qcom: smem: verify partition offset_free_uncached Alex Elder
2018-05-02 1:10 ` [PATCH 10/12] soc: qcom: smem: small change in global entry loop Alex Elder
2018-05-02 1:10 ` Alex Elder [this message]
2018-05-02 1:10 ` [PATCH 12/12] soc: qcom: smem: a few last cleanups Alex Elder
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=20180502011019.22812-12-elder@linaro.org \
--to=elder@linaro.org \
--cc=andy.gross@linaro.org \
--cc=aneela@codeaurora.org \
--cc=clew@codeaurora.org \
--cc=david.brown@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-soc@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