[2023-11-24 18:46] Greg Kroah-Hartman:
6.6-stable review patch. If anyone has any objections, please let me know.
From: Eric Dumazet edumazet@google.com
[ Upstream commit 4b7b492615cf3017190f55444f7016812b66611d ]
syzbot reported the following crash [1]
After releasing unix socket lock, u->oob_skb can be changed by another thread. We must temporarily increase skb refcount to make sure this other thread will not free the skb under us.
[1]
BUG: KASAN: slab-use-after-free in unix_stream_read_actor+0xa7/0xc0 net/unix/af_unix.c:2866 Read of size 4 at addr ffff88801f3b9cc4 by task syz-executor107/5297
CPU: 1 PID: 5297 Comm: syz-executor107 Not tainted 6.6.0-syzkaller-15910-gb8e3a87a627b #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 unix_stream_read_actor+0xa7/0xc0 net/unix/af_unix.c:2866 unix_stream_recv_urg net/unix/af_unix.c:2587 [inline] unix_stream_read_generic+0x19a5/0x2480 net/unix/af_unix.c:2666 unix_stream_recvmsg+0x189/0x1b0 net/unix/af_unix.c:2903 sock_recvmsg_nosec net/socket.c:1044 [inline] sock_recvmsg+0xe2/0x170 net/socket.c:1066 ____sys_recvmsg+0x21f/0x5c0 net/socket.c:2803 ___sys_recvmsg+0x115/0x1a0 net/socket.c:2845 __sys_recvmsg+0x114/0x1e0 net/socket.c:2875 do_syscall_x64 arch/x86/entry/common.c:51 [inline] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82 entry_SYSCALL_64_after_hwframe+0x63/0x6b RIP: 0033:0x7fc67492c559 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:00007fc6748ab228 EFLAGS: 00000246 ORIG_RAX: 000000000000002f RAX: ffffffffffffffda RBX: 000000000000001c RCX: 00007fc67492c559 RDX: 0000000040010083 RSI: 0000000020000140 RDI: 0000000000000004 RBP: 00007fc6749b6348 R08: 00007fc6748ab6c0 R09: 00007fc6748ab6c0 R10: 0000000000000000 R11: 0000000000000246 R12: 00007fc6749b6340 R13: 00007fc6749b634c R14: 00007ffe9fac52a0 R15: 00007ffe9fac5388 </TASK>
Allocated by task 5295: kasan_save_stack+0x33/0x50 mm/kasan/common.c:45 kasan_set_track+0x25/0x30 mm/kasan/common.c:52 __kasan_slab_alloc+0x81/0x90 mm/kasan/common.c:328 kasan_slab_alloc include/linux/kasan.h:188 [inline] slab_post_alloc_hook mm/slab.h:763 [inline] slab_alloc_node mm/slub.c:3478 [inline] kmem_cache_alloc_node+0x180/0x3c0 mm/slub.c:3523 __alloc_skb+0x287/0x330 net/core/skbuff.c:641 alloc_skb include/linux/skbuff.h:1286 [inline] alloc_skb_with_frags+0xe4/0x710 net/core/skbuff.c:6331 sock_alloc_send_pskb+0x7e4/0x970 net/core/sock.c:2780 sock_alloc_send_skb include/net/sock.h:1884 [inline] queue_oob net/unix/af_unix.c:2147 [inline] unix_stream_sendmsg+0xb5f/0x10a0 net/unix/af_unix.c:2301 sock_sendmsg_nosec net/socket.c:730 [inline] __sock_sendmsg+0xd5/0x180 net/socket.c:745 ____sys_sendmsg+0x6ac/0x940 net/socket.c:2584 ___sys_sendmsg+0x135/0x1d0 net/socket.c:2638 __sys_sendmsg+0x117/0x1e0 net/socket.c:2667 do_syscall_x64 arch/x86/entry/common.c:51 [inline] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82 entry_SYSCALL_64_after_hwframe+0x63/0x6b
Freed by task 5295: kasan_save_stack+0x33/0x50 mm/kasan/common.c:45 kasan_set_track+0x25/0x30 mm/kasan/common.c:52 kasan_save_free_info+0x2b/0x40 mm/kasan/generic.c:522 ____kasan_slab_free mm/kasan/common.c:236 [inline] ____kasan_slab_free+0x15b/0x1b0 mm/kasan/common.c:200 kasan_slab_free include/linux/kasan.h:164 [inline] slab_free_hook mm/slub.c:1800 [inline] slab_free_freelist_hook+0x114/0x1e0 mm/slub.c:1826 slab_free mm/slub.c:3809 [inline] kmem_cache_free+0xf8/0x340 mm/slub.c:3831 kfree_skbmem+0xef/0x1b0 net/core/skbuff.c:1015 __kfree_skb net/core/skbuff.c:1073 [inline] consume_skb net/core/skbuff.c:1288 [inline] consume_skb+0xdf/0x170 net/core/skbuff.c:1282 queue_oob net/unix/af_unix.c:2178 [inline] unix_stream_sendmsg+0xd49/0x10a0 net/unix/af_unix.c:2301 sock_sendmsg_nosec net/socket.c:730 [inline] __sock_sendmsg+0xd5/0x180 net/socket.c:745 ____sys_sendmsg+0x6ac/0x940 net/socket.c:2584 ___sys_sendmsg+0x135/0x1d0 net/socket.c:2638 __sys_sendmsg+0x117/0x1e0 net/socket.c:2667 do_syscall_x64 arch/x86/entry/common.c:51 [inline] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82 entry_SYSCALL_64_after_hwframe+0x63/0x6b
The buggy address belongs to the object at ffff88801f3b9c80 which belongs to the cache skbuff_head_cache of size 240 The buggy address is located 68 bytes inside of freed 240-byte region [ffff88801f3b9c80, ffff88801f3b9d70)
The buggy address belongs to the physical page: page:ffffea00007cee40 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1f3b9 flags: 0xfff00000000800(slab|node=0|zone=1|lastcpupid=0x7ff) page_type: 0xffffffff() raw: 00fff00000000800 ffff888142a60640 dead000000000122 0000000000000000 raw: 0000000000000000 00000000000c000c 00000001ffffffff 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 0x12cc0(GFP_KERNEL|__GFP_NOWARN|__GFP_NORETRY), pid 5299, tgid 5283 (syz-executor107), ts 103803840339, free_ts 103600093431 set_page_owner include/linux/page_owner.h:31 [inline] post_alloc_hook+0x2cf/0x340 mm/page_alloc.c:1537 prep_new_page mm/page_alloc.c:1544 [inline] get_page_from_freelist+0xa25/0x36c0 mm/page_alloc.c:3312 __alloc_pages+0x1d0/0x4a0 mm/page_alloc.c:4568 alloc_pages_mpol+0x258/0x5f0 mm/mempolicy.c:2133 alloc_slab_page mm/slub.c:1870 [inline] allocate_slab+0x251/0x380 mm/slub.c:2017 new_slab mm/slub.c:2070 [inline] ___slab_alloc+0x8c7/0x1580 mm/slub.c:3223 __slab_alloc.constprop.0+0x56/0xa0 mm/slub.c:3322 __slab_alloc_node mm/slub.c:3375 [inline] slab_alloc_node mm/slub.c:3468 [inline] kmem_cache_alloc_node+0x132/0x3c0 mm/slub.c:3523 __alloc_skb+0x287/0x330 net/core/skbuff.c:641 alloc_skb include/linux/skbuff.h:1286 [inline] alloc_skb_with_frags+0xe4/0x710 net/core/skbuff.c:6331 sock_alloc_send_pskb+0x7e4/0x970 net/core/sock.c:2780 sock_alloc_send_skb include/net/sock.h:1884 [inline] queue_oob net/unix/af_unix.c:2147 [inline] unix_stream_sendmsg+0xb5f/0x10a0 net/unix/af_unix.c:2301 sock_sendmsg_nosec net/socket.c:730 [inline] __sock_sendmsg+0xd5/0x180 net/socket.c:745 ____sys_sendmsg+0x6ac/0x940 net/socket.c:2584 ___sys_sendmsg+0x135/0x1d0 net/socket.c:2638 __sys_sendmsg+0x117/0x1e0 net/socket.c:2667 page last free stack trace: reset_page_owner include/linux/page_owner.h:24 [inline] free_pages_prepare mm/page_alloc.c:1137 [inline] free_unref_page_prepare+0x4f8/0xa90 mm/page_alloc.c:2347 free_unref_page+0x33/0x3b0 mm/page_alloc.c:2487 __unfreeze_partials+0x21d/0x240 mm/slub.c:2655 qlink_free mm/kasan/quarantine.c:168 [inline] qlist_free_all+0x6a/0x170 mm/kasan/quarantine.c:187 kasan_quarantine_reduce+0x18e/0x1d0 mm/kasan/quarantine.c:294 __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:763 [inline] slab_alloc_node mm/slub.c:3478 [inline] slab_alloc mm/slub.c:3486 [inline] __kmem_cache_alloc_lru mm/slub.c:3493 [inline] kmem_cache_alloc+0x15d/0x380 mm/slub.c:3502 vm_area_dup+0x21/0x2f0 kernel/fork.c:500 __split_vma+0x17d/0x1070 mm/mmap.c:2365 split_vma mm/mmap.c:2437 [inline] vma_modify+0x25d/0x450 mm/mmap.c:2472 vma_modify_flags include/linux/mm.h:3271 [inline] mprotect_fixup+0x228/0xc80 mm/mprotect.c:635 do_mprotect_pkey+0x852/0xd60 mm/mprotect.c:809 __do_sys_mprotect mm/mprotect.c:830 [inline] __se_sys_mprotect mm/mprotect.c:827 [inline] __x64_sys_mprotect+0x78/0xb0 mm/mprotect.c:827 do_syscall_x64 arch/x86/entry/common.c:51 [inline] do_syscall_64+0x3f/0x110 arch/x86/entry/common.c:82 entry_SYSCALL_64_after_hwframe+0x63/0x6b
Memory state around the buggy address: ffff88801f3b9b80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb ffff88801f3b9c00: fb fb fb fb fb fb fc fc fc fc fc fc fc fc fc fc
ffff88801f3b9c80: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^ ffff88801f3b9d00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fc fc ffff88801f3b9d80: fc fc fc fc fc fc fc fc fa fb fb fb fb fb fb fb
Fixes: 876c14ad014d ("af_unix: fix holding spinlock in oob handling") Reported-and-tested-by: syzbot+7a2d546fa43e49315ed3@syzkaller.appspotmail.com Signed-off-by: Eric Dumazet edumazet@google.com Cc: Rao Shoaib rao.shoaib@oracle.com Reviewed-by: Rao shoaib rao.shoaib@oracle.com Link: https://lore.kernel.org/r/20231113134938.168151-1-edumazet@google.com Signed-off-by: Paolo Abeni pabeni@redhat.com Signed-off-by: Sasha Levin sashal@kernel.org
net/unix/af_unix.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 3e8a04a136688..3e6eeacb13aec 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -2553,15 +2553,16 @@ static int unix_stream_recv_urg(struct unix_stream_read_state *state) if (!(state->flags & MSG_PEEK)) WRITE_ONCE(u->oob_skb, NULL);
- else
unix_state_unlock(sk);skb_get(oob_skb);
chunk = state->recv_actor(oob_skb, 0, chunk, state);
- if (!(state->flags & MSG_PEEK)) {
- if (!(state->flags & MSG_PEEK)) UNIXCB(oob_skb).consumed += 1;
kfree_skb(oob_skb);
- }
- consume_skb(oob_skb);
mutex_unlock(&u->iolock);
I'm not 100% sure yet, but it appears that this patch is reproducibly causing crashes at boot time on at least one of my x86_64 VMs. I've attached the kernel config used for building the kernel. The cmdline that I've booted the kernel with is:
root=/dev/vda rootfstype=btrfs rootflags=discard rw console=ttyS0,115200 add_efi_memmap intel_iommu=on lockdown=confidentiality usbcore.nousb debug
"Not 100% sure yet", because I saw the crash first on a heavily patched custom kernel of mine, and noticed that the crash went away when I removed the "af_unix: fix use-after-free in unix_stream_read_actor()" patch. I have now built a "clean" kernel (6.6.2 with all the patches from https://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git/tree... applied on top) that also crashes, but it will take a while until I have compiled such a "clean" kernel without all my custom patches and with only the "af_unix: fix use-after-free in unix_stream_read_actor()" patch removed.
Excerpt from the boot log:
[ 8.715858] systemd-journald[233]: Compressed data object 658 -> 280 using ZSTD Starting Virtual Console Setup... [ 8.837768] systemd-journald[233]: Successfully sent stream file descriptor to service manager. [ OK ] Finished Create Volatile Files and Directories. Starting Record System Boot/Shutdown in UTMP... [ 8.852324] systemd-journald[233]: Successfully sent stream file descriptor to service manager. [ OK ] Finished Record System Boot/Shutdown in UTMP. [ OK ] Finished Virtual Console Setup. [ OK ] Reached target System Initialization. [ OK ] Started Refresh existing PGP keys of archlinux-keyring regularly. [ OK ] Started Daily verification of password and group files. [ OK ] Started Daily Cleanup of Temporary Directories. [ OK ] Reached target Timer Units. [ OK ] Listening on D-Bus System Message Bus Socket. [ OK ] Reached target Socket Units. [ OK ] Reached target Basic System. Starting D-Bus System Message Bus... [ 8.919305] systemd-journald[233]: Successfully sent stream file descriptor to service manager. [ OK ] Started OpenSSH Daemon. Starting User Login Man[ a g 8.925607] general protection fault, probably for non-canonical address 0x968f091e52ae1848: 0000 [#1] PREEMPT SMP PTI [ 8.em9258en98]t systemd-journald[233]: Successfully sent stream file descriptor to service manager. [ 8.927112] CPU: 0 PID: 121 Comm: kworker/0:1H Tainted: G T 6.6.2-0.3-hardened #1 [ 08m..9.. 27115] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS unknown 2/2/2022 [ 8.927116] Workqueue: kblockd blk_mq_run_work_fn [ 8.927122] RIP: 0010:__kmem_cache_alloc_node+0x1c8/0x310 [ 8.927126] Code: 00 0f 85 5a 01 00 00 48 8d 65 d8 5b 41 5c 41 5d 41 5e 41 5f 5d c3 cc cc cc cc 41 8b 47 28 4d 8b 1f 49 89 f8 49 89 d2 48 01 f8 <48> 8b 18 48 89 c1 49 33 9f b8 00 00 00 48 89 f8 48 0f c9 48 31 cb [ 8.939683] RSP: 0018:ffffc9000033fa90 EFLAGS: 00010086 [ Starting Permit User 8.9396S87] eRAX: 968f091e52ae1848 RBX: 0000000000000820 RCX: 0000000000000060 [ 8.939688] RDX: 00000000003b3c00 RSI: 0000000000000820 RDI: 968f091e52ae1818 [ 8.939690] RBP: ffffc9000033fad8 R08: 968f091e52ae1818 R09: ffff888246783e50 [ 8.939691] R10: 0000000ssions003b3c00 R11: 00000000000390c0 R12: 0000000000000820 [ 8.939692] R13: 0000000000000000 R14: 00000000ffffffff R15: ffff888100041600 [ [ 0m.. . 8.939693] FS: 0000000000000000(0000) GS:ffff888763c00000(0000) knlGS:0000000000000000 [ 8.939694] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 8.939696] CR2: 00007f30c16a73e0 CR3: 0000000113cbc004 CR4: 0000000000370ef0 [ 8.939699] Call Trace: [ 8.949689] <TASK> [ 8.949692] ? die_addr+0x36/0x90 [ 8.949697] ? exc_general_protection+0x1c5/0x430 [ 8.949702] ? asm_exc_general_protection+0x26/0x30 [ 8.949707] ? __kmem_cache_alloc_node+0x1c8/0x310 [ 8.949710] ? virtqueue_add_split+0xb1/0x740 [ 8.949714] ? virtqueue_add_split+0xb1/0x740 [ 8.949716] __kmalloc+0x50/0x150 [ 8.949719] virtqueue_add_split+0xb1/0x740 [ 8.949722] virtqueue_add_sgs+0xb6/0xd0 [ 8.949726] virtblk_add_req+0xeb/0x150 [virtio_blk] [ 8.949734] virtio_queue_rq+0x81/0x1c0 [virtio_blk] [ 8.949739] blk_mq_dispatch_rq_list+0x1cc/0x7c0 [ 8.949743] ? preempt_count_add+0x6e/0xa0 [ 8.949745] ? _raw_spin_unlock+0x19/0x40 [ 8.949747] ? blk_mq_flush_busy_ctxs+0x1a0/0x1e0 [ 8.949750] __blk_mq_sched_dispatch_requests+0x219/0x640 [ 8.949752] ? _raw_spin_unlock+0x19/0x40 [ 8.949753] ? finish_task_switch.isra.0+0xa2/0x320 [ 8.949755] ? __switch_to+0x10a/0x420 [ 8.949759] blk_mq_sched_dispatch_requests+0x37/0x60 [ 8.949761] blk_mq_run_work_fn+0x64/0x80 [ 8.949764] process_one_work+0x171/0x340 [ 8.949768] worker_thread+0x281/0x3a0 [ 8.949770] ? preempt_count_add+0x6e/0xa0 [ 8.949772] ? _raw_spin_lock_irqsave+0x27/0x60 [ 8.949775] ? __pfx_worker_thread+0x10/0x10 [ 8.949778] kthread+0xf4/0x130 [ 8.949780] ? __pfx_kthread+0x10/0x10 [ 8.949782] ret_from_fork+0x31/0x50 [ 8.949784] ? __pfx_kthread+0x10/0x10 [ 8.949786] ret_from_fork_asm+0x1b/0x30 [ 8.949791] </TASK> [ 8.949792] Modules linked in: sha256_ssse3 wireguard curve25519_x86_64 libcurve25519_generic libchacha20poly1305 chacha_x86_64 libchacha poly1305_x86_64 ip6_udp_tunnel udp_tunnel virtio_rng virtio_net net_failover failover virtio_blk virtio_balloon ptp_kvm ghash_clmulni_intel evdev crct10dif_pclmul crc32_pclmul btrfs blake2b_generic libcrc32c crc32c_generic crc32c_intel xor lzo_compress raid6_pq aesni_intel crypto_simd cryptd virtio_pci virtio_pci_legacy_dev virtio_pci_modern_dev [ 8.949820] ---[ end trace 0000000000000000 ]--- [ 8.949822] RIP: 0010:__kmem_cache_alloc_node+0x1c8/0x310 [ 8.949824] Code: 00 0f 85 5a 01 00 00 48 8d 65 d8 5b 41 5c 41 5d 41 5e 41 5f 5d c3 cc cc cc cc 41 8b 47 28 4d 8b 1f 49 89 f8 49 89 d2 48 01 f8 <48> 8b 18 48 89 c1 49 33 9f b8 00 00 00 48 89 f8 48 0f c9 48 31 cb [ 8.949826] RSP: 0018:ffffc9000033fa90 EFLAGS: 00010086 [ 8.949828] RAX: 968f091e52ae1848 RBX: 0000000000000820 RCX: 0000000000000060 [ 8.949829] RDX: 00000000003b3c00 RSI: 0000000000000820 RDI: 968f091e52ae1818 [ 8.949831] RBP: ffffc9000033fad8 R08: 968f091e52ae1818 R09: ffff888246783e50 [ 8.949832] R10: 00000000003b3c00 R11: 00000000000390c0 R12: 0000000000000820 [ 8.949833] R13: 0000000000000000 R14: 00000000ffffffff R15: ffff888100041600 [ 8.949834] FS: 0000000000000000(0000) GS:ffff888763c00000(0000) knlGS:0000000000000000 [ 8.949835] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 8.949837] CR2: 00007f30c16a73e0 CR3: 0000000113cbc004 CR4: 0000000000370ef0 [ 8.949840] Kernel panic - not syncing: Fatal exception [ 8.950106] Kernel Offset: disabled
Regards Pascal