Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2908759rdb; Tue, 13 Feb 2024 00:20:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWPmo43Y2XeunyiEP2Sy7c64ZxER5nhFc3fX01v8WRq61vkO/ySIzcPwnpBiMRq50GtiUqBuYmPWnQ5gfOAWbrmjJOFNd9jSOBIsktbBQ== X-Google-Smtp-Source: AGHT+IFXImwUkZo0paeZ2s0zRSpXXWvcAmkK9AM56QQF/Js/XZlhZFrIm63Kc6qYX5Ze/Z5wPz+3 X-Received: by 2002:a17:902:d384:b0:1d9:b27b:1b66 with SMTP id e4-20020a170902d38400b001d9b27b1b66mr10524505pld.7.1707812448351; Tue, 13 Feb 2024 00:20:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707812448; cv=pass; d=google.com; s=arc-20160816; b=dhFj+4zjKKzgWfhq2itAZYGuwGH9gPdrNRcOuXmTBRBQEIn1c2IsMLSFNAEWvA/A7z 0S0zK4eaxqgdDf5jSIfM2vKflrRGVHQBDES2ALtOzG5YmvEqGWYmwfxLQQFv/eHb51ws /s8VV9qPP21zmrjyDSqSGyqNzrf61DlIB7yk9EnRYsnKaAxr89Ks6jZKvqKfxdcthFmq EoQ1c7Obw2XzqyjlGa8NBDLgqdeeX2Tb4CuOKaFlS359wouCg2HDpiXxI30m1aCGP9fK FltGHJc26cWMtqIfZ+nWox5Pdt1K+dDI93iruFufnN4cb3LVpSW02p12Z9gr3MdEiXVG KSXw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=iZUS6Avy7ObEdkigZ/4tAp8qc2aWyi1mNik6pmtJqH8=; fh=CNzDtl5l+UP8nJNLZWO0sriLnOZ3EmuxK2j/Pu76fn0=; b=x42PfFqeVRvDDy4sB3EzYsFNddmeC1Ek8Rx/OCA1R39qYVnpqLqeUKY1MOtwYrfooI AkhsbLsWmEmgSv4C8b+aC/8DLj6t0y4mdICt7PBVHNp7OFJlP+QnMxSaV1XAJ4r1N2Jq aKtE6N3qpZAmI1KwrMXa1Mgm61+xpxTVvHCse+jOa4OGZn1CANXRGn0+/fwO45RvCnNa qGD6QeZ0hcfHtPVhGxKA0G/dUw0z1rpaM+U7Ib6LYQ9Km0W6xa2hDXoV5JnKoLlCGdAW gf3xDkoGdEA4yTaVojYl5RlBFo33Ec641R+DvtPku4xoMCcsE1t+5sqREvfJEwyzLBK9 NOtQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="D5/aIync"; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-63093-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63093-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCV4/RdC6HWecU+hborC7rmyBrSt3zk3yhEsCgPwBWQ53xNG068YdMSOpyOhPWx6XePTZ3ELLYu5mESVz3F7iJK6aryY2sGrJkH0ZzaynA== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d11-20020a170903230b00b001d6fd932a81si1688631plh.275.2024.02.13.00.20.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 00:20:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-63093-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="D5/aIync"; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-63093-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63093-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A5494282B34 for ; Tue, 13 Feb 2024 08:20:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9898029CFD; Tue, 13 Feb 2024 08:18:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="D5/aIync" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A2EB286B3; Tue, 13 Feb 2024 08:18:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707812287; cv=none; b=QQQV+5ttONGZ8/WsppBX/TXd6nbU3sluHGxaN5QMwAQ66q93AT0ArhZ98bfpME+PHPpmOyClbUbH0s2LJO+VRiSRLnDp/zWFOVdNZEVF289oos7PX1YwrC1Bx900J9PmWGW1MCrUGqGeXrD5fWK11hlk8hJbWrCb00r0Y9QuDug= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707812287; c=relaxed/simple; bh=H5tk7A4bfY+JAigsJktni+BUbROwql+zPc9UW2KH6dQ=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=uMT9ooFzJylerW1CYwPN4D6pQo82Jxcpre+iz+eDN5J5139e458puT1wz7A1uqO9c13bJ4SC9J9zP7M+17qzrMof1Iak8BE8ROT/AVgTzAF/m75oE7mOK8dfvcFP+bXWinqIy1/J9R/o9QXe9iNzi5YYnm9s30fVmMNgyKd6Mls= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=D5/aIync; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com 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 41D7WfDP022653; Tue, 13 Feb 2024 08:17:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= message-id:date:mime-version:subject:to:cc:references:from :in-reply-to:content-type:content-transfer-encoding; s= qcppdkim1; bh=iZUS6Avy7ObEdkigZ/4tAp8qc2aWyi1mNik6pmtJqH8=; b=D5 /aIyncPlaqJKZXq/uL2ufkYxJcY1TvAvYsK39nmNi1fLEw7PmS35adTYoCLySb8F cwwShfCBWuqw6TBsMU2tlGhmXanMnGsIVrrEx8LXhwkIxa8zlkLYV10fR728wbaC gZu/dMLDafwj/26oR2GExSiAbUAAOYqN0mlpVH9NHgEqT/KlE3Rv+fghpXiTr7st xVIJHsciCwKtNmzPoex7TyPAVTrKSFGM4U4R8czcjl4e4QqKujmRfKxHmfqTWAdk lFffQ+G5bcLHbu24jhNqy1mtb3QdbRiu8gJ9DErKKPhQV411fRXuBeN3MoZcNc2o 7iJlaEUyoaKDxIqCq2/w== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w8448r2b9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 08:17:52 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41D8Hpas007157 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Feb 2024 08:17:51 GMT Received: from [10.214.25.202] (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; Tue, 13 Feb 2024 00:17:43 -0800 Message-ID: Date: Tue, 13 Feb 2024 13:47:39 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/1] iommu/arm-smmu-qcom: Fix use-after-free issue in qcom_smmu_create() To: Dmitry Baryshkov CC: , , , , , , , , , , , , , , , , , , , References: <20240201210529.7728-4-quic_c_gdjako@quicinc.com> <20240213062608.13018-1-quic_pbrahma@quicinc.com> Content-Language: en-US From: Pratyush Brahma In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit 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-ORIG-GUID: E8HABBGpe90ZckuLynaPQmD2JWHJUBNe X-Proofpoint-GUID: E8HABBGpe90ZckuLynaPQmD2JWHJUBNe 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_04,2024-02-12_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=999 phishscore=0 adultscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1011 spamscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402130064 On 2/13/2024 1:36 PM, Dmitry Baryshkov wrote: > On Tue, 13 Feb 2024 at 08:27, Pratyush Brahma wrote: >> 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 > Missing Fixes tag. Haven't added as the patchset in-reply-to hasn't been merged to linux-next. Please refer my next reply. > >> --- >> 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); > What is the tree that you have been developing this against? I don't > see this part of the code in the linux-next. This is in reply to the patchset at: https://lore.kernel.org/all/20240201210529.7728-4-quic_c_gdjako@quicinc.com The aforementioned patchset introduces this bug. This is a suggested fix to the bug. >> - return &qsmmu->smmu; >> + return smmu; >> } >> >> /* Implementation Defined Register Space 0 register offsets */ >> -- >> 2.17.1 >> >> Thanks, Pratyush