From nobody Sun Oct 5 07:21:19 2025 Received: from sg-1-21.ptr.blmpb.com (sg-1-21.ptr.blmpb.com [118.26.132.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A388524F for ; Thu, 7 Aug 2025 02:37:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=118.26.132.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754534238; cv=none; b=EvoyNMeYPUtuby9eFvB8RLEf1sc//NKYDFecDcmiBXGgatuVmzzsZzvJpuVPR3ByX5OIc/vcrZBX0khkl824nChzCvGJWFVAY/TEZaFg0GXluYz4JiOA77aF6nkkQVIHWSsR9ySG8bYbod7bfB9rmpblKj8+rKyQOG53LlaiCf0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754534238; c=relaxed/simple; bh=/rN/HmM3ZdTXW8EncKDZvcOeakQ8W9MXCc9EUMcxCxo=; h=Subject:Message-Id:Content-Type:From:Cc:Mime-Version:To:Date; b=jeU5pfK/97sb492aDYmfhSiZCIL9ScdCsmtVpHvrrj4006lDZtq6fWxlfNIkV+eyHQsiSzOme7q6Xxxq6DkjAAE8BJORfHQpgUsaoz8yiefpeLQn+tyFjhHv3/3f+voWYr7nKao23JFSZDJ5MMSPnBRexQEVQGB14EPzBx6BsqE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lanxincomputing.com; spf=pass smtp.mailfrom=lanxincomputing.com; dkim=pass (2048-bit key) header.d=lanxincomputing-com.20200927.dkim.feishu.cn header.i=@lanxincomputing-com.20200927.dkim.feishu.cn header.b=QVOUtWvJ; arc=none smtp.client-ip=118.26.132.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lanxincomputing.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lanxincomputing.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lanxincomputing-com.20200927.dkim.feishu.cn header.i=@lanxincomputing-com.20200927.dkim.feishu.cn header.b="QVOUtWvJ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=s1; d=lanxincomputing-com.20200927.dkim.feishu.cn; t=1754534227; h=from:subject:mime-version:from:date:message-id:subject:to:cc: reply-to:content-type:mime-version:in-reply-to:message-id; bh=tvpUwXpgi4bbfw65gWC7ncSTc2jcTFdcUIgVdaFTeCY=; b=QVOUtWvJyGPJ5k4E7xighwdtybqSJQioP8gY/XWRsVuSjrvt21VZ9kcwYKrQPpY7aSPacc OiT6eHf813urrPL8ddkclM2zIQY11+WloarM3UdVoaKFHmzNuUaBQxMnl6nsWpKVrJ6qbE RT0MbGZcilSeXzzJh55xIBWjUDbrizpEyRL0Vk3X1rRppjnCs5nFZzB12W50x6WEPZOfq/ SLmTNdazFzFqV2z6ddjZugHWzaIjgtdC6NXjjLiLyKI1ZyRZ94fvu60rgbtJnC6svVm8eq BD4SAHpMH8AUnRZdFPg0sxp7O6XYVcJ6FIFBbdrHK7ls20AvazAl+crsBWogjw== Subject: [PATCH v2] iommu/riscv: check pte null pointer before use Message-Id: <20250807023557.6482-1-huangxianliang@lanxincomputing.com> Content-Transfer-Encoding: quoted-printable From: "XianLiang Huang" X-Mailer: git-send-email 2.34.1 X-Lms-Return-Path: Received: from LeonHXL.localdomain ([116.237.111.137]) by smtp.feishu.cn with ESMTPS; Thu, 07 Aug 2025 10:37:04 +0800 X-Original-From: XianLiang Huang Cc: , , , , , , , , , , , Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 To: Date: Thu, 7 Aug 2025 10:35:57 +0800 Content-Type: text/plain; charset="utf-8" The riscv_iommu_pte_fetch can return NULL when the provided iova is not yet mapped, the caller should check if the returned pointer is NULL or not, but riscv_iommu_iova_to_phys missed this, which will then lead to a kernel panic. Check the pointer before using it to avoid the bug. Now, when iova_to_phys is called with an unmapped iova, the kernel will not crash here. Changelog --------- v2: - Update change description - Add "Fixes" tag Fixes: 488ffbf18171 ("iommu/riscv: Paging domain support") Cc: Tomasz Jeznach Signed-off-by: XianLiang Huang --- drivers/iommu/riscv/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c index 2d0d31ba2886..b0186faa0300 100644 --- a/drivers/iommu/riscv/iommu.c +++ b/drivers/iommu/riscv/iommu.c @@ -1283,7 +1283,7 @@ static phys_addr_t riscv_iommu_iova_to_phys(struct io= mmu_domain *iommu_domain, unsigned long *ptr; =20 ptr =3D riscv_iommu_pte_fetch(domain, iova, &pte_size); - if (_io_pte_none(*ptr) || !_io_pte_present(*ptr)) + if (!ptr || _io_pte_none(*ptr) || !_io_pte_present(*ptr)) return 0; =20 return pfn_to_phys(__page_val_to_pfn(*ptr)) | (iova & (pte_size - 1)); --=20 2.34.1