Re: [syzbot] [iommu?] KASAN: slab-use-after-free Read in iommufd_access_unpin_pages

From: Jason Gunthorpe
Date: Mon Jun 19 2023 - 14:08:57 EST


On Thu, Jun 15, 2023 at 11:01:13PM -0700, syzbot wrote:
> Hello,
>
> syzbot found the following issue on:
>
> HEAD commit: 4c605260bc60 Merge tag 'x86_urgent_for_v6.4_rc6' of git://..
> git tree: upstream
> console output: https://syzkaller.appspot.com/x/log.txt?x=14d07943280000
> kernel config: https://syzkaller.appspot.com/x/.config?x=3c980bfe8b399968
> dashboard link: https://syzkaller.appspot.com/bug?extid=6c8d756f238a75fc3eb8
> compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
> syz repro: https://syzkaller.appspot.com/x/repro.syz?x=158a29dd280000
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=167dd475280000
>
> Downloadable assets:
> disk image: https://storage.googleapis.com/syzbot-assets/9c4a756cb2ce/disk-4c605260.raw.xz
> vmlinux: https://storage.googleapis.com/syzbot-assets/321df5350ca6/vmlinux-4c605260.xz
> kernel image: https://storage.googleapis.com/syzbot-assets/f117647a1dc2/bzImage-4c605260.xz
>
> IMPORTANT: if you fix the issue, please add the following tag to the commit:
> Reported-by: syzbot+6c8d756f238a75fc3eb8@xxxxxxxxxxxxxxxxxxxxxxxxx
>
> ==================================================================
> BUG: KASAN: slab-use-after-free in iopt_area_last_iova drivers/iommu/iommufd/io_pagetable.h:88 [inline]
> BUG: KASAN: slab-use-after-free in iopt_area_contig_done drivers/iommu/iommufd/io_pagetable.h:160 [inline]
> BUG: KASAN: slab-use-after-free in iommufd_access_unpin_pages+0x363/0x370 drivers/iommu/iommufd/device.c:557
> Read of size 8 at addr ffff888022286e20 by task syz-executor669/5771
>
> CPU: 0 PID: 5771 Comm: syz-executor669 Not tainted 6.4.0-rc5-syzkaller-00313-g4c605260bc60 #0
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 05/25/2023
> Call Trace:
> <TASK>
> __dump_stack lib/dump_stack.c:88 [inline]
> dump_stack_lvl+0xd9/0x150 lib/dump_stack.c:106
> print_address_description.constprop.0+0x2c/0x3c0 mm/kasan/report.c:351
> print_report mm/kasan/report.c:462 [inline]
> kasan_report+0x11c/0x130 mm/kasan/report.c:572
> iopt_area_last_iova drivers/iommu/iommufd/io_pagetable.h:88 [inline]
> iopt_area_contig_done drivers/iommu/iommufd/io_pagetable.h:160 [inline]
> iommufd_access_unpin_pages+0x363/0x370 drivers/iommu/iommufd/device.c:557
> iommufd_test_access_unmap+0x24b/0x390 drivers/iommu/iommufd/selftest.c:613
> iommufd_access_notify_unmap+0x24c/0x3a0 drivers/iommu/iommufd/device.c:520
> iopt_unmap_iova_range+0x4c4/0x5f0 drivers/iommu/iommufd/io_pagetable.c:497
> iopt_unmap_all+0x27/0x50 drivers/iommu/iommufd/io_pagetable.c:555
> iommufd_ioas_unmap+0x3d0/0x490 drivers/iommu/iommufd/ioas.c:300
> iommufd_fops_ioctl+0x317/0x4b0 drivers/iommu/iommufd/main.c:337
> vfs_ioctl fs/ioctl.c:51 [inline]
> __do_sys_ioctl fs/ioctl.c:870 [inline]
> __se_sys_ioctl fs/ioctl.c:856 [inline]
> __x64_sys_ioctl+0x197/0x210 fs/ioctl.c:856
> do_syscall_x64 arch/x86/entry/common.c:50 [inline]
> do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
> entry_SYSCALL_64_after_hwframe+0x63/0xcd
> RIP: 0033:0x7fec1dae3b19
> Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 11 15 00 00 90 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 b8 ff ff ff f7 d8 64 89 01 48
> RSP: 002b:00007fec1da74308 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
> RAX: ffffffffffffffda RBX: 00007fec1db6b438 RCX: 00007fec1dae3b19
> RDX: 0000000020000100 RSI: 0000000000003b86 RDI: 0000000000000003
> RBP: 00007fec1db6b430 R08: 00007fec1da74700 R09: 0000000000000000
> R10: 00007fec1da74700 R11: 0000000000000246 R12: 00007fec1db6b43c
> R13: 00007fec1db39074 R14: 6d6f692f7665642f R15: 0000000000022000
> </TASK>

#syz dup: KASAN: slab-use-after-free Read in iopt_unmap_iova_range