]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
firmware: qcom: scm: Fix missing read barrier in qcom_scm_get_tzmem_pool()
authorKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Mon, 9 Dec 2024 14:27:55 +0000 (15:27 +0100)
committerBjorn Andersson <andersson@kernel.org>
Tue, 7 Jan 2025 00:36:59 +0000 (18:36 -0600)
Commit 2e4955167ec5 ("firmware: qcom: scm: Fix __scm and waitq
completion variable initialization") introduced a write barrier in probe
function to store global '__scm' variable.  We all known barriers are
paired (see memory-barriers.txt: "Note that write barriers should
normally be paired with read or address-dependency barriers"), therefore
accessing it from concurrent contexts requires read barrier.  Previous
commit added such barrier in qcom_scm_is_available(), so let's use that
directly.

Lack of this read barrier can result in fetching stale '__scm' variable
value, NULL, and dereferencing it.

Note that barrier in qcom_scm_is_available() satisfies here the control
dependency.

Fixes: ca61d6836e6f ("firmware: qcom: scm: fix a NULL-pointer dereference")
Fixes: 449d0d84bcd8 ("firmware: qcom: scm: smc: switch to using the SCM allocator")
Cc: stable@vger.kernel.org
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20241209-qcom-scm-missing-barriers-and-all-sort-of-srap-v2-2-9061013c8d92@linaro.org
Signed-off-by: Bjorn Andersson <andersson@kernel.org>
drivers/firmware/qcom/qcom_scm.c

index cde60566c79346aa3fd4c75a929e69ae01a3d1a0..4a1c05a7bf20a42d32d400302f651e603e80b186 100644 (file)
@@ -217,7 +217,10 @@ static DEFINE_SPINLOCK(scm_query_lock);
 
 struct qcom_tzmem_pool *qcom_scm_get_tzmem_pool(void)
 {
-       return __scm ? __scm->mempool : NULL;
+       if (!qcom_scm_is_available())
+               return NULL;
+
+       return __scm->mempool;
 }
 
 static enum qcom_scm_convention __get_convention(void)