syzbot


KASAN: use-after-free Read in selinux_inode_permission

Status: upstream: reported syz repro on 2021/08/12 20:11
Reported-by: syzbot+76edb7559416d46c4cb3@syzkaller.appspotmail.com
First crash: 534d, last: 534d

Sample crash report:
BUG: KASAN: use-after-free in selinux_inode_permission+0x599/0x690 security/selinux/hooks.c:3132
Read of size 4 at addr ffff8881e9d8b824 by task syz-executor.2/3053

CPU: 1 PID: 3053 Comm: syz-executor.2 Not tainted 5.4.125-syzkaller-00007-g299ecc4fc137 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0x1d8/0x24e lib/dump_stack.c:118
 print_address_description+0x9b/0x650 mm/kasan/report.c:384
 __kasan_report+0x182/0x260 mm/kasan/report.c:516
 kasan_report+0x30/0x60 mm/kasan/common.c:653
 selinux_inode_permission+0x599/0x690 security/selinux/hooks.c:3132
 security_inode_permission+0x92/0x110 security/security.c:1210
 may_lookup fs/namei.c:1773 [inline]
 link_path_walk+0x204/0x14b0 fs/namei.c:2159
 path_openat+0x1bb/0x3da0 fs/namei.c:3611
 do_filp_open+0x208/0x450 fs/namei.c:3642
 do_sys_open+0x383/0x7c0 fs/open.c:1113
 do_syscall_64+0xcb/0x1e0 arch/x86/entry/common.c:290
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x4665e9
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 bc ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f21b7ead188 EFLAGS: 00000246 ORIG_RAX: 0000000000000101
RAX: ffffffffffffffda RBX: 000000000056c038 RCX: 00000000004665e9
RDX: 0000000000000000 RSI: 0000000020000080 RDI: 0000000000000003
RBP: 00000000004bfcc4 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 000000000056c038
R13: 00007ffc1131010f R14: 00007f21b7ead300 R15: 0000000000022000

Allocated by task 3053:
 save_stack mm/kasan/common.c:70 [inline]
 set_track mm/kasan/common.c:78 [inline]
 __kasan_kmalloc+0x137/0x1e0 mm/kasan/common.c:529
 kmem_cache_alloc_trace+0x139/0x2b0 mm/slub.c:2848
 kmalloc include/linux/slab.h:556 [inline]
 kzalloc include/linux/slab.h:690 [inline]
 alloc_inode+0x43/0x70 fs/incfs/vfs.c:1544
 alloc_inode fs/inode.c:232 [inline]
 iget5_locked+0x9e/0x3c0 fs/inode.c:1148
 fetch_regular_inode+0x22f/0x300 fs/incfs/vfs.c:376
 incfs_mount_fs+0x4e7/0x840 fs/incfs/vfs.c:1819
 legacy_get_tree+0xde/0x170 fs/fs_context.c:647
 vfs_get_tree+0x83/0x260 fs/super.c:1547
 do_new_mount fs/namespace.c:2825 [inline]
 do_mount+0x19d0/0x2670 fs/namespace.c:3145
 ksys_mount+0xc2/0xf0 fs/namespace.c:3354
 __do_sys_mount fs/namespace.c:3368 [inline]
 __se_sys_mount fs/namespace.c:3365 [inline]
 __x64_sys_mount+0xb1/0xc0 fs/namespace.c:3365
 do_syscall_64+0xcb/0x1e0 arch/x86/entry/common.c:290
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

Freed by task 3034:
 save_stack mm/kasan/common.c:70 [inline]
 set_track mm/kasan/common.c:78 [inline]
 kasan_set_free_info mm/kasan/common.c:345 [inline]
 __kasan_slab_free+0x18a/0x240 mm/kasan/common.c:487
 slab_free_hook mm/slub.c:1454 [inline]
 slab_free_freelist_hook+0x7b/0x150 mm/slub.c:1492
 slab_free mm/slub.c:3072 [inline]
 kfree+0xe0/0x660 mm/slub.c:4061
 destroy_inode fs/inode.c:282 [inline]
 evict+0x59b/0x6a0 fs/inode.c:593
 dispose_list fs/inode.c:611 [inline]
 evict_inodes+0x608/0x690 fs/inode.c:661
 generic_shutdown_super+0x8f/0x2a0 fs/super.c:454
 incfs_kill_sb+0x3d/0x50 fs/incfs/vfs.c:1881
 deactivate_locked_super+0xaf/0x100 fs/super.c:335
 deactivate_super+0x1b3/0x270 fs/super.c:366
 cleanup_mnt+0x432/0x4e0 fs/namespace.c:1102
 task_work_run+0x186/0x1b0 kernel/task_work.c:113
 tracehook_notify_resume include/linux/tracehook.h:188 [inline]
 exit_to_usermode_loop arch/x86/entry/common.c:163 [inline]
 prepare_exit_to_usermode+0x2b0/0x310 arch/x86/entry/common.c:194
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

The buggy address belongs to the object at ffff8881e9d8b800
 which belongs to the cache kmalloc-1k of size 1024
The buggy address is located 36 bytes inside of
 1024-byte region [ffff8881e9d8b800, ffff8881e9d8bc00)
The buggy address belongs to the page:
page:ffffea0007a76200 refcount:1 mapcount:0 mapping:ffff8881f5c02280 index:0x0 compound_mapcount: 0
flags: 0x8000000000010200(slab|head)
raw: 8000000000010200 ffffea0007945800 0000000200000002 ffff8881f5c02280
raw: 0000000000000000 0000000080100010 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Unmovable, gfp_mask 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC)
 set_page_owner include/linux/page_owner.h:31 [inline]
 post_alloc_hook mm/page_alloc.c:2165 [inline]
 prep_new_page+0x19a/0x380 mm/page_alloc.c:2171
 get_page_from_freelist+0x550/0x8b0 mm/page_alloc.c:3794
 __alloc_pages_nodemask+0x3a2/0x880 mm/page_alloc.c:4855
 alloc_slab_page+0x39/0x3e0 mm/slub.c:342
 allocate_slab mm/slub.c:1675 [inline]
 new_slab+0x97/0x460 mm/slub.c:1741
 new_slab_objects mm/slub.c:2498 [inline]
 ___slab_alloc+0x330/0x4c0 mm/slub.c:2659
 __slab_alloc mm/slub.c:2699 [inline]
 slab_alloc_node mm/slub.c:2784 [inline]
 slab_alloc mm/slub.c:2829 [inline]
 __kmalloc_track_caller+0x1d1/0x2e0 mm/slub.c:4439
 __kmalloc_reserve net/core/skbuff.c:142 [inline]
 __alloc_skb+0xaf/0x4d0 net/core/skbuff.c:210
 alloc_skb include/linux/skbuff.h:1060 [inline]
 netlink_alloc_large_skb net/netlink/af_netlink.c:1175 [inline]
 netlink_sendmsg+0x748/0xd40 net/netlink/af_netlink.c:1893
 sock_sendmsg_nosec net/socket.c:638 [inline]
 sock_sendmsg net/socket.c:658 [inline]
 ____sys_sendmsg+0x583/0x8c0 net/socket.c:2298
 ___sys_sendmsg net/socket.c:2352 [inline]
 __sys_sendmsg+0x2c4/0x3b0 net/socket.c:2398
 do_syscall_64+0xcb/0x1e0 arch/x86/entry/common.c:290
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1176 [inline]
 __free_pages_ok+0xc60/0xd80 mm/page_alloc.c:1438
 free_the_page mm/page_alloc.c:4917 [inline]
 __free_pages+0x8f/0x250 mm/page_alloc.c:4923
 __free_slab+0x237/0x2f0 mm/slub.c:1766
 free_slab mm/slub.c:1781 [inline]
 discard_slab mm/slub.c:1787 [inline]
 unfreeze_partials+0x14f/0x180 mm/slub.c:2279
 put_cpu_partial+0xb5/0x150 mm/slub.c:2315
 __slab_free mm/slub.c:2963 [inline]
 do_slab_free mm/slub.c:3060 [inline]
 ___cache_free+0x352/0x4e0 mm/slub.c:3079
 qlist_free_all mm/kasan/quarantine.c:167 [inline]
 quarantine_reduce+0x17a/0x1e0 mm/kasan/quarantine.c:260
 __kasan_kmalloc+0x43/0x1e0 mm/kasan/common.c:507
 slab_post_alloc_hook mm/slab.h:584 [inline]
 slab_alloc_node mm/slub.c:2821 [inline]
 slab_alloc mm/slub.c:2829 [inline]
 kmem_cache_alloc+0x115/0x290 mm/slub.c:2834
 getname_flags+0xba/0x640 fs/namei.c:141
 user_path_at_empty+0x28/0x50 fs/namei.c:2683
 user_path_at include/linux/namei.h:49 [inline]
 vfs_statx fs/stat.c:187 [inline]
 vfs_lstat include/linux/fs.h:3361 [inline]
 __do_sys_newlstat fs/stat.c:354 [inline]
 __se_sys_newlstat+0xde/0x860 fs/stat.c:348
 do_syscall_64+0xcb/0x1e0 arch/x86/entry/common.c:290
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

Memory state around the buggy address:
 ffff8881e9d8b700: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff8881e9d8b780: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff8881e9d8b800: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                               ^
 ffff8881e9d8b880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff8881e9d8b900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
----------------
Code disassembly (best guess), 1 bytes skipped:
   0:	ff c3                	inc    %ebx
   2:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
   9:	00 00 00 
   c:	0f 1f 40 00          	nopl   0x0(%rax)
  10:	48 89 f8             	mov    %rdi,%rax
  13:	48 89 f7             	mov    %rsi,%rdi
  16:	48 89 d6             	mov    %rdx,%rsi
  19:	48 89 ca             	mov    %rcx,%rdx
  1c:	4d 89 c2             	mov    %r8,%r10
  1f:	4d 89 c8             	mov    %r9,%r8
  22:	4c 8b 4c 24 08       	mov    0x8(%rsp),%r9
  27:	0f 05                	syscall 
  29:	48 3d 01 f0 ff ff    	cmp    $0xfffffffffffff001,%rax <-- trapping instruction
  2f:	73 01                	jae    0x32
  31:	c3                   	retq   
  32:	48 c7 c1 bc ff ff ff 	mov    $0xffffffffffffffbc,%rcx
  39:	f7 d8                	neg    %eax
  3b:	64 89 01             	mov    %eax,%fs:(%rcx)
  3e:	48                   	rex.W

Crashes (1):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets Title
ci2-android-5-4-kasan 2021/08/12 20:10 android12-5.4 299ecc4fc137 c551a195 .config console log report syz KASAN: use-after-free Read in selinux_inode_permission
* Struck through repros no longer work on HEAD.