* [PATCH] iommu/amd: Fix potential out-of-bounds read in iommu_mmio_show
@ 2025-10-24 8:02 Songtang Liu
2025-10-27 11:21 ` Dheeraj Kumar Srivastava
0 siblings, 1 reply; 2+ messages in thread
From: Songtang Liu @ 2025-10-24 8:02 UTC (permalink / raw)
To: joro, will
Cc: suravee.suthikulpanit, robin.murphy, vasant.hegde,
dheerajkumar.srivastava, iommu, linux-kernel, liusongtang
In iommu_mmio_write(), it validates the user-provided offset with the
check: `iommu->dbg_mmio_offset > iommu->mmio_phys_end - 4`.
This assumes a 4-byte access. However, the corresponding
show handler, iommu_mmio_show(), uses readq() to perform an 8-byte
(64-bit) read.
If a user provides an offset equal to `mmio_phys_end - 4`, the check
passes, and will lead to a 4-byte out-of-bounds read.
Fix this by adjusting the boundary check to use sizeof(u64), which
corresponds to the size of the readq() operation.
Fixes: 7a4ee419e8c1 ("iommu/amd: Add debugfs support to dump IOMMU
MMIO registers")
Signed-off-by: Songtang Liu <liusongtang@bytedance.com>
---
drivers/iommu/amd/debugfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iommu/amd/debugfs.c b/drivers/iommu/amd/debugfs.c
index 8b4d7db7869a4..5d85c47478a57 100644
--- a/drivers/iommu/amd/debugfs.c
+++ b/drivers/iommu/amd/debugfs.c
@@ -37,7 +37,7 @@ static ssize_t iommu_mmio_write(struct file *filp,
const char __user *ubuf,
if (ret)
return ret;
- if (iommu->dbg_mmio_offset > iommu->mmio_phys_end - 4) {
+ if (iommu->dbg_mmio_offset > iommu->mmio_phys_end - sizeof(u64)) {
iommu->dbg_mmio_offset = -1;
return -EINVAL;
}
--
2.39.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iommu/amd: Fix potential out-of-bounds read in iommu_mmio_show
2025-10-24 8:02 [PATCH] iommu/amd: Fix potential out-of-bounds read in iommu_mmio_show Songtang Liu
@ 2025-10-27 11:21 ` Dheeraj Kumar Srivastava
0 siblings, 0 replies; 2+ messages in thread
From: Dheeraj Kumar Srivastava @ 2025-10-27 11:21 UTC (permalink / raw)
To: Songtang Liu, joro, will
Cc: suravee.suthikulpanit, robin.murphy, vasant.hegde, iommu,
linux-kernel
Hi,
On 10/24/2025 1:32 PM, Songtang Liu wrote:
> In iommu_mmio_write(), it validates the user-provided offset with the
> check: `iommu->dbg_mmio_offset > iommu->mmio_phys_end - 4`.
> This assumes a 4-byte access. However, the corresponding
> show handler, iommu_mmio_show(), uses readq() to perform an 8-byte
> (64-bit) read.
>
> If a user provides an offset equal to `mmio_phys_end - 4`, the check
> passes, and will lead to a 4-byte out-of-bounds read.
>
> Fix this by adjusting the boundary check to use sizeof(u64), which
> corresponds to the size of the readq() operation.
>
> Fixes: 7a4ee419e8c1 ("iommu/amd: Add debugfs support to dump IOMMU
> MMIO registers")
> Signed-off-by: Songtang Liu <liusongtang@bytedance.com>
> ---
> drivers/iommu/amd/debugfs.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/iommu/amd/debugfs.c b/drivers/iommu/amd/debugfs.c
> index 8b4d7db7869a4..5d85c47478a57 100644
> --- a/drivers/iommu/amd/debugfs.c
> +++ b/drivers/iommu/amd/debugfs.c
> @@ -37,7 +37,7 @@ static ssize_t iommu_mmio_write(struct file *filp,
> const char __user *ubuf,
> if (ret)
> return ret;
>
> - if (iommu->dbg_mmio_offset > iommu->mmio_phys_end - 4) {
> + if (iommu->dbg_mmio_offset > iommu->mmio_phys_end - sizeof(u64)) {
LGTM.
Reviewed-by: Dheeraj Kumar Srivastava <dheerajkumar.srivastava@amd.com>
Tested-by: Dheeraj Kumar Srivastava <dheerajkumar.srivastava@amd.com>
Thanks
Dheeraj
> iommu->dbg_mmio_offset = -1;
> return -EINVAL;
> }
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-10-27 11:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-24 8:02 [PATCH] iommu/amd: Fix potential out-of-bounds read in iommu_mmio_show Songtang Liu
2025-10-27 11:21 ` Dheeraj Kumar Srivastava
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox