Skip to content

Commit 2ed48eb

Browse files
committed
iommufd: Don't overflow during division for dirty tracking
JIRA: https://issues.redhat.com/browse/RHEL-131315 Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git commit cb30dfa Author: Jason Gunthorpe <jgg@ziepe.ca> Date: Wed Oct 8 15:17:18 2025 -0300 iommufd: Don't overflow during division for dirty tracking 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. Link: https://patch.msgid.link/r/0-v1-663679b57226+172-iommufd_dirty_div0_jgg@nvidia.com Cc: stable@vger.kernel.org Fixes: 58ccf01 ("vfio: Add an IOVA bitmap support") Reviewed-by: Joao Martins <joao.m.martins@oracle.com> Reviewed-by: Nicolin Chen <nicolinc@nvidia.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reported-by: syzbot+093a8a8b859472e6c257@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=093a8a8b859472e6c257 Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Eder Zulian <ezulian@redhat.com>
1 parent e99d75c commit 2ed48eb

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/iommu/iommufd/iova_bitmap.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,8 @@ struct iova_bitmap {
130130
static unsigned long iova_bitmap_offset_to_index(struct iova_bitmap *bitmap,
131131
unsigned long iova)
132132
{
133-
unsigned long pgsize = 1UL << bitmap->mapped.pgshift;
134-
135-
return iova / (BITS_PER_TYPE(*bitmap->bitmap) * pgsize);
133+
return (iova >> bitmap->mapped.pgshift) /
134+
BITS_PER_TYPE(*bitmap->bitmap);
136135
}
137136

138137
/*

0 commit comments

Comments
 (0)