syzbot


KASAN: use-after-free Read in selinux_socket_recvmsg

Status: auto-obsoleted due to no activity on 2022/11/12 06:45
Reported-by: syzbot+04b20e641c99a5d99ac2@syzkaller.appspotmail.com
First crash: 152d, last: 136d

Sample crash report:
==================================================================
BUG: KASAN: use-after-free in sock_has_perm security/selinux/hooks.c:4535 [inline]
BUG: KASAN: use-after-free in selinux_socket_recvmsg+0x278/0x2b0 security/selinux/hooks.c:4899
Read of size 8 at addr ffff888085bb8480 by task syz-executor.4/13827

CPU: 1 PID: 13827 Comm: syz-executor.4 Not tainted 5.19.0-rc6-syzkaller-00269-g9bd572ec7a66 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 06/29/2022
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
 print_address_description.constprop.0.cold+0xeb/0x467 mm/kasan/report.c:313
 print_report mm/kasan/report.c:429 [inline]
 kasan_report.cold+0xf4/0x1c6 mm/kasan/report.c:491
 sock_has_perm security/selinux/hooks.c:4535 [inline]
 selinux_socket_recvmsg+0x278/0x2b0 security/selinux/hooks.c:4899
 security_socket_recvmsg+0x5c/0xc0 security/security.c:2223
 sock_recvmsg net/socket.c:1011 [inline]
 ____sys_recvmsg+0x23b/0x600 net/socket.c:2707
 ___sys_recvmsg+0x127/0x200 net/socket.c:2749
 do_recvmmsg+0x254/0x6d0 net/socket.c:2843
 __sys_recvmmsg net/socket.c:2922 [inline]
 __do_sys_recvmmsg net/socket.c:2945 [inline]
 __se_sys_recvmmsg net/socket.c:2938 [inline]
 __x64_sys_recvmmsg+0x20b/0x260 net/socket.c:2938
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7fb6d7489109
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 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007fb6d8560168 EFLAGS: 00000246 ORIG_RAX: 000000000000012b
RAX: ffffffffffffffda RBX: 00007fb6d759c100 RCX: 00007fb6d7489109
RDX: 0000000000000003 RSI: 0000000020000540 RDI: 0000000000000004
RBP: 00007fb6d74e30ed R08: 0000000000000000 R09: 0000000000000000
R10: 0000000040012062 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffc1967d6ef R14: 00007fb6d8560300 R15: 0000000000022000
 </TASK>

Allocated by task 13803:
 kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
 kasan_set_track mm/kasan/common.c:45 [inline]
 set_alloc_info mm/kasan/common.c:436 [inline]
 ____kasan_kmalloc mm/kasan/common.c:515 [inline]
 ____kasan_kmalloc mm/kasan/common.c:474 [inline]
 __kasan_kmalloc+0xa6/0xd0 mm/kasan/common.c:524
 kasan_kmalloc include/linux/kasan.h:234 [inline]
 __do_kmalloc mm/slab.c:3696 [inline]
 __kmalloc+0x209/0x4d0 mm/slab.c:3705
 kmalloc include/linux/slab.h:605 [inline]
 sk_prot_alloc+0x110/0x290 net/core/sock.c:1975
 sk_alloc+0x36/0x770 net/core/sock.c:2028
 nr_create+0xb2/0x5f0 net/netrom/af_netrom.c:433
 __sock_create+0x353/0x790 net/socket.c:1515
 sock_create net/socket.c:1566 [inline]
 __sys_socket_create net/socket.c:1603 [inline]
 __sys_socket_create net/socket.c:1588 [inline]
 __sys_socket+0x12f/0x240 net/socket.c:1636
 __do_sys_socket net/socket.c:1649 [inline]
 __se_sys_socket net/socket.c:1647 [inline]
 __x64_sys_socket+0x6f/0xb0 net/socket.c:1647
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

Freed by task 21:
 kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
 kasan_set_track+0x21/0x30 mm/kasan/common.c:45
 kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:370
 ____kasan_slab_free mm/kasan/common.c:366 [inline]
 ____kasan_slab_free+0x13d/0x180 mm/kasan/common.c:328
 kasan_slab_free include/linux/kasan.h:200 [inline]
 __cache_free mm/slab.c:3425 [inline]
 kfree+0x113/0x310 mm/slab.c:3796
 sk_prot_free net/core/sock.c:2011 [inline]
 __sk_destruct+0x5e5/0x710 net/core/sock.c:2097
 sk_destruct net/core/sock.c:2112 [inline]
 __sk_free+0x1a4/0x4a0 net/core/sock.c:2123
 sk_free+0x78/0xa0 net/core/sock.c:2134
 sock_put include/net/sock.h:1927 [inline]
 nr_heartbeat_expiry+0x2de/0x460 net/netrom/nr_timer.c:148
 call_timer_fn+0x1a5/0x6b0 kernel/time/timer.c:1474
 expire_timers kernel/time/timer.c:1519 [inline]
 __run_timers.part.0+0x679/0xa80 kernel/time/timer.c:1790
 __run_timers kernel/time/timer.c:1768 [inline]
 run_timer_softirq+0xb3/0x1d0 kernel/time/timer.c:1803
 __do_softirq+0x29b/0x9c2 kernel/softirq.c:571

Last potentially related work creation:
 kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
 __kasan_record_aux_stack+0x7e/0x90 mm/kasan/generic.c:348
 call_rcu+0x99/0x790 kernel/rcu/tree.c:3126
 netlink_release+0xf08/0x1db0 net/netlink/af_netlink.c:815
 __sock_release net/socket.c:650 [inline]
 sock_release+0x87/0x1b0 net/socket.c:678
 netlink_kernel_release+0x4b/0x60 net/netlink/af_netlink.c:2107
 nfnetlink_net_exit_batch+0x10e/0x320 net/netfilter/nfnetlink.c:722
 ops_exit_list+0x125/0x170 net/core/net_namespace.c:167
 cleanup_net+0x4ea/0xb00 net/core/net_namespace.c:594
 process_one_work+0x996/0x1610 kernel/workqueue.c:2289
 worker_thread+0x665/0x1080 kernel/workqueue.c:2436
 kthread+0x2e9/0x3a0 kernel/kthread.c:376
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306

Second to last potentially related work creation:
 kasan_save_stack+0x1e/0x40 mm/kasan/common.c:38
 __kasan_record_aux_stack+0x7e/0x90 mm/kasan/generic.c:348
 insert_work+0x48/0x350 kernel/workqueue.c:1358
 __queue_work+0x62f/0x1150 kernel/workqueue.c:1517
 queue_work_on+0xee/0x110 kernel/workqueue.c:1545
 queue_work include/linux/workqueue.h:502 [inline]
 afs_queue_server_manager fs/afs/server.c:603 [inline]
 afs_purge_servers+0xea/0x340 fs/afs/server.c:617
 afs_net_exit+0x16d/0x320 fs/afs/main.c:157
 ops_exit_list+0xb0/0x170 net/core/net_namespace.c:162
 cleanup_net+0x4ea/0xb00 net/core/net_namespace.c:594
 process_one_work+0x996/0x1610 kernel/workqueue.c:2289
 worker_thread+0x665/0x1080 kernel/workqueue.c:2436
 kthread+0x2e9/0x3a0 kernel/kthread.c:376
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:306

The buggy address belongs to the object at ffff888085bb8000
 which belongs to the cache kmalloc-2k of size 2048
The buggy address is located 1152 bytes inside of
 2048-byte region [ffff888085bb8000, ffff888085bb8800)

The buggy address belongs to the physical page:
page:ffffea000216ee00 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x85bb8
flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 ffffea00023fc348 ffffea0000e47288 ffff888011840800
raw: 0000000000000000 ffff888085bb8000 0000000100000001 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 0x3420c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_COMP|__GFP_HARDWALL|__GFP_THISNODE), pid 8901, tgid 8900 (syz-executor.4), ts 1952157150220, free_ts 1952068298326
 prep_new_page mm/page_alloc.c:2456 [inline]
 get_page_from_freelist+0x1290/0x3b70 mm/page_alloc.c:4198
 __alloc_pages+0x1c7/0x510 mm/page_alloc.c:5426
 __alloc_pages_node include/linux/gfp.h:587 [inline]
 kmem_getpages mm/slab.c:1363 [inline]
 cache_grow_begin+0x75/0x350 mm/slab.c:2569
 cache_alloc_refill+0x27f/0x380 mm/slab.c:2942
 ____cache_alloc mm/slab.c:3024 [inline]
 ____cache_alloc mm/slab.c:3007 [inline]
 __do_cache_alloc mm/slab.c:3253 [inline]
 slab_alloc mm/slab.c:3295 [inline]
 kmem_cache_alloc_trace+0x380/0x4a0 mm/slab.c:3567
 kmalloc include/linux/slab.h:600 [inline]
 kzalloc include/linux/slab.h:733 [inline]
 fib6_net_init net/ipv6/ip6_fib.c:2376 [inline]
 fib6_net_init+0x1d7/0xa20 net/ipv6/ip6_fib.c:2351
 ops_init+0xaf/0x470 net/core/net_namespace.c:134
 setup_net+0x5d1/0xc50 net/core/net_namespace.c:325
 copy_net_ns+0x318/0x760 net/core/net_namespace.c:471
 create_new_namespaces+0x3f6/0xb20 kernel/nsproxy.c:110
 unshare_nsproxy_namespaces+0xc1/0x1f0 kernel/nsproxy.c:226
 ksys_unshare+0x445/0x920 kernel/fork.c:3165
 __do_sys_unshare kernel/fork.c:3236 [inline]
 __se_sys_unshare kernel/fork.c:3234 [inline]
 __x64_sys_unshare+0x2d/0x40 kernel/fork.c:3234
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x35/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:1371 [inline]
 free_pcp_prepare+0x549/0xd20 mm/page_alloc.c:1421
 free_unref_page_prepare mm/page_alloc.c:3343 [inline]
 free_unref_page+0x19/0x6a0 mm/page_alloc.c:3438
 slab_destroy mm/slab.c:1615 [inline]
 slabs_destroy+0x89/0xc0 mm/slab.c:1635
 cache_flusharray mm/slab.c:3397 [inline]
 ___cache_free+0x34e/0x670 mm/slab.c:3460
 qlink_free mm/kasan/quarantine.c:168 [inline]
 qlist_free_all+0x4f/0x1b0 mm/kasan/quarantine.c:187
 kasan_quarantine_reduce+0x180/0x200 mm/kasan/quarantine.c:294
 __kasan_slab_alloc+0x97/0xb0 mm/kasan/common.c:446
 kasan_slab_alloc include/linux/kasan.h:224 [inline]
 slab_post_alloc_hook mm/slab.h:750 [inline]
 slab_alloc_node mm/slab.c:3239 [inline]
 kmem_cache_alloc_node+0x2ea/0x590 mm/slab.c:3593
 __alloc_skb+0x215/0x340 net/core/skbuff.c:414
 alloc_skb_fclone include/linux/skbuff.h:1476 [inline]
 tcp_stream_alloc_skb+0x66/0x900 net/ipv4/tcp.c:862
 tcp_sendmsg_locked+0xad1/0x2fd0 net/ipv4/tcp.c:1297
 tcp_sendmsg+0x2b/0x40 net/ipv4/tcp.c:1448
 inet_sendmsg+0x99/0xe0 net/ipv4/af_inet.c:819
 sock_sendmsg_nosec net/socket.c:714 [inline]
 sock_sendmsg+0xcf/0x120 net/socket.c:734
 sock_write_iter+0x284/0x3c0 net/socket.c:1108
 call_write_iter include/linux/fs.h:2058 [inline]
 new_sync_write+0x38a/0x560 fs/read_write.c:504

Memory state around the buggy address:
 ffff888085bb8380: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888085bb8400: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888085bb8480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                   ^
 ffff888085bb8500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888085bb8580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (2):
Manager Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Title
ci-upstream-kasan-gce-selinux-root 2022/07/15 06:44 upstream 9bd572ec7a66 5d921b08 .config log report info KASAN: use-after-free Read in selinux_socket_recvmsg
ci-upstream-kasan-gce-selinux-root 2022/06/28 22:56 upstream 941e3e791269 496a8536 .config log report info KASAN: use-after-free Read in selinux_socket_recvmsg
* Struck through repros no longer work on HEAD.