From: Pratyush Brahma <quic_pbrahma@quicinc.com>
To: <quic_c_gdjako@quicinc.com>
Cc: <andersson@kernel.org>, <conor+dt@kernel.org>,
<devicetree@vger.kernel.org>, <djakov@kernel.org>,
<iommu@lists.linux.dev>, <joro@8bytes.org>,
<konrad.dybcio@linaro.org>, <krzysztof.kozlowski+dt@linaro.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-arm-msm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<quic_cgoldswo@quicinc.com>, <quic_pdaly@quicinc.com>,
<quic_sudaraja@quicinc.com>, <quic_sukadev@quicinc.com>,
<robdclark@gmail.com>, <robh+dt@kernel.org>,
<robin.murphy@arm.com>, <will@kernel.org>
Subject: Re: [PATCH v4 03/10] iommu/arm-smmu-qcom: Add support for TBUs
Date: Mon, 12 Feb 2024 22:59:50 +0530 [thread overview]
Message-ID: <13da9cd9-218d-4b3f-98f8-62edcd91a23e@quicinc.com> (raw)
In-Reply-To: <20240201210529.7728-4-quic_c_gdjako@quicinc.com>
Hi
The following patch would introduce a use-after-free bug which was found
during KASAN testing on qcm6490 with the patch.
diff
<https://lore.kernel.org/all/20240201210529.7728-4-quic_c_gdjako@quicinc.com/#iZ2e.:20240201210529.7728-4-quic_c_gdjako::40quicinc.com:1drivers:iommu:arm:arm-smmu:arm-smmu-qcom.c>
--git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c index
8b04ece00420..ca806644e6eb 100644 ---
a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c +++
b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c @@ -1,12 +1,14 @@ // SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2019, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved */
#include <linux/acpi.h>
#include <linux/adreno-smmu-priv.h>
#include <linux/delay.h>
#include <linux/of_device.h>
+#include <linux/of_platform.h> #include <linux/firmware/qcom/qcom_scm.h>
#include "arm-smmu.h"
@@ -446,6 +448,7 @@ static struct arm_smmu_device
*qcom_smmu_create(struct arm_smmu_device *smmu, const struct device_node *np = smmu->dev->of_node;
const struct arm_smmu_impl *impl;
struct qcom_smmu *qsmmu;
+ int ret;
if (!data)
return ERR_PTR(-EINVAL);
@@ -469,6 +472,12 @@ static struct arm_smmu_device
*qcom_smmu_create(struct arm_smmu_device *smmu, qsmmu->smmu.impl = impl;
qsmmu->cfg = data->cfg;
+ INIT_LIST_HEAD(&qsmmu->tbu_list); + mutex_init(&qsmmu->tbu_list_lock);
+ ret = devm_of_platform_populate(smmu->dev); // smmu has been freed by
devm_krealloc() above but is being accessed here again later. This
causes use-after-free bug. + if (ret) + return ERR_PTR(ret); + return &qsmmu->smmu;
}
Can it be done like below?
qsmmu->smmu.impl = impl;
qsmmu->cfg = data->cfg;
+ INIT_LIST_HEAD(&qsmmu->tbu_list); + mutex_init(&qsmmu->tbu_list_lock);
+ ret = devm_of_platform_populate(qsmmu->smmu.dev);// Using the struct
to which smmu was copied instead of freed ptr. Thanks, Pratyush
next prev parent reply other threads:[~2024-02-12 17:30 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-01 21:05 [PATCH v4 00/10] Add support for Translation Buffer Units Georgi Djakov
2024-02-01 21:05 ` [PATCH v4 01/10] dt-bindings: iommu: Add Translation Buffer Unit bindings Georgi Djakov
2024-02-02 21:17 ` Rob Herring
2024-02-12 19:12 ` Robin Murphy
2024-02-29 18:01 ` Krzysztof Kozlowski
2024-02-12 20:25 ` Robin Murphy
2024-02-01 21:05 ` [PATCH v4 02/10] dt-bindings: iommu: Add Qualcomm TBU bindings Georgi Djakov
2024-02-01 21:05 ` [PATCH v4 03/10] iommu/arm-smmu-qcom: Add support for TBUs Georgi Djakov
2024-02-12 17:29 ` Pratyush Brahma [this message]
2024-02-13 6:26 ` [PATCH 1/1] iommu/arm-smmu-qcom: Fix use-after-free issue in qcom_smmu_create() Pratyush Brahma
2024-02-13 8:06 ` Dmitry Baryshkov
2024-02-13 8:17 ` Pratyush Brahma
2024-02-13 11:36 ` Robin Murphy
2024-02-29 17:57 ` Krzysztof Kozlowski
2024-02-01 21:05 ` [PATCH v4 04/10] iommu/arm-smmu-qcom-tbu: Add Qualcomm TBU driver Georgi Djakov
2024-02-01 21:05 ` [PATCH v4 05/10] iommu/arm-smmu: Allow using a threaded handler for context interrupts Georgi Djakov
2024-02-01 21:05 ` [PATCH v4 06/10] iommu/arm-smmu-qcom: Use a custom context fault handler for sdm845 Georgi Djakov
2024-02-01 21:05 ` [PATCH v4 07/10] arm64: dts: qcom: sdm845: Add DT nodes for the TBUs Georgi Djakov
2024-02-01 21:05 ` [PATCH v4 08/10] dt-bindings: arm-smmu: Add TBU support for sc7280 Georgi Djakov
2024-02-01 21:05 ` [PATCH v4 09/10] iommu/arm-smmu-qcom: Use the custom fault handler on more platforms Georgi Djakov
2024-02-01 21:05 ` [PATCH v4 10/10] arm64: dts: qcom: sc7280: Add DT nodes for the TBUs Georgi Djakov
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=13da9cd9-218d-4b3f-98f8-62edcd91a23e@quicinc.com \
--to=quic_pbrahma@quicinc.com \
--cc=andersson@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=djakov@kernel.org \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=konrad.dybcio@linaro.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=quic_c_gdjako@quicinc.com \
--cc=quic_cgoldswo@quicinc.com \
--cc=quic_pdaly@quicinc.com \
--cc=quic_sudaraja@quicinc.com \
--cc=quic_sukadev@quicinc.com \
--cc=robdclark@gmail.com \
--cc=robh+dt@kernel.org \
--cc=robin.murphy@arm.com \
--cc=will@kernel.org \
/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