linux/drivers/iommu
Jason Gunthorpe 8f6887349b iommufd: Protect against overflow of ALIGN() during iova allocation
Userspace can supply an iova and uptr such that the target iova alignment
becomes really big and ALIGN() overflows which corrupts the selected area
range during allocation. CONFIG_IOMMUFD_TEST can detect this:

   WARNING: CPU: 1 PID: 5092 at drivers/iommu/iommufd/io_pagetable.c:268 iopt_alloc_area_pages drivers/iommu/iommufd/io_pagetable.c:268 [inline]
   WARNING: CPU: 1 PID: 5092 at drivers/iommu/iommufd/io_pagetable.c:268 iopt_map_pages+0xf95/0x1050 drivers/iommu/iommufd/io_pagetable.c:352
   Modules linked in:
   CPU: 1 PID: 5092 Comm: syz-executor294 Not tainted 6.10.0-rc5-syzkaller-00294-g3ffea9a7a6f7 #0
   Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 06/07/2024
   RIP: 0010:iopt_alloc_area_pages drivers/iommu/iommufd/io_pagetable.c:268 [inline]
   RIP: 0010:iopt_map_pages+0xf95/0x1050 drivers/iommu/iommufd/io_pagetable.c:352
   Code: fc e9 a4 f3 ff ff e8 1a 8b 4c fc 41 be e4 ff ff ff e9 8a f3 ff ff e8 0a 8b 4c fc 90 0f 0b 90 e9 37 f5 ff ff e8 fc 8a 4c fc 90 <0f> 0b 90 e9 68 f3 ff ff 48 c7 c1 ec 82 ad 8f 80 e1 07 80 c1 03 38
   RSP: 0018:ffffc90003ebf9e0 EFLAGS: 00010293
   RAX: ffffffff85499fa4 RBX: 00000000ffffffef RCX: ffff888079b49e00
   RDX: 0000000000000000 RSI: 00000000ffffffef RDI: 0000000000000000
   RBP: ffffc90003ebfc50 R08: ffffffff85499b30 R09: ffffffff85499942
   R10: 0000000000000002 R11: ffff888079b49e00 R12: ffff8880228e0010
   R13: 0000000000000000 R14: 1ffff920007d7f68 R15: ffffc90003ebfd00
   FS:  000055557d760380(0000) GS:ffff8880b9500000(0000) knlGS:0000000000000000
   CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
   CR2: 00000000005fdeb8 CR3: 000000007404a000 CR4: 00000000003506f0
   DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
   DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
   Call Trace:
    <TASK>
    iommufd_ioas_copy+0x610/0x7b0 drivers/iommu/iommufd/ioas.c:274
    iommufd_fops_ioctl+0x4d9/0x5a0 drivers/iommu/iommufd/main.c:421
    vfs_ioctl fs/ioctl.c:51 [inline]
    __do_sys_ioctl fs/ioctl.c:907 [inline]
    __se_sys_ioctl+0xfc/0x170 fs/ioctl.c:893
    do_syscall_x64 arch/x86/entry/common.c:52 [inline]
    do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
    entry_SYSCALL_64_after_hwframe+0x77/0x7f

Cap the automatic alignment to the huge page size, which is probably a
better idea overall. Huge automatic alignments can fragment and chew up
the available IOVA space without any reason.

Link: https://patch.msgid.link/r/0-v1-8009738b9891+1f7-iommufd_align_overflow_jgg@nvidia.com
Cc: stable@vger.kernel.org
Fixes: 51fe6141f0 ("iommufd: Data structure to provide IOVA to PFN mapping")
Reviewed-by: Nicolin Chen <nicolinc@nvidia.com>
Reported-by: syzbot+16073ebbc4c64b819b47@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/r/000000000000388410061a74f014@google.com
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
2024-09-05 13:54:41 -03:00
..
amd IOMMU Fixes for Linux v6.11-rc1 2024-07-27 12:39:55 -07:00
arm iommu: arm-smmu: Fix Tegra workaround for PAGE_SIZE mappings 2024-07-25 13:08:44 +01:00
intel IOMMU Updates for Linux v6.11 2024-07-19 09:59:58 -07:00
iommufd iommufd: Protect against overflow of ALIGN() during iova allocation 2024-09-05 13:54:41 -03:00
apple-dart.c
dma-iommu.c dma-mapping updates for Linux 6.11 2024-07-19 10:20:26 -07:00
dma-iommu.h
exynos-iommu.c
fsl_pamu_domain.c
fsl_pamu_domain.h
fsl_pamu.c
fsl_pamu.h
hyperv-iommu.c
io-pgfault.c iommu: Restore lost return in iommu_report_device_fault() 2024-08-02 15:58:05 +02:00
io-pgtable-arm-v7s.c
io-pgtable-arm.c iommu/arm-smmu-v3: Enable HTTU for stage1 with io-pgtable mapping 2024-07-03 15:45:47 +01:00
io-pgtable-arm.h
io-pgtable-dart.c
io-pgtable.c
iommu-debugfs.c
iommu-pages.h
iommu-priv.h Merge branch 'iommu/iommufd/attach-handles' into iommu/next 2024-07-12 16:57:42 +01:00
iommu-sva.c Merge branch 'iommu/iommufd/attach-handles' into iommu/next 2024-07-12 16:57:42 +01:00
iommu-sysfs.c
iommu-traces.c
iommu.c Merge branch 'iommu/iommufd/paging-domain-alloc' into iommu/next 2024-07-12 16:57:47 +01:00
iova.c
ipmmu-vmsa.c
irq_remapping.c
irq_remapping.h
Kconfig iommu/arm-smmu-v3: Enable HTTU for stage1 with io-pgtable mapping 2024-07-03 15:45:47 +01:00
Makefile
msm_iommu_hw-8xxx.h
msm_iommu.c
msm_iommu.h
mtk_iommu_v1.c iommu: Resolve fwspec ops automatically 2024-07-04 14:36:03 +01:00
mtk_iommu.c
of_iommu.c Merge branch 'iommu/pci/ats' into iommu/next 2024-07-12 16:57:34 +01:00
omap-iommu-debug.c
omap-iommu.c
omap-iommu.h
omap-iopgtable.h
rockchip-iommu.c
s390-iommu.c
sprd-iommu.c iommu: sprd: Avoid NULL deref in sprd_iommu_hw_en 2024-07-23 17:09:28 +01:00
sun50i-iommu.c
tegra-smmu.c Merge branch 'iommu/fwspec-ops-removal' into iommu/next 2024-07-12 16:55:43 +01:00
virtio-iommu.c virtio: rename virtio_find_vqs_info() to virtio_find_vqs() 2024-07-17 05:20:58 -04:00