patches.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Joao Martins <joao.m.martins@oracle.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: Alex Williamson <alex.williamson@redhat.com>,
	patches@lists.linux.dev, stable@vger.kernel.org,
	syzbot+093a8a8b859472e6c257@syzkaller.appspotmail.com,
	Yishai Hadas <yishaih@nvidia.com>,
	iommu@lists.linux.dev, Joerg Roedel <joro@8bytes.org>,
	Kevin Tian <kevin.tian@intel.com>,
	Robin Murphy <robin.murphy@arm.com>,
	Will Deacon <will@kernel.org>
Subject: Re: [PATCH rc] iommufd: Don't overflow during division for dirty tracking
Date: Wed, 8 Oct 2025 22:35:04 +0100	[thread overview]
Message-ID: <10599aac-3370-4f8a-a18b-4ca2d645d6b6@oracle.com> (raw)
In-Reply-To: <0-v1-663679b57226+172-iommufd_dirty_div0_jgg@nvidia.com>

On 08/10/2025 19:17, Jason Gunthorpe wrote:
> If pgshift is 63 then BITS_PER_TYPE(*bitmap->bitmap) * pgsize will overflow
> to 0 and this triggers divide by 0.
> 
> In this case the index should just be 0, so reorganize things to divide
> by shift and avoid hitting any overflows.
> 
> Cc: stable@vger.kernel.org
> Fixes: 58ccf0190d19 ("vfio: Add an IOVA bitmap support")
> Reported-by: syzbot+093a8a8b859472e6c257@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=093a8a8b859472e6c257
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

Reviewed-by: Joao Martins <joao.m.martins@oracle.com>

> ---
>  drivers/iommu/iommufd/iova_bitmap.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iommu/iommufd/iova_bitmap.c b/drivers/iommu/iommufd/iova_bitmap.c
> index 4514575818fc07..b5b67a9d3fb35e 100644
> --- a/drivers/iommu/iommufd/iova_bitmap.c
> +++ b/drivers/iommu/iommufd/iova_bitmap.c
> @@ -130,9 +130,8 @@ struct iova_bitmap {
>  static unsigned long iova_bitmap_offset_to_index(struct iova_bitmap *bitmap,
>  						 unsigned long iova)
>  {
> -	unsigned long pgsize = 1UL << bitmap->mapped.pgshift;
> -
> -	return iova / (BITS_PER_TYPE(*bitmap->bitmap) * pgsize);
> +	return (iova >> bitmap->mapped.pgshift) /
> +	       BITS_PER_TYPE(*bitmap->bitmap);
>  }
>  
>  /*
> 
> base-commit: 2a918911ed3d0841923525ed0fe707762ee78844


  parent reply	other threads:[~2025-10-08 21:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-08 18:17 [PATCH rc] iommufd: Don't overflow during division for dirty tracking Jason Gunthorpe
2025-10-08 18:57 ` Nicolin Chen
2025-10-08 21:35 ` Joao Martins [this message]
2025-10-16  7:36 ` Tian, Kevin
2025-10-20 22:59 ` Jason Gunthorpe

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=10599aac-3370-4f8a-a18b-4ca2d645d6b6@oracle.com \
    --to=joao.m.martins@oracle.com \
    --cc=alex.williamson@redhat.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=patches@lists.linux.dev \
    --cc=robin.murphy@arm.com \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+093a8a8b859472e6c257@syzkaller.appspotmail.com \
    --cc=will@kernel.org \
    --cc=yishaih@nvidia.com \
    /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;
as well as URLs for NNTP newsgroup(s).