From patchwork Tue Feb 13 06:26:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pratyush Brahma X-Patchwork-Id: 13554471 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 76FFFC4829A for ; Tue, 13 Feb 2024 06:27:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=r9Q5OA6qRQSeuTpa3AAhG/uXfoZYPVYAaW+JAtg+IUU=; b=vxp46PJ5P22EfF 0AloeV23XghesAot+9rf4re3Xa2bAf0jWOtkjLngUT2exNjq7JrmxFwksd9iwveH1WX9AT2OiqXX2 h3HpBi7vorjpY++Y1sHpI95GEVNLR1V95ObcPWlouB6xHrVLTVf2IE+1iwDXJjpx8/5vZMssv0wPl C9foEhL7SrFxMeDW0vZ1F7bBrwr+UbCfPtxP8aL10mKsYVJGNDEaNth8adeA2V4BPkWXO6C5rBicF uuLBw/9y/wjQKLolZUiw8rCIuVVWf+wplpExWnOfZwN8HfgvLZwa+Xcs5E6TDZVOEAO2TUD3IKEqb 2gO/wMdJowE6zRnN0mrw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZmG0-000000088L5-0XbJ; Tue, 13 Feb 2024 06:27:04 +0000 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZmFx-000000088Kg-05DO for linux-arm-kernel@lists.infradead.org; Tue, 13 Feb 2024 06:27:02 +0000 Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41D5Th6m004424; Tue, 13 Feb 2024 06:26:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=1HyR7N1uFxB3/NwkHjKq /EjyE4gxvWiOfwIKWk1/RFw=; b=ZB50NDycJnqQKbROyNFmFELZF62cZwslDc/G Rm4Y6cJm336AL2eKMLlO95RF6YZNX9o9Xrn0DvbJDYKZy92cJxQzzWjD+ydVLchy rRtjKq/DpJWkxpjnfS1ITK+Qj3TXGrUdjbLuxXAPHJNQUH/aXLkqq+vv5d9o+s3i XokDM/UYTUTdPaXkXTYsgxA7H3oWhd1CuKyXCTg+KwkbRKVU27iBuppWP+Fno5F8 zVRZaWyfnGhQRcmKsKLqom877/OkF4sewkA41Binz0TNNYMlOmFEzS+lMOeSelLt 117Dhnj7GfktYorYVvuShgOBu9jzv0NEnJz7ud0P44h/pV4O/g== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w7gs1j9m2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 06:26:44 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D6Qhim017018 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 06:26:43 GMT Received: from hu-pbrahma-hyd.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Mon, 12 Feb 2024 22:26:37 -0800 From: Pratyush Brahma To: CC: , , , , , , , , , , , , , , , , , , , Pratyush Brahma Subject: [PATCH 1/1] iommu/arm-smmu-qcom: Fix use-after-free issue in qcom_smmu_create() Date: Tue, 13 Feb 2024 11:56:08 +0530 Message-ID: <20240213062608.13018-1-quic_pbrahma@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240201210529.7728-4-quic_c_gdjako@quicinc.com> References: <20240201210529.7728-4-quic_c_gdjako@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: DZwZkC2Dnn9CE46HDwYLMIDiZKGSws-x X-Proofpoint-ORIG-GUID: DZwZkC2Dnn9CE46HDwYLMIDiZKGSws-x X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-13_02,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=959 suspectscore=0 adultscore=0 clxscore=1015 impostorscore=0 mlxscore=0 malwarescore=0 spamscore=0 phishscore=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130047 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240212_222701_105909_E43988FB X-CRM114-Status: GOOD ( 15.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently, during arm smmu probe, struct arm_smmu_device pointer is allocated. The pointer is reallocated to a new struct qcom_smmu in qcom_smmu_create() with devm_krealloc() which frees the smmu device after copying the data into the new pointer. The freed pointer is then passed again in devm_of_platform_populate() inside qcom_smmu_create() which causes a use-after-free issue. Fix the use-after-free issue by reassigning the old pointer to the new pointer where the struct was copied by devm_krealloc(). Signed-off-by: Pratyush Brahma --- drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c index ed5ed5da7740..49eaeed6a91c 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c +++ b/drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c @@ -710,6 +710,7 @@ static struct arm_smmu_device *qcom_smmu_create(struct arm_smmu_device *smmu, qsmmu = devm_krealloc(smmu->dev, smmu, sizeof(*qsmmu), GFP_KERNEL); if (!qsmmu) return ERR_PTR(-ENOMEM); + smmu = &qsmmu->smmu; qsmmu->smmu.impl = impl; qsmmu->data = data; @@ -719,7 +720,7 @@ static struct arm_smmu_device *qcom_smmu_create(struct arm_smmu_device *smmu, if (ret) return ERR_PTR(ret); - return &qsmmu->smmu; + return smmu; } /* Implementation Defined Register Space 0 register offsets */