mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] firmware: qcom: pas-tee: Always initialize resource table output size
@ 2026-11-02 15:01 Krzysztof Kozlowski
  2026-11-02 15:01 ` [PATCH 2/2] firmware: qcom: pas-tee: Fix purely theoretical out-of-bounds read of resource table Krzysztof Kozlowski
  2026-11-03  8:51 ` [PATCH 1/2] firmware: qcom: pas-tee: Always initialize resource table output size Konrad Dybcio
  0 siblings, 2 replies; 3+ messages in thread
From: Krzysztof Kozlowski @ 2026-11-02 15:01 UTC (permalink / raw)
  To: Sumit Garg, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
	Harshal Dev, Mukesh Ojha, linux-arm-msm, linux-kernel
  Cc: Krzysztof Kozlowski, Sashiko, stable

qcom_pas_tee_get_rsc_table() sets the "output_rt_size" only when the first
TEE invocation reports a size smaller than the input table, or when the
second invocation returns a non-zero size.  If the TEE reports a size
bigger or equal to the input size on the first call, but then returns
size of 0 on the second call, the function returns NULL (no table) and
leaves "output_rt_size" output parameter untouched.

Caller of qcom_pas_tee_get_rsc_table() treats NULL as success, thus
uninitialized "output_rt_size" output argument could in theory lead to
out-of-bounds accesses further.

Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/bug/linux-bb15726c-4185-460a-a5f0-f779d5ee144a
Fixes: b6f7978da0c4 ("firmware: qcom: Add a PAS TEE service")
Cc: <stable@vger.kernel.org>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
 drivers/firmware/qcom/qcom_pas_tee.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/firmware/qcom/qcom_pas_tee.c b/drivers/firmware/qcom/qcom_pas_tee.c
index ac33a00687aa..ba9957023ec8 100644
--- a/drivers/firmware/qcom/qcom_pas_tee.c
+++ b/drivers/firmware/qcom/qcom_pas_tee.c
@@ -275,6 +275,8 @@ static void *qcom_pas_tee_get_rsc_table(struct device *dev,
 			rt_buf = kmemdup(rt_shm_va, *output_rt_size, GFP_KERNEL);
 			if (!rt_buf)
 				return ERR_PTR(-ENOMEM);
+		} else {
+			*output_rt_size = 0;
 		}
 	} else {
 		*output_rt_size = 0;
-- 
2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] firmware: qcom: pas-tee: Fix purely theoretical out-of-bounds read of resource table
  2026-11-02 15:01 [PATCH 1/2] firmware: qcom: pas-tee: Always initialize resource table output size Krzysztof Kozlowski
@ 2026-11-02 15:01 ` Krzysztof Kozlowski
  2026-11-03  8:51 ` [PATCH 1/2] firmware: qcom: pas-tee: Always initialize resource table output size Konrad Dybcio
  1 sibling, 0 replies; 3+ messages in thread
From: Krzysztof Kozlowski @ 2026-11-02 15:01 UTC (permalink / raw)
  To: Sumit Garg, Bjorn Andersson, Konrad Dybcio, Abel Vesa,
	Harshal Dev, Mukesh Ojha, linux-arm-msm, linux-kernel
  Cc: Krzysztof Kozlowski, Sashiko, stable

qcom_pas_tee_get_rsc_table() first queries the TEE for the size of the
resource table, allocates a shared memory buffer of that size and then
invokes the TEE again to fill the buffer.  TEE can update the returned
size, but the driver does not check that the size returned by the second
call fits in the allocated buffer.

Theoretically and unlikely, some erroneous or compromised TEE returning
a bigger size leads to kmemdup() reading past the end of the shared
memory buffer and leaking adjacent kernel memory.

Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/#/bug/linux-dc984fcd-4884-4518-a98d-9490de9ffce5
Fixes: b6f7978da0c4 ("firmware: qcom: Add a PAS TEE service")
Cc: <stable@vger.kernel.org>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
---
 drivers/firmware/qcom/qcom_pas_tee.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/firmware/qcom/qcom_pas_tee.c b/drivers/firmware/qcom/qcom_pas_tee.c
index ba9957023ec8..cd84befa34d7 100644
--- a/drivers/firmware/qcom/qcom_pas_tee.c
+++ b/drivers/firmware/qcom/qcom_pas_tee.c
@@ -244,9 +244,9 @@ static void *qcom_pas_tee_get_rsc_table(struct device *dev,
 	}
 
 	if (param[1].u.memref.size >= input_rt_size) {
+		size_t rt_shm_size = param[1].u.memref.size;
 		struct tee_shm *rt_shm __free(shm_free) =
-			tee_shm_alloc_kernel_buf(data->ctx,
-						 param[1].u.memref.size);
+			tee_shm_alloc_kernel_buf(data->ctx, rt_shm_size);
 		void *rt_shm_va;
 
 		if (IS_ERR_OR_NULL(rt_shm)) {
@@ -270,6 +270,12 @@ static void *qcom_pas_tee_get_rsc_table(struct device *dev,
 			return ret ? ERR_PTR(ret) : ERR_PTR(-EINVAL);
 		}
 
+		if (param[1].u.memref.size > rt_shm_size) {
+			dev_err(dev, "PAS get RT returned too big size: %zu > %zu\n",
+				param[1].u.memref.size, rt_shm_size);
+			return ERR_PTR(-EINVAL);
+		}
+
 		if (param[1].u.memref.size) {
 			*output_rt_size = param[1].u.memref.size;
 			rt_buf = kmemdup(rt_shm_va, *output_rt_size, GFP_KERNEL);
-- 
2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] firmware: qcom: pas-tee: Always initialize resource table output size
  2026-11-02 15:01 [PATCH 1/2] firmware: qcom: pas-tee: Always initialize resource table output size Krzysztof Kozlowski
  2026-11-02 15:01 ` [PATCH 2/2] firmware: qcom: pas-tee: Fix purely theoretical out-of-bounds read of resource table Krzysztof Kozlowski
@ 2026-11-03  8:51 ` Konrad Dybcio
  1 sibling, 0 replies; 3+ messages in thread
From: Konrad Dybcio @ 2026-11-03  8:51 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Sumit Garg, Bjorn Andersson, Konrad Dybcio,
	Abel Vesa, Harshal Dev, Mukesh Ojha, linux-arm-msm, linux-kernel
  Cc: Sashiko, stable

On 11/2/26 4:01 PM, Krzysztof Kozlowski wrote:
> qcom_pas_tee_get_rsc_table() sets the "output_rt_size" only when the first
> TEE invocation reports a size smaller than the input table, or when the
> second invocation returns a non-zero size.  If the TEE reports a size
> bigger or equal to the input size on the first call, but then returns
> size of 0 on the second call, the function returns NULL (no table) and
> leaves "output_rt_size" output parameter untouched.
> 
> Caller of qcom_pas_tee_get_rsc_table() treats NULL as success, thus
> uninitialized "output_rt_size" output argument could in theory lead to
> out-of-bounds accesses further.
> 
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://sashiko.dev/#/bug/linux-bb15726c-4185-460a-a5f0-f779d5ee144a
> Fixes: b6f7978da0c4 ("firmware: qcom: Add a PAS TEE service")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
> ---


Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>

Konrad

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-03  8:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-02 15:01 [PATCH 1/2] firmware: qcom: pas-tee: Always initialize resource table output size Krzysztof Kozlowski
2026-11-02 15:01 ` [PATCH 2/2] firmware: qcom: pas-tee: Fix purely theoretical out-of-bounds read of resource table Krzysztof Kozlowski
2026-11-03  8:51 ` [PATCH 1/2] firmware: qcom: pas-tee: Always initialize resource table output size Konrad Dybcio

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®