patches.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH rc] iommufd: Don't overflow during division for dirty tracking
@ 2025-10-08 18:17 Jason Gunthorpe
  2025-10-08 18:57 ` Nicolin Chen
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Jason Gunthorpe @ 2025-10-08 18:17 UTC (permalink / raw)
  To: iommu, Joerg Roedel, Kevin Tian, Robin Murphy, Will Deacon
  Cc: Alex Williamson, Joao Martins, patches, stable,
	syzbot+093a8a8b859472e6c257, Yishai Hadas

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>
---
 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
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH rc] iommufd: Don't overflow during division for dirty tracking
  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
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Nicolin Chen @ 2025-10-08 18:57 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: iommu, Joerg Roedel, Kevin Tian, Robin Murphy, Will Deacon,
	Alex Williamson, Joao Martins, patches, stable,
	syzbot+093a8a8b859472e6c257, Yishai Hadas

On Wed, Oct 08, 2025 at 03:17:18PM -0300, 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: Nicolin Chen <nicolinc@nvidia.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH rc] iommufd: Don't overflow during division for dirty tracking
  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
  2025-10-16  7:36 ` Tian, Kevin
  2025-10-20 22:59 ` Jason Gunthorpe
  3 siblings, 0 replies; 5+ messages in thread
From: Joao Martins @ 2025-10-08 21:35 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Alex Williamson, patches, stable, syzbot+093a8a8b859472e6c257,
	Yishai Hadas, iommu, Joerg Roedel, Kevin Tian, Robin Murphy,
	Will Deacon

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH rc] iommufd: Don't overflow during division for dirty tracking
  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
@ 2025-10-16  7:36 ` Tian, Kevin
  2025-10-20 22:59 ` Jason Gunthorpe
  3 siblings, 0 replies; 5+ messages in thread
From: Tian, Kevin @ 2025-10-16  7:36 UTC (permalink / raw)
  To: Jason Gunthorpe, iommu@lists.linux.dev, Joerg Roedel,
	Robin Murphy, Will Deacon
  Cc: Alex Williamson, Joao Martins, patches@lists.linux.dev,
	stable@vger.kernel.org,
	syzbot+093a8a8b859472e6c257@syzkaller.appspotmail.com,
	Yishai Hadas

> From: Jason Gunthorpe <jgg@nvidia.com>
> Sent: Thursday, October 9, 2025 2:17 AM
> 
> 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: Kevin Tian <kevin.tian@intel.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH rc] iommufd: Don't overflow during division for dirty tracking
  2025-10-08 18:17 [PATCH rc] iommufd: Don't overflow during division for dirty tracking Jason Gunthorpe
                   ` (2 preceding siblings ...)
  2025-10-16  7:36 ` Tian, Kevin
@ 2025-10-20 22:59 ` Jason Gunthorpe
  3 siblings, 0 replies; 5+ messages in thread
From: Jason Gunthorpe @ 2025-10-20 22:59 UTC (permalink / raw)
  To: iommu, Joerg Roedel, Kevin Tian, Robin Murphy, Will Deacon
  Cc: Alex Williamson, Joao Martins, patches, stable,
	syzbot+093a8a8b859472e6c257, Yishai Hadas

On Wed, Oct 08, 2025 at 03:17:18PM -0300, 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>
> ---
>  drivers/iommu/iommufd/iova_bitmap.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)

Applied to for-rc

Thanks,
Jason

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-10-20 22:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2025-10-16  7:36 ` Tian, Kevin
2025-10-20 22:59 ` Jason Gunthorpe

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).