syzbot


KASAN: slab-use-after-free Read in iommufd_vfio_ioas

Status: fixed on 2024/01/20 21:18
Subsystems: iommu
[Documentation on labels]
Reported-by: syzbot+d31adfb277377ef8fcba@syzkaller.appspotmail.com
Fix commit: 6f9c4d8c468c iommufd: Do not UAF during iommufd_put_object()
First crash: 125d, last: 103d
Cause bisection: introduced by (bisect log) :
commit 99f98a7c0d6985d5507c8130a981972e4b7b3bdc
Author: Jason Gunthorpe <jgg@nvidia.com>
Date: Tue Jul 25 19:05:49 2023 +0000

  iommufd: IOMMUFD_DESTROY should not increase the refcount

Crash: KASAN: slab-use-after-free Read in iommufd_vfio_ioas (log)
Repro: C syz .config
  
Discussions (2)
Title Replies (including bot) Last reply
Re: A bug was found in Linux Kernel 6.6+: KASAN: slab-use-after-free in iommufd_test (with POC) 1 (1) 2023/12/28 10:18
[syzbot] [iommu?] KASAN: slab-use-after-free Read in iommufd_vfio_ioas 0 (5) 2023/11/03 07:58
Last patch testing requests (6)
Created Duration User Patch Repo Result
2023/11/18 15:04 20m retest repro upstream report log
2023/11/03 11:45 23m hdanton@sina.com patch https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master OK log
2023/11/03 07:58 8m lizhi.xu@windriver.com patch https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2af9b20dbb39 error OK
2023/11/03 07:09 5m lizhi.xu@windriver.com patch https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2af9b20dbb39 error OK
2023/11/03 05:36 14m lizhi.xu@windriver.com patch https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2af9b20dbb39 report log
2023/11/03 01:18 24m lizhi.xu@windriver.com patch https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2af9b20dbb39 report log

Sample crash report:
==================================================================
BUG: KASAN: slab-use-after-free in __up_read+0x627/0x750 kernel/locking/rwsem.c:1342
Read of size 8 at addr ffff888073cde868 by task syz-executor934/6535

CPU: 1 PID: 6535 Comm: syz-executor934 Not tainted 6.6.0-rc7-syzkaller-00195-g2af9b20dbb39 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/09/2023
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xd9/0x1b0 lib/dump_stack.c:106
 print_address_description mm/kasan/report.c:364 [inline]
 print_report+0xc4/0x620 mm/kasan/report.c:475
 kasan_report+0xda/0x110 mm/kasan/report.c:588
 __up_read+0x627/0x750 kernel/locking/rwsem.c:1342
 iommufd_put_object drivers/iommu/iommufd/iommufd_private.h:149 [inline]
 iommufd_vfio_ioas+0x46c/0x580 drivers/iommu/iommufd/vfio_compat.c:146
 iommufd_fops_ioctl+0x347/0x4d0 drivers/iommu/iommufd/main.c:398
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:871 [inline]
 __se_sys_ioctl fs/ioctl.c:857 [inline]
 __x64_sys_ioctl+0x18f/0x210 fs/ioctl.c:857
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f7d7a6505d9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 51 18 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 b0 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f7d7a5f0218 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 0000000000000037 RCX: 00007f7d7a6505d9
RDX: 0000000020000080 RSI: 0000000000003b88 RDI: 0000000000000003
RBP: 00007f7d7a6da358 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007f7d7a6d8100
R13: 00007f7d7a6da350 R14: 00007f7d7a6da35c R15: 00007f7d7a6a7074
 </TASK>

Allocated by task 6529:
 kasan_save_stack+0x33/0x50 mm/kasan/common.c:45
 kasan_set_track+0x25/0x30 mm/kasan/common.c:52
 ____kasan_kmalloc mm/kasan/common.c:374 [inline]
 __kasan_kmalloc+0xa3/0xb0 mm/kasan/common.c:383
 kasan_kmalloc include/linux/kasan.h:198 [inline]
 __do_kmalloc_node mm/slab_common.c:1026 [inline]
 __kmalloc+0x60/0x100 mm/slab_common.c:1039
 kmalloc include/linux/slab.h:603 [inline]
 kzalloc include/linux/slab.h:720 [inline]
 _iommufd_object_alloc+0x26/0x1b0 drivers/iommu/iommufd/main.c:40
 iommufd_ioas_alloc drivers/iommu/iommufd/ioas.c:27 [inline]
 iommufd_ioas_alloc_ioctl+0xaf/0x370 drivers/iommu/iommufd/ioas.c:46
 iommufd_fops_ioctl+0x347/0x4d0 drivers/iommu/iommufd/main.c:398
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:871 [inline]
 __se_sys_ioctl fs/ioctl.c:857 [inline]
 __x64_sys_ioctl+0x18f/0x210 fs/ioctl.c:857
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Freed by task 6536:
 kasan_save_stack+0x33/0x50 mm/kasan/common.c:45
 kasan_set_track+0x25/0x30 mm/kasan/common.c:52
 kasan_save_free_info+0x28/0x40 mm/kasan/generic.c:522
 ____kasan_slab_free mm/kasan/common.c:236 [inline]
 ____kasan_slab_free+0x138/0x190 mm/kasan/common.c:200
 kasan_slab_free include/linux/kasan.h:164 [inline]
 __cache_free mm/slab.c:3370 [inline]
 __do_kmem_cache_free mm/slab.c:3557 [inline]
 __kmem_cache_free+0xcc/0x2d0 mm/slab.c:3564
 iommufd_destroy+0x11e/0x180 drivers/iommu/iommufd/main.c:216
 iommufd_fops_ioctl+0x347/0x4d0 drivers/iommu/iommufd/main.c:398
 vfs_ioctl fs/ioctl.c:51 [inline]
 __do_sys_ioctl fs/ioctl.c:871 [inline]
 __se_sys_ioctl fs/ioctl.c:857 [inline]
 __x64_sys_ioctl+0x18f/0x210 fs/ioctl.c:857
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

The buggy address belongs to the object at ffff888073cde800
 which belongs to the cache kmalloc-cg-1k of size 1024
The buggy address is located 104 bytes inside of
 freed 1024-byte region [ffff888073cde800, ffff888073cdec00)

The buggy address belongs to the physical page:
page:ffffea0001cf3780 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x73cde
flags: 0xfff00000000800(slab|node=0|zone=1|lastcpupid=0x7ff)
page_type: 0x2()
raw: 00fff00000000800 ffff888012c4d800 ffffea000082b690 ffffea0000712a10
raw: 0000000000000000 ffff888073cde000 0000000100000002 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x2420c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_COMP|__GFP_THISNODE), pid 4488, tgid 4488 (udevd), ts 55677988515, free_ts 55675597837
 set_page_owner include/linux/page_owner.h:31 [inline]
 post_alloc_hook+0x2cf/0x340 mm/page_alloc.c:1536
 prep_new_page mm/page_alloc.c:1543 [inline]
 get_page_from_freelist+0xee0/0x2f20 mm/page_alloc.c:3170
 __alloc_pages+0x1d0/0x4a0 mm/page_alloc.c:4426
 __alloc_pages_node include/linux/gfp.h:237 [inline]
 kmem_getpages mm/slab.c:1356 [inline]
 cache_grow_begin+0x99/0x3a0 mm/slab.c:2550
 cache_alloc_refill+0x294/0x3a0 mm/slab.c:2923
 ____cache_alloc mm/slab.c:2999 [inline]
 ____cache_alloc mm/slab.c:2982 [inline]
 __do_cache_alloc mm/slab.c:3182 [inline]
 slab_alloc_node mm/slab.c:3230 [inline]
 __kmem_cache_alloc_node+0x3c5/0x470 mm/slab.c:3521
 __do_kmalloc_node mm/slab_common.c:1025 [inline]
 __kmalloc+0x4f/0x100 mm/slab_common.c:1039
 kmalloc_array include/linux/slab.h:636 [inline]
 kcalloc include/linux/slab.h:667 [inline]
 alloc_pipe_info+0x1ed/0x580 fs/pipe.c:808
 get_pipe_inode fs/pipe.c:882 [inline]
 create_pipe_files+0x8f/0x870 fs/pipe.c:914
 __do_pipe_flags fs/pipe.c:963 [inline]
 do_pipe2+0xb0/0x1c0 fs/pipe.c:1014
 __do_sys_pipe2 fs/pipe.c:1032 [inline]
 __se_sys_pipe2 fs/pipe.c:1030 [inline]
 __x64_sys_pipe2+0x54/0x80 fs/pipe.c:1030
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1136 [inline]
 free_unref_page_prepare+0x476/0xa40 mm/page_alloc.c:2312
 free_unref_page+0x33/0x3b0 mm/page_alloc.c:2405
 selinux_genfs_get_sid security/selinux/hooks.c:1341 [inline]
 inode_doinit_with_dentry+0xac0/0x12c0 security/selinux/hooks.c:1539
 selinux_d_instantiate+0x26/0x30 security/selinux/hooks.c:6284
 security_d_instantiate+0x54/0xe0 security/security.c:3799
 d_splice_alias+0x94/0xdf0 fs/dcache.c:3145
 kernfs_iop_lookup+0x283/0x330 fs/kernfs/dir.c:1208
 __lookup_slow+0x24d/0x450 fs/namei.c:1694
 lookup_slow fs/namei.c:1711 [inline]
 walk_component+0x349/0x5a0 fs/namei.c:2002
 lookup_last fs/namei.c:2459 [inline]
 path_lookupat+0x17f/0x770 fs/namei.c:2483
 filename_lookup+0x1e7/0x5b0 fs/namei.c:2512
 vfs_statx+0x160/0x430 fs/stat.c:240
 vfs_fstatat+0xb3/0x140 fs/stat.c:295
 __do_sys_newfstatat+0x98/0x110 fs/stat.c:459
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x38/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Memory state around the buggy address:
 ffff888073cde700: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff888073cde780: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff888073cde800: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                                                          ^
 ffff888073cde880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888073cde900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (4):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2023/10/30 01:08 upstream 2af9b20dbb39 3c418d72 .config console log report syz C [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-selinux-root KASAN: slab-use-after-free Read in iommufd_vfio_ioas
2023/11/20 16:54 git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci 8de1e7afcc1c cb976f63 .config console log report syz C [disk image] [vmlinux] [kernel image] ci-upstream-gce-arm64 KASAN: slab-use-after-free Read in iommufd_vfio_ioas
2023/11/04 02:58 upstream 8f6f76a6a29f 500bfdc4 .config console log report syz [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce KASAN: slab-use-after-free Read in iommufd_vfio_ioas
2023/10/29 22:55 upstream 2af9b20dbb39 3c418d72 .config console log report info [disk image] [vmlinux] [kernel image] ci-upstream-kasan-gce-selinux-root KASAN: slab-use-after-free Read in iommufd_vfio_ioas
* Struck through repros no longer work on HEAD.