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

12 views
Skip to first unread message

syzbot

unread,
Nov 2, 2023, 7:03:30 PM11/2/23
to io...@lists.linux.dev, j...@nvidia.com, j...@ziepe.ca, jo...@8bytes.org, kevin...@intel.com, linux-...@vger.kernel.org, robin....@arm.com, syzkall...@googlegroups.com, wi...@kernel.org
Hello,

syzbot found the following issue on:

HEAD commit: 2af9b20dbb39 Merge tag 'x86-urgent-2023-10-28' of git://gi..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=114a6a73680000
kernel config: https://syzkaller.appspot.com/x/.config?x=cb98fe061049a6e4
dashboard link: https://syzkaller.appspot.com/bug?extid=d31adfb277377ef8fcba
compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=122fb4d1680000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=1330c151680000

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/073dcbc6250b/disk-2af9b20d.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/842a91197227/vmlinux-2af9b20d.xz
kernel image: https://storage.googleapis.com/syzbot-assets/760ca08d7937/bzImage-2af9b20d.xz

The issue was bisected to:

commit 99f98a7c0d6985d5507c8130a981972e4b7b3bdc
Author: Jason Gunthorpe <j...@nvidia.com>
Date: Tue Jul 25 19:05:49 2023 +0000

iommufd: IOMMUFD_DESTROY should not increase the refcount

bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=125266e7680000
final oops: https://syzkaller.appspot.com/x/report.txt?x=115266e7680000
console output: https://syzkaller.appspot.com/x/log.txt?x=165266e7680000

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+d31adf...@syzkaller.appspotmail.com
Fixes: 99f98a7c0d69 ("iommufd: IOMMUFD_DESTROY should not increase the refcount")

==================================================================
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
==================================================================


---
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 syzk...@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
For information about bisection process see: https://goo.gl/tpsmEJ#bisection

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

Lizhi Xu

unread,
Nov 2, 2023, 9:18:09 PM11/2/23
to syzbot+d31adf...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2af9b20dbb39

diff --git a/drivers/iommu/iommufd/vfio_compat.c b/drivers/iommu/iommufd/vfio_compat.c
index 6c810bf80f99..85cff4489757 100644
--- a/drivers/iommu/iommufd/vfio_compat.c
+++ b/drivers/iommu/iommufd/vfio_compat.c
@@ -138,6 +138,8 @@ int iommufd_vfio_ioas(struct iommufd_ucmd *ucmd)

case IOMMU_VFIO_IOAS_SET:
ioas = iommufd_get_ioas(ucmd->ictx, cmd->ioas_id);
+ if (!ioas)
+ return -EINVAL;
if (IS_ERR(ioas))
return PTR_ERR(ioas);
xa_lock(&ucmd->ictx->objects);

syzbot

unread,
Nov 3, 2023, 12:08:04 AM11/3/23
to linux-...@vger.kernel.org, lizh...@windriver.com, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Read in iommufd_vfio_ioas

==================================================================
BUG: KASAN: slab-use-after-free in instrument_atomic_read include/linux/instrumented.h:68 [inline]
BUG: KASAN: slab-use-after-free in atomic_long_read include/linux/atomic/atomic-instrumented.h:3160 [inline]
BUG: KASAN: slab-use-after-free in is_rwsem_reader_owned kernel/locking/rwsem.c:193 [inline]
BUG: KASAN: slab-use-after-free in __up_read+0xce/0x750 kernel/locking/rwsem.c:1343
Read of size 8 at addr ffff88807db5a800 by task syz-executor.4/6650

CPU: 0 PID: 6650 Comm: syz-executor.4 Not tainted 6.6.0-rc7-syzkaller-00195-g2af9b20dbb39-dirty #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
check_region_inline mm/kasan/generic.c:181 [inline]
kasan_check_range+0xef/0x190 mm/kasan/generic.c:187
instrument_atomic_read include/linux/instrumented.h:68 [inline]
atomic_long_read include/linux/atomic/atomic-instrumented.h:3160 [inline]
is_rwsem_reader_owned kernel/locking/rwsem.c:193 [inline]
__up_read+0xce/0x750 kernel/locking/rwsem.c:1343
iommufd_put_object drivers/iommu/iommufd/iommufd_private.h:149 [inline]
iommufd_vfio_ioas+0x47a/0x5a0 drivers/iommu/iommufd/vfio_compat.c:148
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:0x7f6c5a87cae9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 e1 20 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:00007f6c5b60d0c8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007f6c5a99c050 RCX: 00007f6c5a87cae9
RDX: 0000000020000080 RSI: 0000000000003b88 RDI: 0000000000000003
RBP: 00007f6c5a8c847a R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 000000000000000b R14: 00007f6c5a99c050 R15: 00007ffecfcd2da8
</TASK>

Allocated by task 6649:
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 6651:
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 ffff88807db5a800
which belongs to the cache kmalloc-cg-1k of size 1024
The buggy address is located 0 bytes inside of
freed 1024-byte region [ffff88807db5a800, ffff88807db5ac00)

The buggy address belongs to the physical page:
page:ffffea0001f6d680 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x7db5a
memcg:ffff888063c85681
flags: 0xfff00000000800(slab|node=0|zone=1|lastcpupid=0x7ff)
page_type: 0x2()
raw: 00fff00000000800 ffff888012c4d800 ffffea0000af4c50 ffffea0001e64e10
raw: 0000000000000000 ffff88807db5a000 0000000100000002 ffff888063c85681
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 4892, tgid 4892 (dhcpcd-run-hook), ts 66035864217, free_ts 66034134175
skb_free_frag include/linux/skbuff.h:3260 [inline]
skb_free_head+0xa6/0x1b0 net/core/skbuff.c:955
skb_release_data+0x5ba/0x870 net/core/skbuff.c:987
skb_release_all net/core/skbuff.c:1053 [inline]
__kfree_skb net/core/skbuff.c:1067 [inline]
skb_attempt_defer_free+0x3bc/0x570 net/core/skbuff.c:6817
tcp_eat_recv_skb net/ipv4/tcp.c:1511 [inline]
tcp_recvmsg_locked+0x10a8/0x24a0 net/ipv4/tcp.c:2522
tcp_recvmsg+0x12e/0x670 net/ipv4/tcp.c:2568
inet_recvmsg+0x114/0x630 net/ipv4/af_inet.c:878
sock_recvmsg_nosec net/socket.c:1044 [inline]
sock_recvmsg+0xe2/0x170 net/socket.c:1066
sock_read_iter+0x2c3/0x3c0 net/socket.c:1136
call_read_iter include/linux/fs.h:1950 [inline]
new_sync_read fs/read_write.c:389 [inline]
vfs_read+0x7ef/0x930 fs/read_write.c:470
ksys_read+0x1f0/0x250 fs/read_write.c:613
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:
ffff88807db5a700: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff88807db5a780: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff88807db5a800: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88807db5a880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88807db5a900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================


Tested on:

commit: 2af9b20d Merge tag 'x86-urgent-2023-10-28' of git://gi..
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=11260fd7680000
kernel config: https://syzkaller.appspot.com/x/.config?x=cb98fe061049a6e4
dashboard link: https://syzkaller.appspot.com/bug?extid=d31adfb277377ef8fcba
compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=14cde6bb680000

Lizhi Xu

unread,
Nov 3, 2023, 1:36:46 AM11/3/23
to syzbot+d31adf...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c
index e71523cbd0de..e89c90784536 100644
--- a/drivers/iommu/iommufd/main.c
+++ b/drivers/iommu/iommufd/main.c
@@ -159,7 +159,8 @@ static struct iommufd_object *iommufd_object_remove(struct iommufd_ctx *ictx,
}

xas_store(&xas, NULL);
- if (ictx->vfio_ioas == container_of(obj, struct iommufd_ioas, obj))
+ __xa_erase(&ictx->objects, obj->id);
+ if (ictx->vfio_ioas && &ictx->vfio_ioas->obj == obj)
ictx->vfio_ioas = NULL;

out_xa:

syzbot

unread,
Nov 3, 2023, 1:52:04 AM11/3/23
to linux-...@vger.kernel.org, lizh...@windriver.com, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
KASAN: slab-use-after-free Read in iommufd_vfio_ioas

==================================================================
BUG: KASAN: slab-use-after-free in __up_read+0x627/0x750 kernel/locking/rwsem.c:1342
Read of size 8 at addr ffff88801c36c868 by task syz-executor.3/6257

CPU: 1 PID: 6257 Comm: syz-executor.3 Not tainted 6.6.0-rc7-syzkaller-00195-g2af9b20dbb39-dirty #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:399
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:0x7f8704c7cae9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 e1 20 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:00007f870596e0c8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007f8704d9c050 RCX: 00007f8704c7cae9
RDX: 0000000020000080 RSI: 0000000000003b88 RDI: 0000000000000003
RBP: 00007f8704cc847a R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 000000000000000b R14: 00007f8704d9c050 R15: 00007ffcfcbdc3a8
</TASK>

Allocated by task 6255:
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:399
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 6260:
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:217
iommufd_fops_ioctl+0x347/0x4d0 drivers/iommu/iommufd/main.c:399
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

Last potentially related work creation:
kasan_save_stack+0x33/0x50 mm/kasan/common.c:45
__kasan_record_aux_stack+0x78/0x80 mm/kasan/generic.c:492
kvfree_call_rcu+0x70/0xbe0 kernel/rcu/tree.c:3372
drop_sysctl_table+0x1d4/0x3b0 fs/proc/proc_sysctl.c:1508
unregister_sysctl_table fs/proc/proc_sysctl.c:1529 [inline]
unregister_sysctl_table+0x41/0x60 fs/proc/proc_sysctl.c:1521
neigh_sysctl_unregister+0x5f/0x80 net/core/neighbour.c:3873
devinet_sysctl_unregister net/ipv4/devinet.c:2659 [inline]
inetdev_event+0xedc/0x1900 net/ipv4/devinet.c:1631
notifier_call_chain+0xb6/0x3b0 kernel/notifier.c:93
call_netdevice_notifiers_info+0xb9/0x130 net/core/dev.c:1995
call_netdevice_notifiers_extack net/core/dev.c:2033 [inline]
call_netdevice_notifiers net/core/dev.c:2047 [inline]
dev_change_name+0x495/0x7c0 net/core/dev.c:1269
do_setlink+0x2f99/0x3fa0 net/core/rtnetlink.c:2853
__rtnl_newlink+0xc1d/0x1940 net/core/rtnetlink.c:3671
rtnl_newlink+0x67/0xa0 net/core/rtnetlink.c:3718
rtnetlink_rcv_msg+0x3c4/0xdf0 net/core/rtnetlink.c:6442
netlink_rcv_skb+0x16b/0x440 net/netlink/af_netlink.c:2545
netlink_unicast_kernel net/netlink/af_netlink.c:1342 [inline]
netlink_unicast+0x536/0x810 net/netlink/af_netlink.c:1368
netlink_sendmsg+0x93c/0xe40 net/netlink/af_netlink.c:1910
sock_sendmsg_nosec net/socket.c:730 [inline]
__sock_sendmsg+0xd5/0x180 net/socket.c:745
__sys_sendto+0x255/0x340 net/socket.c:2194
__do_sys_sendto net/socket.c:2206 [inline]
__se_sys_sendto net/socket.c:2202 [inline]
__x64_sys_sendto+0xe0/0x1b0 net/socket.c:2202
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 ffff88801c36c800
which belongs to the cache kmalloc-cg-1k of size 1024
The buggy address is located 104 bytes inside of
freed 1024-byte region [ffff88801c36c800, ffff88801c36cc00)

The buggy address belongs to the physical page:
page:ffffea000070db00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1c36c
memcg:ffff88801770ad81
flags: 0xfff00000000800(slab|node=0|zone=1|lastcpupid=0x7ff)
page_type: 0x2()
raw: 00fff00000000800 ffff888012c4d800 ffffea0001f77e50 ffffea00007fbfd0
raw: 0000000000000000 ffff88801c36c000 0000000100000002 ffff88801770ad81
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0x2c20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_COMP|__GFP_NOMEMALLOC|__GFP_THISNODE), pid 4694, tgid 4694 (dhcpcd), ts 56107701927, free_ts 46839953379
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_node_track_caller+0x50/0x100 mm/slab_common.c:1046
kmalloc_reserve+0xef/0x260 net/core/skbuff.c:581
__alloc_skb+0x12b/0x330 net/core/skbuff.c:650
alloc_skb include/linux/skbuff.h:1286 [inline]
alloc_skb_with_frags+0xe4/0x710 net/core/skbuff.c:6313
sock_alloc_send_pskb+0x7e4/0x970 net/core/sock.c:2795
unix_dgram_sendmsg+0x455/0x1c30 net/unix/af_unix.c:1953
sock_sendmsg_nosec net/socket.c:730 [inline]
__sock_sendmsg+0xd5/0x180 net/socket.c:745
sock_write_iter+0x29b/0x3d0 net/socket.c:1158
call_write_iter include/linux/fs.h:1956 [inline]
do_iter_readv_writev+0x21e/0x3c0 fs/read_write.c:735
do_iter_write+0x17f/0x830 fs/read_write.c:860
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
slab_destroy mm/slab.c:1608 [inline]
slabs_destroy+0x85/0xc0 mm/slab.c:1628
cache_flusharray mm/slab.c:3341 [inline]
___cache_free+0x2b7/0x420 mm/slab.c:3404
qlink_free mm/kasan/quarantine.c:166 [inline]
qlist_free_all+0x4c/0x1b0 mm/kasan/quarantine.c:185
kasan_quarantine_reduce+0x18e/0x1d0 mm/kasan/quarantine.c:292
__kasan_slab_alloc+0x65/0x90 mm/kasan/common.c:305
kasan_slab_alloc include/linux/kasan.h:188 [inline]
slab_post_alloc_hook mm/slab.h:762 [inline]
slab_alloc_node mm/slab.c:3237 [inline]
slab_alloc mm/slab.c:3246 [inline]
__kmem_cache_alloc_lru mm/slab.c:3423 [inline]
kmem_cache_alloc+0x159/0x400 mm/slab.c:3432
getname_flags.part.0+0x50/0x4e0 fs/namei.c:140
getname_flags include/linux/audit.h:321 [inline]
getname+0x90/0xe0 fs/namei.c:219
do_sys_openat2+0x100/0x1e0 fs/open.c:1416
do_sys_open fs/open.c:1437 [inline]
__do_sys_openat fs/open.c:1453 [inline]
__se_sys_openat fs/open.c:1448 [inline]
__x64_sys_openat+0x175/0x210 fs/open.c:1448
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:
ffff88801c36c700: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff88801c36c780: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff88801c36c800: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88801c36c880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88801c36c900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================


Tested on:

commit: 2af9b20d Merge tag 'x86-urgent-2023-10-28' of git://gi..
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
console output: https://syzkaller.appspot.com/x/log.txt?x=15522940e80000
kernel config: https://syzkaller.appspot.com/x/.config?x=cb98fe061049a6e4
dashboard link: https://syzkaller.appspot.com/bug?extid=d31adfb277377ef8fcba
compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=17d652f3680000

Lizhi Xu

unread,
Nov 3, 2023, 3:09:44 AM11/3/23
to syzbot+d31adf...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2af9b20dbb39

diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c
index e71523cbd0de..6b75f9fab6ce 100644
--- a/drivers/iommu/iommufd/main.c
+++ b/drivers/iommu/iommufd/main.c
@@ -208,11 +208,14 @@ static int iommufd_destroy(struct iommufd_ucmd *ucmd)
{
struct iommu_destroy *cmd = ucmd->cmd;
struct iommufd_object *obj;
+ struct iommufd_ioas *ioas;

obj = iommufd_object_remove(ucmd->ictx, cmd->id, false);
if (IS_ERR(obj))
return PTR_ERR(obj);
iommufd_object_ops[obj->type].destroy(obj);
+ ioas = container_of(obj, struct iommufd_ioas, obj);
+ ioas->obj = NULL;
kfree(obj);
return 0;
}
diff --git a/drivers/iommu/iommufd/vfio_compat.c b/drivers/iommu/iommufd/vfio_compat.c
index 6c810bf80f99..06317d0bd95e 100644
--- a/drivers/iommu/iommufd/vfio_compat.c
+++ b/drivers/iommu/iommufd/vfio_compat.c
@@ -140,6 +140,8 @@ int iommufd_vfio_ioas(struct iommufd_ucmd *ucmd)
ioas = iommufd_get_ioas(ucmd->ictx, cmd->ioas_id);
if (IS_ERR(ioas))
return PTR_ERR(ioas);
+ if (!ioas->obj)
+ return -EINVAL;
xa_lock(&ucmd->ictx->objects);
ucmd->ictx->vfio_ioas = ioas;
xa_unlock(&ucmd->ictx->objects);

syzbot

unread,
Nov 3, 2023, 3:16:05 AM11/3/23
to linux-...@vger.kernel.org, lizh...@windriver.com, syzkall...@googlegroups.com
Hello,

syzbot tried to test the proposed patch but the build/boot failed:

./include/linux/stddef.h:8:14: error: incompatible types when assigning to type 'struct iommufd_object' from type 'void *'


Tested on:

commit: 2af9b20d Merge tag 'x86-urgent-2023-10-28' of git://gi..
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel config: https://syzkaller.appspot.com/x/.config?x=cb98fe061049a6e4
dashboard link: https://syzkaller.appspot.com/bug?extid=d31adfb277377ef8fcba
compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=13c8c53d680000

Lizhi Xu

unread,
Nov 3, 2023, 3:58:06 AM11/3/23
to syzbot+d31adf...@syzkaller.appspotmail.com, syzkall...@googlegroups.com
#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2af9b20dbb39

diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c
index e71523cbd0de..8d2dba522baf 100644
--- a/drivers/iommu/iommufd/main.c
+++ b/drivers/iommu/iommufd/main.c
@@ -137,6 +137,7 @@ static struct iommufd_object *iommufd_object_remove(struct iommufd_ctx *ictx,
u32 id, bool extra_put)
{
struct iommufd_object *obj;
+ struct iommufd_ioas *ioas;
XA_STATE(xas, &ictx->objects, id);

xa_lock(&ictx->objects);
@@ -159,7 +160,9 @@ static struct iommufd_object *iommufd_object_remove(struct iommufd_ctx *ictx,
}

xas_store(&xas, NULL);
- if (ictx->vfio_ioas == container_of(obj, struct iommufd_ioas, obj))
+ ioas = container_of(obj, struct iommufd_ioas, obj);
+ ioas->obj = NULL;
+ if (ictx->vfio_ioas == ioas)
ictx->vfio_ioas = NULL;

out_xa:

syzbot

unread,
Nov 3, 2023, 4:08:05 AM11/3/23
to linux-...@vger.kernel.org, lizh...@windriver.com, syzkall...@googlegroups.com

Hillf Danton

unread,
Nov 3, 2023, 7:45:37 AM11/3/23
to syzbot, linux-...@vger.kernel.org, syzkall...@googlegroups.com
On Thu, 02 Nov 2023 16:03:28 -0700
> HEAD commit: 2af9b20dbb39 Merge tag 'x86-urgent-2023-10-28' of git://gi..
> git tree: upstream
> C reproducer: https://syzkaller.appspot.com/x/repro.c?x=1330c151680000

#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master

--- x/drivers/iommu/iommufd/iommufd_private.h
+++ y/drivers/iommu/iommufd/iommufd_private.h
@@ -156,8 +156,8 @@ struct iommufd_object *iommufd_get_objec
enum iommufd_object_type type);
static inline void iommufd_put_object(struct iommufd_object *obj)
{
- refcount_dec(&obj->users);
up_read(&obj->destroy_rwsem);
+ refcount_dec(&obj->users);
}

void iommufd_object_abort(struct iommufd_ctx *ictx, struct iommufd_object *obj);
--

syzbot

unread,
Nov 3, 2023, 8:15:07 AM11/3/23
to hda...@sina.com, linux-...@vger.kernel.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch and the reproducer did not trigger any issue:

Reported-and-tested-by: syzbot+d31adf...@syzkaller.appspotmail.com

Tested on:

commit: 8f6f76a6 Merge tag 'mm-nonmm-stable-2023-11-02-14-08' ..
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
console output: https://syzkaller.appspot.com/x/log.txt?x=166db0eb680000
kernel config: https://syzkaller.appspot.com/x/.config?x=4c856b92a9ee7d89
dashboard link: https://syzkaller.appspot.com/bug?extid=d31adfb277377ef8fcba
compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
patch: https://syzkaller.appspot.com/x/patch.diff?x=138b353d680000

Note: testing is done by a robot and is best-effort only.
Reply all
Reply to author
Forward
0 new messages