stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] firmware: qcom: uefisecapp: fix efivars registration race
@ 2025-01-20 15:10 Johan Hovold
  2025-01-23 12:10 ` Konrad Dybcio
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Johan Hovold @ 2025-01-20 15:10 UTC (permalink / raw)
  To: Maximilian Luz, Bjorn Andersson
  Cc: Konrad Dybcio, Elliot Berman, Bartosz Golaszewski, linux-arm-msm,
	linux-kernel, Johan Hovold, stable

Since the conversion to using the TZ allocator, the efivars service is
registered before the memory pool has been allocated, something which
can lead to a NULL-pointer dereference in case of a racing EFI variable
access.

Make sure that all resources have been set up before registering the
efivars.

Fixes: 6612103ec35a ("firmware: qcom: qseecom: convert to using the TZ allocator")
Cc: stable@vger.kernel.org	# 6.11
Cc: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
---

Note that commit 40289e35ca52 ("firmware: qcom: scm: enable the TZ mem
allocator") looks equally broken as it allocates the tzmem pool only
after qcom_scm_is_available() returns true and other driver can start
making SCM calls.

That one appears to be a bit harder to fix as qcom_tzmem_enable()
currently depends on SCM being available, but someone should definitely
look into untangling that mess.

Johan




 .../firmware/qcom/qcom_qseecom_uefisecapp.c    | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c b/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c
index 447246bd04be..98a463e9774b 100644
--- a/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c
+++ b/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c
@@ -814,15 +814,6 @@ static int qcom_uefisecapp_probe(struct auxiliary_device *aux_dev,
 
 	qcuefi->client = container_of(aux_dev, struct qseecom_client, aux_dev);
 
-	auxiliary_set_drvdata(aux_dev, qcuefi);
-	status = qcuefi_set_reference(qcuefi);
-	if (status)
-		return status;
-
-	status = efivars_register(&qcuefi->efivars, &qcom_efivar_ops);
-	if (status)
-		qcuefi_set_reference(NULL);
-
 	memset(&pool_config, 0, sizeof(pool_config));
 	pool_config.initial_size = SZ_4K;
 	pool_config.policy = QCOM_TZMEM_POLICY_MULTIPLIER;
@@ -833,6 +824,15 @@ static int qcom_uefisecapp_probe(struct auxiliary_device *aux_dev,
 	if (IS_ERR(qcuefi->mempool))
 		return PTR_ERR(qcuefi->mempool);
 
+	auxiliary_set_drvdata(aux_dev, qcuefi);
+	status = qcuefi_set_reference(qcuefi);
+	if (status)
+		return status;
+
+	status = efivars_register(&qcuefi->efivars, &qcom_efivar_ops);
+	if (status)
+		qcuefi_set_reference(NULL);
+
 	return status;
 }
 
-- 
2.45.2


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

* Re: [PATCH] firmware: qcom: uefisecapp: fix efivars registration race
  2025-01-20 15:10 [PATCH] firmware: qcom: uefisecapp: fix efivars registration race Johan Hovold
@ 2025-01-23 12:10 ` Konrad Dybcio
  2025-01-25 16:32 ` Maximilian Luz
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Konrad Dybcio @ 2025-01-23 12:10 UTC (permalink / raw)
  To: Johan Hovold, Maximilian Luz, Bjorn Andersson
  Cc: Konrad Dybcio, Elliot Berman, Bartosz Golaszewski, linux-arm-msm,
	linux-kernel, stable

On 20.01.2025 4:10 PM, Johan Hovold wrote:
> Since the conversion to using the TZ allocator, the efivars service is
> registered before the memory pool has been allocated, something which
> can lead to a NULL-pointer dereference in case of a racing EFI variable
> access.
> 
> Make sure that all resources have been set up before registering the
> efivars.
> 
> Fixes: 6612103ec35a ("firmware: qcom: qseecom: convert to using the TZ allocator")
> Cc: stable@vger.kernel.org	# 6.11
> Cc: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
> ---

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

Konrad

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

* Re: [PATCH] firmware: qcom: uefisecapp: fix efivars registration race
  2025-01-20 15:10 [PATCH] firmware: qcom: uefisecapp: fix efivars registration race Johan Hovold
  2025-01-23 12:10 ` Konrad Dybcio
@ 2025-01-25 16:32 ` Maximilian Luz
  2025-01-27 15:46 ` Bartosz Golaszewski
  2025-02-14 22:38 ` Bjorn Andersson
  3 siblings, 0 replies; 5+ messages in thread
From: Maximilian Luz @ 2025-01-25 16:32 UTC (permalink / raw)
  To: Johan Hovold, Bjorn Andersson
  Cc: Konrad Dybcio, Elliot Berman, Bartosz Golaszewski, linux-arm-msm,
	linux-kernel, stable

On 1/20/25 4:10 PM, Johan Hovold wrote:
> Since the conversion to using the TZ allocator, the efivars service is
> registered before the memory pool has been allocated, something which
> can lead to a NULL-pointer dereference in case of a racing EFI variable
> access.
> 
> Make sure that all resources have been set up before registering the
> efivars.
> 
> Fixes: 6612103ec35a ("firmware: qcom: qseecom: convert to using the TZ allocator")
> Cc: stable@vger.kernel.org	# 6.11
> Cc: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
> ---

Looks good to me.

Reviewed-by: Maximilian Luz <luzmaximilian@gmail.com>

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

* Re: [PATCH] firmware: qcom: uefisecapp: fix efivars registration race
  2025-01-20 15:10 [PATCH] firmware: qcom: uefisecapp: fix efivars registration race Johan Hovold
  2025-01-23 12:10 ` Konrad Dybcio
  2025-01-25 16:32 ` Maximilian Luz
@ 2025-01-27 15:46 ` Bartosz Golaszewski
  2025-02-14 22:38 ` Bjorn Andersson
  3 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2025-01-27 15:46 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Maximilian Luz, Bjorn Andersson, Konrad Dybcio, Elliot Berman,
	linux-arm-msm, linux-kernel, stable

On Mon, 20 Jan 2025 at 16:10, Johan Hovold <johan+linaro@kernel.org> wrote:
>
> Since the conversion to using the TZ allocator, the efivars service is
> registered before the memory pool has been allocated, something which
> can lead to a NULL-pointer dereference in case of a racing EFI variable
> access.
>
> Make sure that all resources have been set up before registering the
> efivars.
>
> Fixes: 6612103ec35a ("firmware: qcom: qseecom: convert to using the TZ allocator")
> Cc: stable@vger.kernel.org      # 6.11
> Cc: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> Signed-off-by: Johan Hovold <johan+linaro@kernel.org>

Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

> ---
>
> Note that commit 40289e35ca52 ("firmware: qcom: scm: enable the TZ mem
> allocator") looks equally broken as it allocates the tzmem pool only
> after qcom_scm_is_available() returns true and other driver can start
> making SCM calls.
>
> That one appears to be a bit harder to fix as qcom_tzmem_enable()
> currently depends on SCM being available, but someone should definitely
> look into untangling that mess.
>
> Johan

Yeah, I have it on my TODO list. I'll get to it.

Bartosz

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

* Re: [PATCH] firmware: qcom: uefisecapp: fix efivars registration race
  2025-01-20 15:10 [PATCH] firmware: qcom: uefisecapp: fix efivars registration race Johan Hovold
                   ` (2 preceding siblings ...)
  2025-01-27 15:46 ` Bartosz Golaszewski
@ 2025-02-14 22:38 ` Bjorn Andersson
  3 siblings, 0 replies; 5+ messages in thread
From: Bjorn Andersson @ 2025-02-14 22:38 UTC (permalink / raw)
  To: Maximilian Luz, Johan Hovold
  Cc: Konrad Dybcio, Elliot Berman, Bartosz Golaszewski, linux-arm-msm,
	linux-kernel, stable


On Mon, 20 Jan 2025 16:10:00 +0100, Johan Hovold wrote:
> Since the conversion to using the TZ allocator, the efivars service is
> registered before the memory pool has been allocated, something which
> can lead to a NULL-pointer dereference in case of a racing EFI variable
> access.
> 
> Make sure that all resources have been set up before registering the
> efivars.
> 
> [...]

Applied, thanks!

[1/1] firmware: qcom: uefisecapp: fix efivars registration race
      commit: da8d493a80993972c427002684d0742560f3be4a

Best regards,
-- 
Bjorn Andersson <andersson@kernel.org>

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

end of thread, other threads:[~2025-02-14 22:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-20 15:10 [PATCH] firmware: qcom: uefisecapp: fix efivars registration race Johan Hovold
2025-01-23 12:10 ` Konrad Dybcio
2025-01-25 16:32 ` Maximilian Luz
2025-01-27 15:46 ` Bartosz Golaszewski
2025-02-14 22:38 ` Bjorn Andersson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).