]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
iommu: Protect against overflow in iommu_pgsize()
authorJason Gunthorpe <jgg@nvidia.com>
Fri, 25 Apr 2025 13:08:37 +0000 (10:08 -0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 27 Jun 2025 10:05:12 +0000 (11:05 +0100)
commit65b935d4e5c449bc55abbd75de1a4450988928f9
tree5051a3b40bac45c802683b2025dd8af1eb92c50f
parent5c3e52ab78878601eada0587302a3a2597617cc2
iommu: Protect against overflow in iommu_pgsize()

[ Upstream commit e586e22974d2b7acbef3c6c3e01b2d5ce69efe33 ]

On a 32 bit system calling:
 iommu_map(0, 0x40000000)

When using the AMD V1 page table type with a domain->pgsize of 0xfffff000
causes iommu_pgsize() to miscalculate a result of:
  size=0x40000000 count=2

count should be 1. This completely corrupts the mapping process.

This is because the final test to adjust the pagesize malfunctions when
the addition overflows. Use check_add_overflow() to prevent this.

Fixes: b1d99dc5f983 ("iommu: Hook up '->unmap_pages' driver callback")
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Link: https://lore.kernel.org/r/0-v1-3ad28fc2e3a3+163327-iommu_overflow_pgsize_jgg@nvidia.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/iommu/iommu.c