bisecting cause commit starting from cb71b93c2dc36d18a8b05245973328d018272cdf
building syzkaller on bff65f44b47bd73f56c3d6a5c3899de5f5775136
testing commit cb71b93c2dc36d18a8b05245973328d018272cdf
compiler: gcc (GCC) 10.2.1 20210217, GNU ld (GNU Binutils for Debian) 2.35.2
kernel signature: b5b94c3d1e96a484970c5f4f3bfb7ede059c2bc81853e8addadbcaf640ef33b8
all runs: crashed: KASAN: use-after-free Read in pty_close
testing release v5.18
testing commit 4b0986a3613c92f4ec1bdc7f60ec66fea135991f
compiler: gcc (GCC) 10.2.1 20210217, GNU ld (GNU Binutils for Debian) 2.35.2
kernel signature: 31ab11752df35b127adc01e0f8d8ac7f49e1a63a41fe80eeb763afc7d885b500
all runs: OK
# git bisect start cb71b93c2dc36d18a8b05245973328d018272cdf 4b0986a3613c92f4ec1bdc7f60ec66fea135991f
Bisecting: 10621 revisions left to test after this (roughly 13 steps)
[9d004b2f4fea97cde123e7f1939b80e77bf2e695] Merge tag 'cxl-for-5.19' of git://git.kernel.org/pub/scm/linux/kernel/git/cxl/cxl

testing commit 9d004b2f4fea97cde123e7f1939b80e77bf2e695
compiler: gcc (GCC) 10.2.1 20210217, GNU ld (GNU Binutils for Debian) 2.35.2
kernel signature: f791865b835c9b5c677c511e3d96f7f821cb7d6057bb0e27d0f06088caa858df
all runs: OK
# git bisect good 9d004b2f4fea97cde123e7f1939b80e77bf2e695
Bisecting: 5301 revisions left to test after this (roughly 12 steps)
[b4c48ce837dc0122ed62b423c334b620cf8ff81b] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/tegra/linux.git

testing commit b4c48ce837dc0122ed62b423c334b620cf8ff81b
compiler: gcc (GCC) 10.2.1 20210217, GNU ld (GNU Binutils for Debian) 2.35.2
kernel signature: 3c2ae45e93644906d478ee9c7657c2cc3a8b482b9d1f5721e02a859620f390d0
all runs: OK
# git bisect good b4c48ce837dc0122ed62b423c334b620cf8ff81b
Bisecting: 2582 revisions left to test after this (roughly 11 steps)
[c2e609e496f8195af2b789511f24a00546bb976e] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git

testing commit c2e609e496f8195af2b789511f24a00546bb976e
compiler: gcc (GCC) 10.2.1 20210217, GNU ld (GNU Binutils for Debian) 2.35.2
kernel signature: d824f143127e955c09bf20ae59f6ad3ff34d0daf1486af8fa5d1ee15595fc6bf
all runs: OK
# git bisect good c2e609e496f8195af2b789511f24a00546bb976e
Bisecting: 1245 revisions left to test after this (roughly 10 steps)
[f38c55f14bf7f4b2abc621e53d4f2ec05693b8d9] Merge branch 'tty-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git

testing commit f38c55f14bf7f4b2abc621e53d4f2ec05693b8d9
compiler: gcc (GCC) 10.2.1 20210217, GNU ld (GNU Binutils for Debian) 2.35.2
kernel signature: 72e4e609dd46e0b0b2f7d2fb361d0239f9b4545776606debf9fd48fb21149941
all runs: crashed: KASAN: use-after-free Read in pty_close
# git bisect bad f38c55f14bf7f4b2abc621e53d4f2ec05693b8d9
Bisecting: 621 revisions left to test after this (roughly 9 steps)
[3dbe720029fea822bc10e4090c356081f092147c] Merge branch 'rcu/next' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu.git

testing commit 3dbe720029fea822bc10e4090c356081f092147c
compiler: gcc (GCC) 10.2.1 20210217, GNU ld (GNU Binutils for Debian) 2.35.2
kernel signature: 73d3332ec405964fb39731025d84089a848202b9692f399b9eb36c2ba338f9bf
run #0: basic kernel testing failed: BUG: program execution failed: executor NUM: failed to write control pipe: write |NUM: broken pipe
run #1: crashed: KASAN: use-after-free Read in pty_close
run #2: crashed: KASAN: use-after-free Read in pty_close
run #3: crashed: KASAN: use-after-free Read in pty_close
run #4: crashed: KASAN: use-after-free Read in pty_close
run #5: crashed: KASAN: use-after-free Read in pty_close
run #6: crashed: KASAN: use-after-free Read in pty_close
run #7: crashed: KASAN: use-after-free Read in pty_close
run #8: crashed: KASAN: use-after-free Read in pty_close
run #9: crashed: KASAN: use-after-free Read in pty_close
# git bisect bad 3dbe720029fea822bc10e4090c356081f092147c
Bisecting: 359 revisions left to test after this (roughly 9 steps)
[87473733404a7f7bcd7b9ad361e6ae14258fa98f] Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux.git

testing commit 87473733404a7f7bcd7b9ad361e6ae14258fa98f
compiler: gcc (GCC) 10.2.1 20210217, GNU ld (GNU Binutils for Debian) 2.35.2
kernel signature: 55610fee1e06f316b9b1e515816fe3289caea22b4da8ebc02a0cd0ee57fa3755
all runs: crashed: KASAN: use-after-free Read in pty_close
# git bisect bad 87473733404a7f7bcd7b9ad361e6ae14258fa98f
Bisecting: 178 revisions left to test after this (roughly 8 steps)
[33b5cb78b145dea3e216f5ed6fcb9eee47df372e] Merge branch 'for-5.20/io_uring' into for-next

testing commit 33b5cb78b145dea3e216f5ed6fcb9eee47df372e
compiler: gcc (GCC) 10.2.1 20210217, GNU ld (GNU Binutils for Debian) 2.35.2
kernel signature: 7c55ce5eb69b99ade58e10db655aa008572f12d1bb7dba940c379ab65b5b76c4
all runs: crashed: KASAN: use-after-free Read in pty_close
# git bisect bad 33b5cb78b145dea3e216f5ed6fcb9eee47df372e
Bisecting: 87 revisions left to test after this (roughly 7 steps)
[4f97b6207dd1c52d0b59af7829f0389b08f05cd6] io_uring: introduce io_req_cqe_overflow()

testing commit 4f97b6207dd1c52d0b59af7829f0389b08f05cd6
compiler: gcc (GCC) 10.2.1 20210217, GNU ld (GNU Binutils for Debian) 2.35.2
kernel signature: d8fd08c0cd6c6ad52311c1ca8073e20e7f736c136dc513c800de946a07f869cb
all runs: OK
# git bisect good 4f97b6207dd1c52d0b59af7829f0389b08f05cd6
Bisecting: 43 revisions left to test after this (roughly 6 steps)
[387bd8179f68673cd77a682090a894a64340ed46] io_uring: move POLLFREE handling to separate function

testing commit 387bd8179f68673cd77a682090a894a64340ed46
compiler: gcc (GCC) 10.2.1 20210217, GNU ld (GNU Binutils for Debian) 2.35.2
kernel signature: 50d450306cf7815acada8c0b4a323cf7c89aade059c2ae4461f692e87e792a28
all runs: crashed: KASAN: use-after-free Read in pty_close
# git bisect bad 387bd8179f68673cd77a682090a894a64340ed46
Bisecting: 21 revisions left to test after this (roughly 5 steps)
[e5feb366a5867434579928bcd7048677ebb08579] io_uring: optimize io_uring_task layout

testing commit e5feb366a5867434579928bcd7048677ebb08579
compiler: gcc (GCC) 10.2.1 20210217, GNU ld (GNU Binutils for Debian) 2.35.2
kernel signature: df7948e6b22edcaad3cff9fc44c94f595bb41f2742194df0601f53239bed2850
all runs: OK
# git bisect good e5feb366a5867434579928bcd7048677ebb08579
Bisecting: 10 revisions left to test after this (roughly 4 steps)
[f39711a2f7885b68b503f66120c851c5b7dad1e3] io_uring: kbuf: kill __io_kbuf_recycle()

testing commit f39711a2f7885b68b503f66120c851c5b7dad1e3
compiler: gcc (GCC) 10.2.1 20210217, GNU ld (GNU Binutils for Debian) 2.35.2
kernel signature: a27410c4c61a7f6af55c7e89ab8cc37c07f61276ee177d2ba80280607854d9f2
all runs: OK
# git bisect good f39711a2f7885b68b503f66120c851c5b7dad1e3
Bisecting: 5 revisions left to test after this (roughly 3 steps)
[d61e5170253a710c3bf49226aeb77a1aad4226a3] io_uring: remove events caching atavisms

testing commit d61e5170253a710c3bf49226aeb77a1aad4226a3
compiler: gcc (GCC) 10.2.1 20210217, GNU ld (GNU Binutils for Debian) 2.35.2
kernel signature: b8181e74bbacef2624d0cb7cc5dbb62daa8c4972d830f09aa0b9685233294764
all runs: OK
# git bisect good d61e5170253a710c3bf49226aeb77a1aad4226a3
Bisecting: 2 revisions left to test after this (roughly 2 steps)
[cb736cd6b8ee0376e262ee291bd7f6fe5ce2e43a] io_uring: refactor poll arm error handling

testing commit cb736cd6b8ee0376e262ee291bd7f6fe5ce2e43a
compiler: gcc (GCC) 10.2.1 20210217, GNU ld (GNU Binutils for Debian) 2.35.2
kernel signature: 188976aaad175edfc865351cb6a1de68e72d82e928a9bcd51bb057c6a09c9322
all runs: OK
# git bisect good cb736cd6b8ee0376e262ee291bd7f6fe5ce2e43a
Bisecting: 0 revisions left to test after this (roughly 1 step)
[d183792f537b3404b81038c7fb93fe63fb2046ad] io_uring: kbuf: inline io_kbuf_recycle_ring()

testing commit d183792f537b3404b81038c7fb93fe63fb2046ad
compiler: gcc (GCC) 10.2.1 20210217, GNU ld (GNU Binutils for Debian) 2.35.2
kernel signature: 0e41d6bc47f84f7c2c06a6c3e87fed5e0401fc4581d0007ea2165be894837813
all runs: crashed: KASAN: use-after-free Read in pty_close
# git bisect bad d183792f537b3404b81038c7fb93fe63fb2046ad
Bisecting: 0 revisions left to test after this (roughly 0 steps)
[a18427bb2d9b2c8bbacccd4f862b7b6b0a83ab75] io_uring: optimise submission side poll_refs

testing commit a18427bb2d9b2c8bbacccd4f862b7b6b0a83ab75
compiler: gcc (GCC) 10.2.1 20210217, GNU ld (GNU Binutils for Debian) 2.35.2
kernel signature: 320aaad9528a1a480549d246b95e0fb9a4228bf9f0babfb05ab488ad0a34eeae
all runs: crashed: KASAN: use-after-free Read in pty_close
# git bisect bad a18427bb2d9b2c8bbacccd4f862b7b6b0a83ab75
a18427bb2d9b2c8bbacccd4f862b7b6b0a83ab75 is the first bad commit
commit a18427bb2d9b2c8bbacccd4f862b7b6b0a83ab75
Author: Pavel Begunkov <asml.silence@gmail.com>
Date:   Thu Jun 23 14:24:49 2022 +0100

    io_uring: optimise submission side poll_refs
    
    The final poll_refs put in __io_arm_poll_handler() takes quite some
    cycles. When we're arming from the original task context task_work won't
    be run, so in this case we can assume that we won't race with task_works
    and so not take the initial ownership ref.
    
    One caveat is that after arming a poll we may race with it, so we have
    to add a bunch of io_poll_get_ownership() hidden inside of
    io_poll_can_finish_inline() whenever we want to complete arming inline.
    For the same reason we can't just set REQ_F_DOUBLE_POLL in
    __io_queue_proc() and so need to sync with the first poll entry by
    taking its wq head lock.
    
    Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
    Link: https://lore.kernel.org/r/8825315d7f5e182ac1578a031e546f79b1c97d01.1655990418.git.asml.silence@gmail.com
    Signed-off-by: Jens Axboe <axboe@kernel.dk>

 io_uring/poll.c | 88 +++++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 67 insertions(+), 21 deletions(-)

culprit signature: 320aaad9528a1a480549d246b95e0fb9a4228bf9f0babfb05ab488ad0a34eeae
parent  signature: 188976aaad175edfc865351cb6a1de68e72d82e928a9bcd51bb057c6a09c9322
revisions tested: 17, total time: 4h6m5.270916149s (build: 1h57m10.677413749s, test: 2h6m58.87895945s)
first bad commit: a18427bb2d9b2c8bbacccd4f862b7b6b0a83ab75 io_uring: optimise submission side poll_refs
recipients (to): ["asml.silence@gmail.com" "axboe@kernel.dk" "linux-kernel@vger.kernel.org"]
recipients (cc): []
crash: KASAN: use-after-free Read in pty_close
==================================================================
BUG: KASAN: use-after-free in __wake_up_common+0x637/0x650 kernel/sched/wait.c:100
Read of size 8 at addr ffff8880708d10b0 by task syz-executor.0/4202

CPU: 0 PID: 4202 Comm: syz-executor.0 Not tainted 5.19.0-rc4-syzkaller #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+0x57/0x7d lib/dump_stack.c:106
 print_address_description.constprop.0.cold+0xeb/0x495 mm/kasan/report.c:313
 print_report mm/kasan/report.c:429 [inline]
 kasan_report.cold+0xf4/0x1c6 mm/kasan/report.c:491
 __wake_up_common+0x637/0x650 kernel/sched/wait.c:100
 __wake_up_common_lock+0xd0/0x130 kernel/sched/wait.c:137
 pty_close+0xef/0x450 drivers/tty/pty.c:59
 tty_release+0x3aa/0xf80 drivers/tty/tty_io.c:1758
 __fput+0x1f5/0x8c0 fs/file_table.c:317
 task_work_run+0xc0/0x160 kernel/task_work.c:177
 resume_user_mode_work include/linux/resume_user_mode.h:49 [inline]
 exit_to_user_mode_loop kernel/entry/common.c:169 [inline]
 exit_to_user_mode_prepare+0x23c/0x250 kernel/entry/common.c:201
 __syscall_exit_to_user_mode_work kernel/entry/common.c:283 [inline]
 syscall_exit_to_user_mode+0x19/0x50 kernel/entry/common.c:294
 do_syscall_64+0x42/0xb0 arch/x86/entry/common.c:86
 entry_SYSCALL_64_after_hwframe+0x46/0xb0
RIP: 0033:0x7f5c7d03bd4b
Code: 0f 05 48 3d 00 f0 ff ff 77 45 c3 0f 1f 40 00 48 83 ec 18 89 7c 24 0c e8 63 fc ff ff 8b 7c 24 0c 41 89 c0 b8 03 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 35 44 89 c7 89 44 24 0c e8 a1 fc ff ff 8b 44
RSP: 002b:00007fff1f87b130 EFLAGS: 00000293 ORIG_RAX: 0000000000000003
RAX: 0000000000000000 RBX: 0000000000000009 RCX: 00007f5c7d03bd4b
RDX: 0000001b33620000 RSI: 0000000000000000 RDI: 0000000000000008
RBP: 00007f5c7d19d960 R08: 0000000000000000 R09: 00007fff1f9e2080
R10: 00007fff1f9e2090 R11: 0000000000000293 R12: 000000000001d529
R13: 00007fff1f87b230 R14: 00007f5c7d19c030 R15: 0000000000000032
 </TASK>

Allocated by task 4204:
 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+0xa9/0xd0 mm/kasan/common.c:524
 kmalloc include/linux/slab.h:600 [inline]
 __io_queue_proc+0x296/0x8e0 io_uring/poll.c:425
 poll_wait include/linux/poll.h:49 [inline]
 n_tty_poll+0x9d/0x790 drivers/tty/n_tty.c:2372
 tty_poll+0x10e/0x180 drivers/tty/tty_io.c:2212
 vfs_poll include/linux/poll.h:88 [inline]
 __io_arm_poll_handler+0x461/0x10e0 io_uring/poll.c:507
 io_arm_poll_handler+0x406/0xa00 io_uring/poll.c:634
 io_queue_async+0x6d/0x1c0 io_uring/io_uring.c:1754
 io_queue_sqe io_uring/io_uring.c:1788 [inline]
 io_submit_sqe io_uring/io_uring.c:2037 [inline]
 io_submit_sqes+0x10ae/0x1b50 io_uring/io_uring.c:2148
 __do_sys_io_uring_enter+0xca4/0x1870 io_uring/io_uring.c:3094
 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+0x46/0xb0

Freed by task 4206:
 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+0x166/0x1a0 mm/kasan/common.c:328
 kasan_slab_free include/linux/kasan.h:200 [inline]
 slab_free_hook mm/slub.c:1754 [inline]
 slab_free_freelist_hook+0x8b/0x1c0 mm/slub.c:1780
 slab_free mm/slub.c:3536 [inline]
 kfree+0xd6/0x4d0 mm/slub.c:4584
 io_clean_op+0x15a/0x8c0 io_uring/io_uring.c:1556
 io_dismantle_req io_uring/io_uring.c:930 [inline]
 io_free_req+0xa2/0x235 io_uring/io_uring.c:940
 io_put_req_find_next io_uring/io_uring.c:1237 [inline]
 io_wq_free_work.cold+0x50/0x57 io_uring/io_uring.c:1637
 io_worker_handle_work+0x760/0x1b00 io_uring/io-wq.c:590
 io_wqe_worker+0x547/0xcb0 io_uring/io-wq.c:634
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:302

The buggy address belongs to the object at ffff8880708d1080
 which belongs to the cache kmalloc-64 of size 64
The buggy address is located 48 bytes inside of
 64-byte region [ffff8880708d1080, ffff8880708d10c0)

The buggy address belongs to the physical page:
page:ffffea0001c23440 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x708d1
flags: 0xfff00000000200(slab|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000000200 ffffea0000822200 dead000000000005 ffff888010c41640
raw: 0000000000000000 0000000000200020 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 3604, tgid 3604 (syz-executor.0), ts 42216497829, free_ts 9351379967
 prep_new_page mm/page_alloc.c:2456 [inline]
 get_page_from_freelist+0x19d3/0x3b30 mm/page_alloc.c:4198
 __alloc_pages+0x1c7/0x510 mm/page_alloc.c:5426
 alloc_slab_page mm/slub.c:1824 [inline]
 allocate_slab+0x26c/0x3c0 mm/slub.c:1969
 new_slab mm/slub.c:2029 [inline]
 ___slab_alloc+0x9bc/0xe10 mm/slub.c:3031
 __slab_alloc.constprop.0+0x4d/0xa0 mm/slub.c:3118
 slab_alloc_node mm/slub.c:3209 [inline]
 slab_alloc mm/slub.c:3251 [inline]
 __kmalloc+0x318/0x350 mm/slub.c:4442
 kmalloc include/linux/slab.h:605 [inline]
 kzalloc include/linux/slab.h:733 [inline]
 kobject_get_path+0x9a/0x1f0 lib/kobject.c:147
 kobject_uevent_env+0x1eb/0x12f0 lib/kobject_uevent.c:529
 rx_queue_add_kobject net/core/net-sysfs.c:1074 [inline]
 net_rx_queue_update_kobjects+0xab/0x410 net/core/net-sysfs.c:1114
 register_queue_kobjects net/core/net-sysfs.c:1774 [inline]
 netdev_register_kobject+0x241/0x3a0 net/core/net-sysfs.c:2019
 register_netdevice+0xada/0x1300 net/core/dev.c:10047
 nsim_init_netdevsim drivers/net/netdevsim/netdev.c:317 [inline]
 nsim_create+0x371/0x4b0 drivers/net/netdevsim/netdev.c:365
 __nsim_dev_port_add+0x24f/0x780 drivers/net/netdevsim/dev.c:1390
 nsim_dev_port_add_all+0x38/0x70 drivers/net/netdevsim/dev.c:1451
 nsim_drv_probe+0xbb2/0x1020 drivers/net/netdevsim/dev.c:1605
 call_driver_probe drivers/base/dd.c:555 [inline]
 really_probe+0x1c1/0xa40 drivers/base/dd.c:634
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
 free_contig_range+0xb1/0x180 mm/page_alloc.c:9314
 destroy_args+0x7e/0x503 mm/debug_vm_pgtable.c:1031
 debug_vm_pgtable+0x1f48/0x1fcc mm/debug_vm_pgtable.c:1354
 do_one_initcall+0xbe/0x440 init/main.c:1295
 do_initcall_level init/main.c:1368 [inline]
 do_initcalls init/main.c:1384 [inline]
 do_basic_setup init/main.c:1403 [inline]
 kernel_init_freeable+0x5ab/0x605 init/main.c:1610
 kernel_init+0x14/0x130 init/main.c:1499
 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:302

Memory state around the buggy address:
 ffff8880708d0f80: fb fb fb fb fc fc fc fc fc fc fc fc fc fc fc fc
 ffff8880708d1000: 00 00 00 00 00 00 00 00 fc fc fc fc fc fc fc fc
>ffff8880708d1080: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
                                     ^
 ffff8880708d1100: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
 ffff8880708d1180: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
==================================================================