syzbot


KASAN: invalid-free in packet_set_ring

Status: fixed on 2022/03/08 16:11
Subsystems: net
[Documentation on labels]
Fix commit: ec6af094ea28 net/packet: rx_owner_map depends on pg_vec
First crash: 866d, last: 866d
Cause bisection: the issue happens on the oldest tested release (bisect log)
Crash: KASAN: invalid-free in packet_set_ring (log)
Repro: C syz .config
  
Discussions (6)
Title Replies (including bot) Last reply
[PATCH 4.19 00/56] 4.19.222-rc1 review 66 (66) 2021/12/22 07:54
[PATCH 5.15 000/177] 5.15.11-rc1 review 183 (183) 2021/12/21 23:14
[PATCH 5.10 00/99] 5.10.88-rc1 review 106 (106) 2021/12/21 23:13
[PATCH 5.4 00/71] 5.4.168-rc1 review 78 (78) 2021/12/21 23:13
[PATCH 4.14 00/45] 4.14.259-rc1 review 48 (48) 2021/12/21 23:12
[PATCH net] net/packet: rx_owner_map depends on pg_vec 1 (1) 2021/12/15 14:39
Similar bugs (2)
Kernel Title Repro Cause bisect Fix bisect Count Last Reported Patched Status
linux-4.19 KASAN: invalid-free in packet_set_ring C error 1 866d 866d 0/1 upstream: reported C repro on 2021/12/12 11:35
android-54 KASAN: invalid-free in packet_set_ring C 1 866d 866d 0/2 auto-obsoleted due to no activity on 2023/04/20 06:54

Sample crash report:
==================================================================
BUG: KASAN: double-free or invalid-free in packet_set_ring+0xfa6/0x1b20 net/packet/af_packet.c:4495

CPU: 1 PID: 8668 Comm: syz-executor880 Not tainted 5.16.0-rc4-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
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+0x8d/0x2ed mm/kasan/report.c:247
 kasan_report_invalid_free+0x51/0x80 mm/kasan/report.c:372
 ____kasan_slab_free mm/kasan/common.c:346 [inline]
 __kasan_slab_free+0xf6/0x110 mm/kasan/common.c:374
 kasan_slab_free include/linux/kasan.h:235 [inline]
 __cache_free mm/slab.c:3445 [inline]
 kfree+0x10d/0x2c0 mm/slab.c:3802
 packet_set_ring+0xfa6/0x1b20 net/packet/af_packet.c:4495
 packet_setsockopt+0x1bd3/0x3c10 net/packet/af_packet.c:3785
 __sys_setsockopt+0x2db/0x610 net/socket.c:2176
 __do_sys_setsockopt net/socket.c:2187 [inline]
 __se_sys_setsockopt net/socket.c:2184 [inline]
 __x64_sys_setsockopt+0xba/0x150 net/socket.c:2184
 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+0x44/0xae
RIP: 0033:0x7f1a8ae519c9
Code: 28 00 00 00 75 05 48 83 c4 28 c3 e8 b1 15 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 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f1a8ade1318 EFLAGS: 00000246 ORIG_RAX: 0000000000000036
RAX: ffffffffffffffda RBX: 00007f1a8aedb4b8 RCX: 00007f1a8ae519c9
RDX: 0000000000000005 RSI: 0000000000000107 RDI: 0000000000000003
RBP: 00007f1a8aedb4b0 R08: 000000000000001c R09: 0000000000000000
R10: 00000000200000c0 R11: 0000000000000246 R12: 00007f1a8aea82a4
R13: 00007ffe5b491b9f R14: 00007f1a8ade1400 R15: 0000000000022000
 </TASK>

Allocated by task 8657:
 kasan_save_stack+0x1e/0x50 mm/kasan/common.c:38
 kasan_set_track mm/kasan/common.c:46 [inline]
 set_alloc_info mm/kasan/common.c:434 [inline]
 ____kasan_kmalloc mm/kasan/common.c:513 [inline]
 ____kasan_kmalloc mm/kasan/common.c:472 [inline]
 __kasan_kmalloc+0xa6/0xd0 mm/kasan/common.c:522
 kasan_kmalloc include/linux/kasan.h:269 [inline]
 __do_kmalloc mm/slab.c:3702 [inline]
 __kmalloc+0x209/0x4d0 mm/slab.c:3711
 kmalloc_array include/linux/slab.h:630 [inline]
 kcalloc include/linux/slab.h:661 [inline]
 alloc_pg_vec net/packet/af_packet.c:4317 [inline]
 packet_set_ring+0xa76/0x1b20 net/packet/af_packet.c:4407
 packet_setsockopt+0x1bd3/0x3c10 net/packet/af_packet.c:3785
 __sys_setsockopt+0x2db/0x610 net/socket.c:2176
 __do_sys_setsockopt net/socket.c:2187 [inline]
 __se_sys_setsockopt net/socket.c:2184 [inline]
 __x64_sys_setsockopt+0xba/0x150 net/socket.c:2184
 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+0x44/0xae

Freed by task 8657:
 kasan_save_stack+0x1e/0x50 mm/kasan/common.c:38
 kasan_set_track+0x21/0x30 mm/kasan/common.c:46
 kasan_set_free_info+0x20/0x30 mm/kasan/generic.c:370
 ____kasan_slab_free mm/kasan/common.c:366 [inline]
 ____kasan_slab_free mm/kasan/common.c:328 [inline]
 __kasan_slab_free+0xd1/0x110 mm/kasan/common.c:374
 kasan_slab_free include/linux/kasan.h:235 [inline]
 __cache_free mm/slab.c:3445 [inline]
 kfree+0x10d/0x2c0 mm/slab.c:3802
 packet_set_ring+0x6c7/0x1b20 net/packet/af_packet.c:4497
 packet_setsockopt+0x1bd3/0x3c10 net/packet/af_packet.c:3785
 __sys_setsockopt+0x2db/0x610 net/socket.c:2176
 __do_sys_setsockopt net/socket.c:2187 [inline]
 __se_sys_setsockopt net/socket.c:2184 [inline]
 __x64_sys_setsockopt+0xba/0x150 net/socket.c:2184
 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+0x44/0xae

The buggy address belongs to the object at ffff888079d24900
 which belongs to the cache kmalloc-64 of size 64
The buggy address is located 0 bytes inside of
 64-byte region [ffff888079d24900, ffff888079d24940)
The buggy address belongs to the page:
page:ffffea0001e74900 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x79d24
flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 ffffea0001e86bc8 ffffea0001e74ec8 ffff888010c40200
raw: 0000000000000000 ffff888079d24000 0000000100000020 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 0x242040(__GFP_IO|__GFP_NOWARN|__GFP_COMP|__GFP_THISNODE), pid 2973, ts 21638960315, free_ts 21638873086
 prep_new_page mm/page_alloc.c:2418 [inline]
 get_page_from_freelist+0xa72/0x2f50 mm/page_alloc.c:4149
 __alloc_pages+0x1b2/0x500 mm/page_alloc.c:5369
 __alloc_pages_node include/linux/gfp.h:570 [inline]
 kmem_getpages mm/slab.c:1377 [inline]
 cache_grow_begin+0x75/0x470 mm/slab.c:2593
 cache_alloc_refill+0x27f/0x380 mm/slab.c:2965
 ____cache_alloc mm/slab.c:3048 [inline]
 ____cache_alloc mm/slab.c:3031 [inline]
 __do_cache_alloc mm/slab.c:3275 [inline]
 slab_alloc mm/slab.c:3316 [inline]
 __do_kmalloc mm/slab.c:3700 [inline]
 __kmalloc+0x3b3/0x4d0 mm/slab.c:3711
 kmalloc include/linux/slab.h:595 [inline]
 kzalloc include/linux/slab.h:724 [inline]
 tomoyo_encode2.part.0+0xe9/0x3a0 security/tomoyo/realpath.c:45
 tomoyo_encode2 security/tomoyo/realpath.c:31 [inline]
 tomoyo_encode+0x28/0x50 security/tomoyo/realpath.c:80
 tomoyo_realpath_from_path+0x186/0x620 security/tomoyo/realpath.c:288
 tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
 tomoyo_path_perm+0x21b/0x400 security/tomoyo/file.c:822
 security_inode_getattr+0xcf/0x140 security/security.c:1334
 vfs_getattr fs/stat.c:157 [inline]
 vfs_statx+0x164/0x390 fs/stat.c:225
 vfs_fstatat fs/stat.c:243 [inline]
 __do_sys_newfstatat+0x96/0x120 fs/stat.c:412
 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+0x44/0xae
page last free stack trace:
 reset_page_owner include/linux/page_owner.h:24 [inline]
 free_pages_prepare mm/page_alloc.c:1338 [inline]
 free_pcp_prepare+0x374/0x870 mm/page_alloc.c:1389
 free_unref_page_prepare mm/page_alloc.c:3309 [inline]
 free_unref_page+0x19/0x690 mm/page_alloc.c:3388
 selinux_genfs_get_sid security/selinux/hooks.c:1356 [inline]
 inode_doinit_with_dentry+0x868/0x12e0 security/selinux/hooks.c:1551
 selinux_d_instantiate+0x23/0x30 security/selinux/hooks.c:6385
 security_d_instantiate+0x50/0xe0 security/security.c:2040
 d_splice_alias+0x8c/0xc60 fs/dcache.c:3064
 kernfs_iop_lookup+0x22d/0x2c0 fs/kernfs/dir.c:1137
 __lookup_slow+0x24c/0x480 fs/namei.c:1657
 lookup_slow fs/namei.c:1674 [inline]
 walk_component+0x40f/0x6a0 fs/namei.c:1970
 lookup_last fs/namei.c:2425 [inline]
 path_lookupat+0x1bb/0x860 fs/namei.c:2449
 filename_lookup+0x1c6/0x590 fs/namei.c:2478
 user_path_at_empty+0x42/0x60 fs/namei.c:2801
 do_readlinkat+0xcd/0x2f0 fs/stat.c:443
 __do_sys_readlink fs/stat.c:476 [inline]
 __se_sys_readlink fs/stat.c:473 [inline]
 __x64_sys_readlink+0x74/0xb0 fs/stat.c:473
 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+0x44/0xae

Memory state around the buggy address:
 ffff888079d24800: 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc
 ffff888079d24880: 00 00 00 00 00 00 00 00 fc fc fc fc fc fc fc fc
>ffff888079d24900: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
                   ^
 ffff888079d24980: 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc
 ffff888079d24a00: 00 00 00 00 00 00 00 00 fc fc fc fc fc fc fc fc
==================================================================

Crashes (4):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2021/12/12 11:11 upstream a763d5a5abd6 49ca1f59 .config console log report syz C ci-upstream-kasan-gce-selinux-root KASAN: invalid-free in packet_set_ring
2021/12/12 11:41 net-old ee60e626d536 49ca1f59 .config console log report syz C ci-upstream-net-this-kasan-gce KASAN: invalid-free in packet_set_ring
2021/12/12 16:42 net-next-old 8c8b7aa7fb0c 49ca1f59 .config console log report syz C ci-upstream-net-kasan-gce KASAN: invalid-free in packet_set_ring
2021/12/12 10:37 upstream a763d5a5abd6 49ca1f59 .config console log report info ci-upstream-kasan-gce-selinux-root KASAN: invalid-free in packet_set_ring
* Struck through repros no longer work on HEAD.