Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2987146rdb; Tue, 13 Feb 2024 03:38:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUfU02KfsXdohForE95TJJaszTE1pMOrpeJccnGIEZBh+NinmocVGAc5f72PFLCS1ReU6kLCarhKG/ATUMFLFZahAsxhYMZ0fE3c3+mjg== X-Google-Smtp-Source: AGHT+IEHEQeuqQ/vFFRhaFK3lKM3+mO6M56DX+adtlpXhOTOV0BldnvnQNm0JqO7posgTb+YBjN3 X-Received: by 2002:a25:3627:0:b0:dbe:9f4a:6bb0 with SMTP id d39-20020a253627000000b00dbe9f4a6bb0mr7738690yba.56.1707824295355; Tue, 13 Feb 2024 03:38:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707824295; cv=pass; d=google.com; s=arc-20160816; b=C6Oox39KFxWr25yJxV/V19kmxfcS5t0LrlNf1fYDPpqYDBj0VaZTqvJUkOGbAOf+gu rpf9Y7OVp+P5lx083at6rcJjr56po2rKODKzVe46DBM36dfvyowgi5mSJlWLtfVag3Ud gqd3XVy+IM0fTAjXSTHpL4qlVs6pzu9TyuTuk2UsA6EoKyYz8zGfGyNBSzL4+Xiakuj+ 9nbAtuq6rGezZIX7kBQTZXScfKPuTu6SRjp82ajKfrNjcW/Z/mfGKmMlBPvVhEpmTy1n IxRDTe6p/73k59gEruJDozcajLcQzFtC1nS73qxN5sqVYZ2TR2zfEX2UYBAJdwaKOPpV PGlw== 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:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=EOFsgGfg+Fo3+VMyLxl5nzO5QqTxrasZh49GOIxzE3I=; fh=KZV71IvPvUo+oPU20N4BzQgKe55MewW2yYjFG3uV7xU=; b=qwNhMAKD00KvgY2/QcBaeXNfoOJHyTQh5zELnE04NUe47FG0hl+Tw3vmwuCfLwvsfM Z18yHtslCfo20Qu336/KjGYqPqf72q0S4B5yHjGZEfhU3yLcMBFFTpFutK+VTjcihdXR vtpn9gYmhus6rnt/U8TFV/D9ckz7go9C6RQQpYGCDq7rfBCJi3UpFYlCBagcmxss78pw qZzH+pYu/DWcYtGCW+FTXsXXrNVPXz/1Ah5xYfREDdpY89NNHgJgyB1tf3+AlQBt4aKg GxqU/GpUE5aVqQ36b7M2f4ws3ASFSobDfHQgavDYbnguQ+VAg5Sc/yaWXo1YFHZ5XO98 w5rw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-63445-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63445-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com X-Forwarded-Encrypted: i=2; AJvYcCUncEdhBs+AWdsdBteNbcH6HSVfgqLYeNcoCl1EcEn8ikPl5oBsKjmC7N281JzMQlFuDDWBg1oq5ga8OcEUEuxrL9MrtQjJXEMDbvz9jA== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id i21-20020a05620a0a1500b00783de628217si8110434qka.121.2024.02.13.03.38.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 03:38:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-63445-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-63445-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63445-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 210101C2318A for ; Tue, 13 Feb 2024 11:38:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CC638381C6; Tue, 13 Feb 2024 11:37:00 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 922BC3717A; Tue, 13 Feb 2024 11:36:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707824220; cv=none; b=TTs9ZKNUIPPeK4lGas2SlvForusu1DImY6s/KUvPIdTFRBcVugtlOSiwiZ8sUz8Whw4NIyMcXrsuzGQAbkYO/nmUPcq9QwC6SYws4U+RFCCtdGNBj4MYc0l0VT5nU+shQ3y7K1SEy81hcu8oPydjMnoEDnQ5EFgV+9fdn+LlFXY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707824220; c=relaxed/simple; bh=fFDvWAUz+casXDjawJVoU0ywBbK/Tmx5t81ELfWtrYs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=drp2SyebBbdBigXhoEDvG0VrLxqoVmdcBrv4so620x8UisiM2GvZ4EoU+YSXcpfuBKfXAwi+w1ZMVg9Lyge2fgfiE4ifjhFiX3dynxTetUzEEqLSzoCEkK0Q25s2eG4X2HiMjkhysEvqVC2BIQKR0+AFh7LX9Saph3GveLZX+Dg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EF0ACDA7; Tue, 13 Feb 2024 03:37:37 -0800 (PST) Received: from [10.57.49.48] (unknown [10.57.49.48]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C36EA3F5A1; Tue, 13 Feb 2024 03:36:53 -0800 (PST) Message-ID: Date: Tue, 13 Feb 2024 11:36:51 +0000 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() Content-Language: en-GB To: Pratyush Brahma , Dmitry Baryshkov Cc: quic_c_gdjako@quicinc.com, 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, will@kernel.org References: <20240201210529.7728-4-quic_c_gdjako@quicinc.com> <20240213062608.13018-1-quic_pbrahma@quicinc.com> From: Robin Murphy In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2024-02-13 8:17 am, Pratyush Brahma wrote: > > 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. Unless you are the 0-day bot, please just point out bugs in under-review patches via regular review comments rather than sending patches for unmerged patches. There is nothing to fix in mainline, and as I commented on the binding patch I'm not sure I agree with the fundamental premise for touching qcom_smmu_create() in this series at all. Thanks, Robin. >>> -       return &qsmmu->smmu; >>> +       return smmu; >>>   } >>> >>>   /* Implementation Defined Register Space 0 register offsets */ >>> -- >>> 2.17.1 >>> >>> > Thanks, > Pratyush