enable those syscalls in syzkaller and begin to fuzz
```
"enable_syscalls": [
"openat$ptmx",
"ioctl$TIOCSPTLCK",
"ioctl$TIOCSETD"
],
```
I got 31 similar crashes in 14h, here is an example
```
==================================================================
BUG: KASAN: use-after-free in instrument_atomic_read include/linux/instrumented.h:71 [inline]
BUG: KASAN: use-after-free in test_bit include/asm-generic/bitops/instrumented-non-atomic.h:134 [inline]
BUG: KASAN: use-after-free in kthread_is_per_cpu+0x81/0xe0 kernel/kthread.c:610
Read of size 8 at addr ffff8881240ab800 by task syz-executor.1/27180
CPU: 6 PID: 27180 Comm: syz-executor.1 Not tainted 5.18.0-rc1 #5
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x4d/0x66 lib/dump_stack.c:106
print_address_description mm/kasan/report.c:313 [inline]
print_report.cold+0xb2/0x6b7 mm/kasan/report.c:429
kasan_report+0xa9/0x120 mm/kasan/report.c:491
check_region_inline mm/kasan/generic.c:183 [inline]
kasan_check_range+0x14d/0x1d0 mm/kasan/generic.c:189
instrument_atomic_read include/linux/instrumented.h:71 [inline]
test_bit include/asm-generic/bitops/instrumented-non-atomic.h:134 [inline]
kthread_is_per_cpu+0x81/0xe0 kernel/kthread.c:610
can_migrate_task kernel/sched/fair.c:7807 [inline]
detach_tasks kernel/sched/fair.c:7971 [inline]
load_balance+0x9ad/0x20d0 kernel/sched/fair.c:9960
newidle_balance.isra.0+0x520/0xc70 kernel/sched/fair.c:10969
pick_next_task_fair+0x4e/0xb20 kernel/sched/fair.c:7387
__pick_next_task kernel/sched/core.c:5695 [inline]
pick_next_task kernel/sched/core.c:6198 [inline]
__schedule+0x290/0x1b30 kernel/sched/core.c:6346
schedule+0xd2/0x1f0 kernel/sched/core.c:6454
freezable_schedule include/linux/freezer.h:172 [inline]
futex_wait_queue+0x10e/0x290 kernel/futex/waitwake.c:355
futex_wait+0x29e/0x630 kernel/futex/waitwake.c:656
do_futex+0x2aa/0x330 kernel/futex/syscalls.c:106
__do_sys_futex kernel/futex/syscalls.c:183 [inline]
__se_sys_futex kernel/futex/syscalls.c:164 [inline]
__x64_sys_futex+0x1ad/0x400 kernel/futex/syscalls.c:164
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3b/0x90 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0xae
RIP: 0033:0x7f550fc9383d
Code: 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 f3 0f 1e fa 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:00007f550f405c98 EFLAGS: 00000246 ORIG_RAX: 00000000000000ca
RAX: ffffffffffffffda RBX: 00007f550fdb2f60 RCX: 00007f550fc9383d
RDX: 0000000000000000 RSI: 0000000000000080 RDI: 00007f550fdb2f68
RBP: 00007f550fdb2f68 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007f550fdb2f6c
R13: 00007ffc93d3187f R14: 00007ffc93d31a20 R15: 00007f550f405d80
</TASK>
Allocated by task 29732:
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+0x81/0xa0 mm/kasan/common.c:524
kmalloc include/linux/slab.h:581 [inline]
kzalloc include/linux/slab.h:714 [inline]
set_kthread_struct+0xb5/0x230 kernel/kthread.c:117
copy_process+0x440c/0x6440 kernel/fork.c:2161
kernel_clone+0xc2/0x8f0 kernel/fork.c:2639
kernel_thread+0xb5/0xf0 kernel/fork.c:2691
call_usermodehelper_exec_sync kernel/umh.c:135 [inline]
call_usermodehelper_exec_work+0x5b/0x160 kernel/umh.c:166
process_one_work+0x866/0x11d0 kernel/workqueue.c:2289
worker_thread+0x549/0x1130 kernel/workqueue.c:2436
kthread+0x288/0x330 kernel/kthread.c:376
ret_from_fork+0x22/0x30 arch/x86/entry/entry_64.S:298
Freed by task 27184:
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 mm/kasan/common.c:328 [inline]
__kasan_slab_free+0x10c/0x170 mm/kasan/common.c:374
kasan_slab_free include/linux/kasan.h:200 [inline]
slab_free_hook mm/slub.c:1728 [inline]
slab_free_freelist_hook mm/slub.c:1754 [inline]
slab_free mm/slub.c:3510 [inline]
kfree+0x89/0x290 mm/slub.c:4552
free_kthread_struct+0xf5/0x150 kernel/kthread.c:145
begin_new_exec+0x1d1e/0x27e0 fs/exec.c:1312
load_elf_binary+0x10ce/0x4620 fs/binfmt_elf.c:1002
search_binary_handler fs/exec.c:1726 [inline]
exec_binprm fs/exec.c:1767 [inline]
bprm_execve fs/exec.c:1836 [inline]
bprm_execve+0x69a/0x1390 fs/exec.c:1798
kernel_execve+0x328/0x430 fs/exec.c:1997
call_usermodehelper_exec_async+0x2e0/0x550 kernel/umh.c:112
ret_from_fork+0x22/0x30 arch/x86/entry/entry_64.S:298
The buggy address belongs to the object at ffff8881240ab800
which belongs to the cache kmalloc-128 of size 128
The buggy address is located 0 bytes inside of
128-byte region [ffff8881240ab800, ffff8881240ab880)
The buggy address belongs to the physical page:
page:00000000c44cb91e refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1240aa
head:00000000c44cb91e order:1 compound_mapcount:0 compound_pincount:0
flags: 0x200000000010200(slab|head|node=0|zone=2)
raw: 0200000000010200 ffffea0004027980 dead000000000002 ffff8881000428c0
raw: 0000000000000000 0000000080200020 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff8881240ab700: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8881240ab780: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff8881240ab800: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8881240ab880: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff8881240ab900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
BUG: KASAN: use-after-free in instrument_atomic_read include/linux/instrumented.h:71 [inline]
BUG: KASAN: use-after-free in test_bit include/asm-generic/bitops/instrumented-non-atomic.h:134 [inline]
BUG: KASAN: use-after-free in kthread_is_per_cpu+0x81/0xe0 kernel/kthread.c:610
Read of size 8 at addr ffff8881240ab800 by task syz-executor.1/27180
CPU: 6 PID: 27180 Comm: syz-executor.1 Not tainted 5.18.0-rc1 #5
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x4d/0x66 lib/dump_stack.c:106
print_address_description mm/kasan/report.c:313 [inline]
print_report.cold+0xb2/0x6b7 mm/kasan/report.c:429
kasan_report+0xa9/0x120 mm/kasan/report.c:491
check_region_inline mm/kasan/generic.c:183 [inline]
kasan_check_range+0x14d/0x1d0 mm/kasan/generic.c:189
instrument_atomic_read include/linux/instrumented.h:71 [inline]
test_bit include/asm-generic/bitops/instrumented-non-atomic.h:134 [inline]
kthread_is_per_cpu+0x81/0xe0 kernel/kthread.c:610
can_migrate_task kernel/sched/fair.c:7807 [inline]
detach_tasks kernel/sched/fair.c:7971 [inline]
load_balance+0x9ad/0x20d0 kernel/sched/fair.c:9960
newidle_balance.isra.0+0x520/0xc70 kernel/sched/fair.c:10969
pick_next_task_fair+0x4e/0xb20 kernel/sched/fair.c:7387
__pick_next_task kernel/sched/core.c:5695 [inline]
pick_next_task kernel/sched/core.c:6198 [inline]
__schedule+0x290/0x1b30 kernel/sched/core.c:6346
schedule+0xd2/0x1f0 kernel/sched/core.c:6454
freezable_schedule include/linux/freezer.h:172 [inline]
futex_wait_queue+0x10e/0x290 kernel/futex/waitwake.c:355
futex_wait+0x29e/0x630 kernel/futex/waitwake.c:656
do_futex+0x2aa/0x330 kernel/futex/syscalls.c:106
__do_sys_futex kernel/futex/syscalls.c:183 [inline]
__se_sys_futex kernel/futex/syscalls.c:164 [inline]
__x64_sys_futex+0x1ad/0x400 kernel/futex/syscalls.c:164
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3b/0x90 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0xae
RIP: 0033:0x7f550fc9383d
Code: 02 b8 ff ff ff ff c3 66 0f 1f 44 00 00 f3 0f 1e fa 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:00007f550f405c98 EFLAGS: 00000246 ORIG_RAX: 00000000000000ca
RAX: ffffffffffffffda RBX: 00007f550fdb2f60 RCX: 00007f550fc9383d
RDX: 0000000000000000 RSI: 0000000000000080 RDI: 00007f550fdb2f68
RBP: 00007f550fdb2f68 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00007f550fdb2f6c
R13: 00007ffc93d3187f R14: 00007ffc93d31a20 R15: 00007f550f405d80
</TASK>
Allocated by task 29732:
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+0x81/0xa0 mm/kasan/common.c:524
kmalloc include/linux/slab.h:581 [inline]
kzalloc include/linux/slab.h:714 [inline]
set_kthread_struct+0xb5/0x230 kernel/kthread.c:117
copy_process+0x440c/0x6440 kernel/fork.c:2161
kernel_clone+0xc2/0x8f0 kernel/fork.c:2639
kernel_thread+0xb5/0xf0 kernel/fork.c:2691
call_usermodehelper_exec_sync kernel/umh.c:135 [inline]
call_usermodehelper_exec_work+0x5b/0x160 kernel/umh.c:166
process_one_work+0x866/0x11d0 kernel/workqueue.c:2289
worker_thread+0x549/0x1130 kernel/workqueue.c:2436
kthread+0x288/0x330 kernel/kthread.c:376
ret_from_fork+0x22/0x30 arch/x86/entry/entry_64.S:298
Freed by task 27184:
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 mm/kasan/common.c:328 [inline]
__kasan_slab_free+0x10c/0x170 mm/kasan/common.c:374
kasan_slab_free include/linux/kasan.h:200 [inline]
slab_free_hook mm/slub.c:1728 [inline]
slab_free_freelist_hook mm/slub.c:1754 [inline]
slab_free mm/slub.c:3510 [inline]
kfree+0x89/0x290 mm/slub.c:4552
free_kthread_struct+0xf5/0x150 kernel/kthread.c:145
begin_new_exec+0x1d1e/0x27e0 fs/exec.c:1312
load_elf_binary+0x10ce/0x4620 fs/binfmt_elf.c:1002
search_binary_handler fs/exec.c:1726 [inline]
exec_binprm fs/exec.c:1767 [inline]
bprm_execve fs/exec.c:1836 [inline]
bprm_execve+0x69a/0x1390 fs/exec.c:1798
kernel_execve+0x328/0x430 fs/exec.c:1997
call_usermodehelper_exec_async+0x2e0/0x550 kernel/umh.c:112
ret_from_fork+0x22/0x30 arch/x86/entry/entry_64.S:298
The buggy address belongs to the object at ffff8881240ab800
which belongs to the cache kmalloc-128 of size 128
The buggy address is located 0 bytes inside of
128-byte region [ffff8881240ab800, ffff8881240ab880)
The buggy address belongs to the physical page:
page:00000000c44cb91e refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1240aa
head:00000000c44cb91e order:1 compound_mapcount:0 compound_pincount:0
flags: 0x200000000010200(slab|head|node=0|zone=2)
raw: 0200000000010200 ffffea0004027980 dead000000000002 ffff8881000428c0
raw: 0000000000000000 0000000080200020 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff8881240ab700: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff8881240ab780: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff8881240ab800: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff8881240ab880: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff8881240ab900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
```
I think crash is related is `ioctl$TIOCSETD` .
`ioctl$TIOCSETD` syscall use `request_module("tty-ldisc-%d", disc);` to load unknow line discipline module, it lead to kthread object being freed by `free_kthread_struct(...)`
crash will happen when can_migrate_task() try to access kthread object
this crash can easily be triggered in syzkaller fuzz. but hard to reproduce it.
It's really strange, and I could not give a POC or explaination
if it's really a security problem in kernel, I wish I can get a CVE number