From: Albert Esteve <aesteve@redhat.com>
To: Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>
Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
Albert Esteve <aesteve@redhat.com>,
Sarannya S <sarannya.s@oss.qualcomm.com>,
Pranav Mahesh Phansalkar <pranav.phansalkar@oss.qualcomm.com>,
Sudeepgoud Patil <sudeep.patil@oss.qualcomm.com>
Subject: [PATCH v4 3/4] soc: qcom: smem: validate private item payloads
Date: Thu, 22 Oct 2026 11:47:23 +0200 [thread overview]
Message-ID: <20261022-port-smem-v4-3-b0baf39c6e01@redhat.com> (raw)
In-Reply-To: <20261022-port-smem-v4-0-b0baf39c6e01@redhat.com>
From: Sarannya S <sarannya.s@oss.qualcomm.com>
Validate a matching entry's size and padding even when the caller does
not request the length, and check that the payload stays inside the
same region as the header.
Signed-off-by: Sarannya S <sarannya.s@oss.qualcomm.com>
Signed-off-by: Pranav Mahesh Phansalkar <pranav.phansalkar@oss.qualcomm.com>
Signed-off-by: Sudeepgoud Patil <sudeep.patil@oss.qualcomm.com>
Signed-off-by: Albert Esteve <aesteve@redhat.com>
---
drivers/soc/qcom/smem.c | 39 +++++++++++++++++++++------------------
1 file changed, 21 insertions(+), 18 deletions(-)
diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c
index a6732832e2c5..f34eaba230ad 100644
--- a/drivers/soc/qcom/smem.c
+++ b/drivers/soc/qcom/smem.c
@@ -616,6 +616,7 @@ static void *qcom_smem_get_private(struct qcom_smem *smem,
struct smem_private_entry *next_e;
struct smem_partition_header *phdr;
void *item_ptr, *p_end;
+ size_t entry_size = 0;
u32 padding_data;
u32 e_size;
@@ -635,20 +636,21 @@ static void *qcom_smem_get_private(struct qcom_smem *smem,
goto invalid_canary;
if (le16_to_cpu(e->item) == item) {
- if (size != NULL) {
- e_size = le32_to_cpu(e->size);
- padding_data = le16_to_cpu(e->padding_data);
+ e_size = le32_to_cpu(e->size);
+ padding_data = le16_to_cpu(e->padding_data);
- if (WARN_ON(e_size > part->size || padding_data > e_size))
- return ERR_PTR(-EINVAL);
-
- *size = e_size - padding_data;
- }
+ if (e_size < part->size && padding_data < e_size)
+ entry_size = e_size - padding_data;
+ else
+ return ERR_PTR(-EINVAL);
item_ptr = uncached_entry_to_item(e);
- if (WARN_ON(item_ptr > p_end))
+ if (WARN_ON(!IN_PARTITION_RANGE(item_ptr, entry_size, e, uncached_end)))
return ERR_PTR(-EINVAL);
+ if (size != NULL)
+ *size = entry_size;
+
return item_ptr;
}
@@ -678,20 +680,21 @@ static void *qcom_smem_get_private(struct qcom_smem *smem,
goto invalid_canary;
if (le16_to_cpu(e->item) == item) {
- if (size != NULL) {
- e_size = le32_to_cpu(e->size);
- padding_data = le16_to_cpu(e->padding_data);
+ e_size = le32_to_cpu(e->size);
+ padding_data = le16_to_cpu(e->padding_data);
- if (WARN_ON(e_size > part->size || padding_data > e_size))
- return ERR_PTR(-EINVAL);
-
- *size = e_size - padding_data;
- }
+ if (e_size < part->size && padding_data < e_size)
+ entry_size = e_size - padding_data;
+ else
+ return ERR_PTR(-EINVAL);
item_ptr = cached_entry_to_item(e);
- if (WARN_ON(item_ptr < (void *)phdr))
+ if (WARN_ON(!IN_PARTITION_RANGE(item_ptr, entry_size, cached_end, e)))
return ERR_PTR(-EINVAL);
+ if (size != NULL)
+ *size = entry_size;
+
return item_ptr;
}
--
2.55.0
next prev parent reply other threads:[~2026-10-22 9:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 9:47 [PATCH v4 0/4] Add automotive SMEM hardening for Qualcomm platforms Albert Esteve
2026-10-22 9:47 ` [PATCH v4 1/4] soc: qcom: smem: add IN_PARTITION_RANGE helper Albert Esteve
2026-10-27 12:18 ` Konrad Dybcio
2026-10-22 9:47 ` [PATCH v4 2/4] soc: qcom: smem: validate private entry list walks Albert Esteve
2026-10-27 12:45 ` Konrad Dybcio
2026-10-28 8:29 ` Albert Esteve
2026-10-22 9:47 ` Albert Esteve [this message]
2026-10-27 12:58 ` [PATCH v4 3/4] soc: qcom: smem: validate private item payloads Konrad Dybcio
2026-10-22 9:47 ` [PATCH v4 4/4] soc: qcom: smem: ignore multi remote host partitions Albert Esteve
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=20261022-port-smem-v4-3-b0baf39c6e01@redhat.com \
--to=aesteve@redhat.com \
--cc=andersson@kernel.org \
--cc=konradybcio@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pranav.phansalkar@oss.qualcomm.com \
--cc=sarannya.s@oss.qualcomm.com \
--cc=sudeep.patil@oss.qualcomm.com \
/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
all inboxes | Powered by JetHome®