Skip to contentSkip to conversation

firmware: qcom: uefisecapp: fix efivars registration race

PATCH Applied Johan Hovold 5 participants 5 messages Jan 20, 2025 – Feb 14, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 firmware: qcom: uefisecapp: fix efivars registration race

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 Bartosz Golaszewski <[email protected]>

---

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(-)
drivers/firmware/qcom/qcom_qseecom_uefisecapp.c +9 -9
index 447246bd04be..98a463e9774b 100644
@@ -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;
 }
 
Signature · 1 line
2.45.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Johan Hovold

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.

Quoted 8 lines

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 Bartosz Golaszewski <[email protected]>

---

Konrad

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Johan Hovold
Quoted 5 lines · Johan Hovold

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.

Quoted 8 lines

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 Bartosz Golaszewski <[email protected]>

---

Looks good to me.

Reviewed-by on v1 1/1
#3 lore raw
In reply to Johan Hovold
Quoted 6 lines · Johan Hovold

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.

Quoted 7 lines

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 Bartosz Golaszewski <[email protected]>
Quoted 7 lines

---

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.

Quoted 5 lines

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

maintainer Applied
#4 lore raw
In reply to Johan Hovold
Quoted 9 lines · Johan Hovold

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,

Signature · 1 line
Bjorn Andersson <[email protected]>