mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [syzbot] [iommu?] divide error in iova_bitmap_alloc
@ 2025-10-07 23:32 syzbot
  2025-10-08  7:53 ` [PATCH] iommufd: Prevent the use of nil data Edward Adam Davis
  0 siblings, 1 reply; 3+ messages in thread
From: syzbot @ 2025-10-07 23:32 UTC (permalink / raw)
  To: iommu, jgg, joro, kevin.tian, linux-kernel, robin.murphy,
	syzkaller-bugs, will

Hello,

syzbot found the following issue on:

HEAD commit:    971199ad2a0f Merge tag 'arm64-fixes' of git://git.kernel.o..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=1570f92f980000
kernel config:  https://syzkaller.appspot.com/x/.config?x=87fcad19f7d09298
dashboard link: https://syzkaller.appspot.com/bug?extid=093a8a8b859472e6c257
compiler:       gcc (Debian 12.2.0-14+deb12u1) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=16286304580000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=1370f92f980000

Downloadable assets:
disk image (non-bootable): https://storage.googleapis.com/syzbot-assets/d900f083ada3/non_bootable_disk-971199ad.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/a4f2f91ba510/vmlinux-971199ad.xz
kernel image: https://storage.googleapis.com/syzbot-assets/8fa7552ebcd0/bzImage-971199ad.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+093a8a8b859472e6c257@syzkaller.appspotmail.com

Oops: divide error: 0000 [#1] SMP KASAN NOPTI
CPU: 2 UID: 0 PID: 6098 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2~bpo12+1 04/01/2014
RIP: 0010:iova_bitmap_offset_to_index drivers/iommu/iommufd/iova_bitmap.c:135 [inline]
RIP: 0010:iova_bitmap_alloc+0xe8/0x350 drivers/iommu/iommufd/iova_bitmap.c:259
Code: e8 3d ad 7e fc 48 83 fd 3f 0f 87 c0 8c e9 fb e8 be b1 7e fc 89 e9 b8 08 00 00 00 31 d2 48 d3 e0 48 8d 7b 40 48 89 c1 4c 89 e0 <48> f7 f1 48 ba 00 00 00 00 00 fc ff df 48 89 f9 48 c1 e9 03 48 83
RSP: 0018:ffffc900034ffba8 EFLAGS: 00010246
RAX: ffffffffffffffff RBX: ffff888032636100 RCX: 0000000000000000
RDX: 0000000000000000 RSI: ffffffff853dc2d2 RDI: ffff888032636140
RBP: 000000000000003f R08: 0000000000000007 R09: 000000000000003f
R10: 000000000000003f R11: 0000000000000000 R12: ffffffffffffffff
R13: 0000000000000000 R14: 0000000000000000 R15: ffffffff8c065aa0
FS:  000055558b0da500(0000) GS:ffff8880d6bdf000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000001b2f463fff CR3: 000000004ee7c000 CR4: 0000000000352ef0
Call Trace:
 <TASK>
 iommu_read_and_clear_dirty drivers/iommu/iommufd/io_pagetable.c:543 [inline]
 iopt_read_and_clear_dirty_data+0x271/0x4c0 drivers/iommu/iommufd/io_pagetable.c:603
 iommufd_hwpt_get_dirty_bitmap+0x1c3/0x340 drivers/iommu/iommufd/hw_pagetable.c:485
 iommufd_fops_ioctl+0x34d/0x540 drivers/iommu/iommufd/main.c:533
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:597 [inline]
 __se_sys_ioctl fs/ioctl.c:583 [inline]
 __x64_sys_ioctl+0x18b/0x210 fs/ioctl.c:583
 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
 do_syscall_64+0xcd/0xfa0 arch/x86/entry/syscall_64.c:94
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f705598eec9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffeac4d43a8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007f7055be5fa0 RCX: 00007f705598eec9
RDX: 0000200000000300 RSI: 0000000000003b8c RDI: 0000000000000003
RBP: 00007f7055a11f91 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f7055be5fa0 R14: 00007f7055be5fa0 R15: 0000000000000003
 </TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:iova_bitmap_offset_to_index drivers/iommu/iommufd/iova_bitmap.c:135 [inline]
RIP: 0010:iova_bitmap_alloc+0xe8/0x350 drivers/iommu/iommufd/iova_bitmap.c:259
Code: e8 3d ad 7e fc 48 83 fd 3f 0f 87 c0 8c e9 fb e8 be b1 7e fc 89 e9 b8 08 00 00 00 31 d2 48 d3 e0 48 8d 7b 40 48 89 c1 4c 89 e0 <48> f7 f1 48 ba 00 00 00 00 00 fc ff df 48 89 f9 48 c1 e9 03 48 83
RSP: 0018:ffffc900034ffba8 EFLAGS: 00010246
RAX: ffffffffffffffff RBX: ffff888032636100 RCX: 0000000000000000
RDX: 0000000000000000 RSI: ffffffff853dc2d2 RDI: ffff888032636140
RBP: 000000000000003f R08: 0000000000000007 R09: 000000000000003f
R10: 000000000000003f R11: 0000000000000000 R12: ffffffffffffffff
R13: 0000000000000000 R14: 0000000000000000 R15: ffffffff8c065aa0
FS:  000055558b0da500(0000) GS:ffff8880d6cdf000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000055558b0da808 CR3: 000000004ee7c000 CR4: 0000000000352ef0
----------------
Code disassembly (best guess):
   0:	e8 3d ad 7e fc       	call   0xfc7ead42
   5:	48 83 fd 3f          	cmp    $0x3f,%rbp
   9:	0f 87 c0 8c e9 fb    	ja     0xfbe98ccf
   f:	e8 be b1 7e fc       	call   0xfc7eb1d2
  14:	89 e9                	mov    %ebp,%ecx
  16:	b8 08 00 00 00       	mov    $0x8,%eax
  1b:	31 d2                	xor    %edx,%edx
  1d:	48 d3 e0             	shl    %cl,%rax
  20:	48 8d 7b 40          	lea    0x40(%rbx),%rdi
  24:	48 89 c1             	mov    %rax,%rcx
  27:	4c 89 e0             	mov    %r12,%rax
* 2a:	48 f7 f1             	div    %rcx <-- trapping instruction
  2d:	48 ba 00 00 00 00 00 	movabs $0xdffffc0000000000,%rdx
  34:	fc ff df
  37:	48 89 f9             	mov    %rdi,%rcx
  3a:	48 c1 e9 03          	shr    $0x3,%rcx
  3e:	48                   	rex.W
  3f:	83                   	.byte 0x83


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

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

* [PATCH] iommufd: Prevent the use of nil data
  2025-10-07 23:32 [syzbot] [iommu?] divide error in iova_bitmap_alloc syzbot
@ 2025-10-08  7:53 ` Edward Adam Davis
  2025-10-08 18:10   ` Jason Gunthorpe
  0 siblings, 1 reply; 3+ messages in thread
From: Edward Adam Davis @ 2025-10-08  7:53 UTC (permalink / raw)
  To: syzbot+093a8a8b859472e6c257
  Cc: iommu, jgg, joro, kevin.tian, linux-kernel, robin.murphy,
	syzkaller-bugs, will

The division exception occurs because:
The denominator bitmap->bitmap is 0, which is derived from the nil value
of bitmap->data passed in by the reproducer.

Before calling iova_bitmap_alloc() to allocate iter, add a check for a
null value in data to avoid the division exception.

syzbot reported:
divide error in iova_bitmap_alloc

Call Trace:
 <TASK>
 iommu_read_and_clear_dirty drivers/iommu/iommufd/io_pagetable.c:543 [inline]
 iopt_read_and_clear_dirty_data+0x271/0x4c0 drivers/iommu/iommufd/io_pagetable.c:603
 iommufd_hwpt_get_dirty_bitmap+0x1c3/0x340 drivers/iommu/iommufd/hw_pagetable.c:485

Reported-by: syzbot+093a8a8b859472e6c257@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=093a8a8b859472e6c257
Signed-off-by: Edward Adam Davis <eadavis@qq.com>
---
 drivers/iommu/iommufd/io_pagetable.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/iommu/iommufd/io_pagetable.c b/drivers/iommu/iommufd/io_pagetable.c
index c0360c450880..9ddaed95e79f 100644
--- a/drivers/iommu/iommufd/io_pagetable.c
+++ b/drivers/iommu/iommufd/io_pagetable.c
@@ -540,6 +540,9 @@ iommu_read_and_clear_dirty(struct iommu_domain *domain,
 	if (!ops || !ops->read_and_clear_dirty)
 		return -EOPNOTSUPP;
 
+	if (!bitmap->data)
+		return -EINVAL;
+
 	iter = iova_bitmap_alloc(bitmap->iova, bitmap->length,
 				 bitmap->page_size,
 				 u64_to_user_ptr(bitmap->data));
-- 
2.43.0


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

* Re: [PATCH] iommufd: Prevent the use of nil data
  2025-10-08  7:53 ` [PATCH] iommufd: Prevent the use of nil data Edward Adam Davis
@ 2025-10-08 18:10   ` Jason Gunthorpe
  0 siblings, 0 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2025-10-08 18:10 UTC (permalink / raw)
  To: Edward Adam Davis
  Cc: syzbot+093a8a8b859472e6c257, iommu, joro, kevin.tian,
	linux-kernel, robin.murphy, syzkaller-bugs, will

On Wed, Oct 08, 2025 at 03:53:07PM +0800, Edward Adam Davis wrote:
> The division exception occurs because:
> The denominator bitmap->bitmap is 0, which is derived from the nil value
> of bitmap->data passed in by the reproducer.

No, that just causes the reproducer to bail early. The reported
problem is divide by zero. Which is caused by this:

	unsigned long pgsize = 1UL << bitmap->mapped.pgshift;

	return iova / (BITS_PER_TYPE(*bitmap->bitmap) * pgsize);


  //  ioctl$IOMMU_HWPT_GET_DIRTY_BITMAP arguments: [
  //    fd: fd_iommufd (resource)
  //    cmd: const = 0x3b8c (4 bytes)
  //    arg: ptr[in, iommu_hwpt_get_dirty_bitmap] {
  //      iommu_hwpt_get_dirty_bitmap {
  //        size: len = 0x30 (4 bytes)
  //        hwpt_id: hwpt_handle (resource)
  //        flags: iommufd_hwpt_get_dirty_bitmap_flags = 0x0 (4 bytes)
  //        __reserved: const = 0x0 (4 bytes)
  //        iova: int64 = 0x0 (8 bytes)
  //        length: int64 = 0x0 (8 bytes)
  //        page_size: int64 = 0x8000000000000000 (8 bytes)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^

0x8000000000000000 * BITS_PER_TYPE(*bitmap->bitmap) == 0

It should be fixed by adjusting the logic:

+       return (iova >> bitmap->mapped.pgshift) /
+              BITS_PER_TYPE(*bitmap->bitmap);

I will send a patch.

Jason

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

end of thread, other threads:[~2025-10-08 18:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-07 23:32 [syzbot] [iommu?] divide error in iova_bitmap_alloc syzbot
2025-10-08  7:53 ` [PATCH] iommufd: Prevent the use of nil data Edward Adam Davis
2025-10-08 18:10   ` Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome