Linux IOMMU Development
 help / color / mirror / Atom feed
From: Dheeraj Kumar Srivastava <dheerajkumar.srivastava@amd.com>
To: Songtang Liu <liusongtang@bytedance.com>, <joro@8bytes.org>,
	<will@kernel.org>
Cc: <suravee.suthikulpanit@amd.com>, <robin.murphy@arm.com>,
	<vasant.hegde@amd.com>, <iommu@lists.linux.dev>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] iommu/amd: Fix potential out-of-bounds read in iommu_mmio_show
Date: Mon, 27 Oct 2025 16:51:19 +0530	[thread overview]
Message-ID: <7d28fa51-0c1d-46da-9372-031ddc20874a@amd.com> (raw)
In-Reply-To: <CAA=HWd3_nKzKguK4JAs3aX7MhyX3mxFPLNLzEqwRPiSPTwvm6Q@mail.gmail.com>

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;
>   	}



      reply	other threads:[~2025-10-27 11:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7d28fa51-0c1d-46da-9372-031ddc20874a@amd.com \
    --to=dheerajkumar.srivastava@amd.com \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liusongtang@bytedance.com \
    --cc=robin.murphy@arm.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=vasant.hegde@amd.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox