1. 08 2月, 2021 12 次提交
    • P
      io_uring: fix skipping disabling sqo on exec · 417ce493
      Pavel Begunkov 提交于
      stable inclusion
      from stable-5.10.12
      commit 186725a80c4e931b6fe31b94d66c989d5f2354c1
      bugzilla: 47876
      
      --------------------------------
      
      [ Upstream commit 0b5cd6c3 ]
      
      If there are no requests at the time __io_uring_task_cancel() is called,
      tctx_inflight() returns zero and and it terminates not getting a chance
      to go through __io_uring_files_cancel() and do
      io_disable_sqo_submit(). And we absolutely want them disabled by the
      time cancellation ends.
      
      Cc: stable@vger.kernel.org # 5.5+
      Reported-by: NJens Axboe <axboe@kernel.dk>
      Signed-off-by: NPavel Begunkov <asml.silence@gmail.com>
      Fixes: d9d05217 ("io_uring: stop SQPOLL submit on creator's death")
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NChen Jun <chenjun102@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      417ce493
    • P
      io_uring: fix uring_flush in exit_files() warning · 8940e1a8
      Pavel Begunkov 提交于
      stable inclusion
      from stable-5.10.12
      commit 54b4c4f9aba9e5d1ef6877f42a57895b189107c9
      bugzilla: 47876
      
      --------------------------------
      
      [ Upstream commit 4325cb49 ]
      
      WARNING: CPU: 1 PID: 11100 at fs/io_uring.c:9096
      	io_uring_flush+0x326/0x3a0 fs/io_uring.c:9096
      RIP: 0010:io_uring_flush+0x326/0x3a0 fs/io_uring.c:9096
      Call Trace:
       filp_close+0xb4/0x170 fs/open.c:1280
       close_files fs/file.c:401 [inline]
       put_files_struct fs/file.c:416 [inline]
       put_files_struct+0x1cc/0x350 fs/file.c:413
       exit_files+0x7e/0xa0 fs/file.c:433
       do_exit+0xc22/0x2ae0 kernel/exit.c:820
       do_group_exit+0x125/0x310 kernel/exit.c:922
       get_signal+0x3e9/0x20a0 kernel/signal.c:2770
       arch_do_signal_or_restart+0x2a8/0x1eb0 arch/x86/kernel/signal.c:811
       handle_signal_work kernel/entry/common.c:147 [inline]
       exit_to_user_mode_loop kernel/entry/common.c:171 [inline]
       exit_to_user_mode_prepare+0x148/0x250 kernel/entry/common.c:201
       __syscall_exit_to_user_mode_work kernel/entry/common.c:291 [inline]
       syscall_exit_to_user_mode+0x19/0x50 kernel/entry/common.c:302
       entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      An SQPOLL ring creator task may have gotten rid of its file note during
      exit and called io_disable_sqo_submit(), but the io_uring is still left
      referenced through fdtable, which will be put during close_files() and
      cause a false positive warning.
      
      First split the warning into two for more clarity when is hit, and the
      add sqo_dead check to handle the described case.
      
      Cc: stable@vger.kernel.org # 5.5+
      Reported-by: syzbot+a32b546d58dde07875a1@syzkaller.appspotmail.com
      Signed-off-by: NPavel Begunkov <asml.silence@gmail.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NChen Jun <chenjun102@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      8940e1a8
    • P
      io_uring: fix false positive sqo warning on flush · 79ee5666
      Pavel Begunkov 提交于
      stable inclusion
      from stable-5.10.12
      commit 0682759126bc761c325325ca809ae99c93fda2a0
      bugzilla: 47876
      
      --------------------------------
      
      [ Upstream commit 6b393a1f ]
      
      WARNING: CPU: 1 PID: 9094 at fs/io_uring.c:8884
      	io_disable_sqo_submit+0x106/0x130 fs/io_uring.c:8884
      Call Trace:
       io_uring_flush+0x28b/0x3a0 fs/io_uring.c:9099
       filp_close+0xb4/0x170 fs/open.c:1280
       close_fd+0x5c/0x80 fs/file.c:626
       __do_sys_close fs/open.c:1299 [inline]
       __se_sys_close fs/open.c:1297 [inline]
       __x64_sys_close+0x2f/0xa0 fs/open.c:1297
       do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
       entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      io_uring's final close() may be triggered by any task not only the
      creator. It's well handled by io_uring_flush() including SQPOLL case,
      though a warning in io_disable_sqo_submit() will fallaciously fire by
      moving this warning out to the only call site that matters.
      
      Cc: stable@vger.kernel.org # 5.5+
      Reported-by: syzbot+2f5d1785dc624932da78@syzkaller.appspotmail.com
      Signed-off-by: NPavel Begunkov <asml.silence@gmail.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NChen Jun <chenjun102@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      79ee5666
    • P
      io_uring: do sqo disable on install_fd error · 43eac3ed
      Pavel Begunkov 提交于
      stable inclusion
      from stable-5.10.12
      commit 8cb6f4da831bc51145aee3a923f03114121dea6b
      bugzilla: 47876
      
      --------------------------------
      
      [ Upstream commit 06585c49 ]
      
      WARNING: CPU: 0 PID: 8494 at fs/io_uring.c:8717
      	io_ring_ctx_wait_and_kill+0x4f2/0x600 fs/io_uring.c:8717
      Call Trace:
       io_uring_release+0x3e/0x50 fs/io_uring.c:8759
       __fput+0x283/0x920 fs/file_table.c:280
       task_work_run+0xdd/0x190 kernel/task_work.c:140
       tracehook_notify_resume include/linux/tracehook.h:189 [inline]
       exit_to_user_mode_loop kernel/entry/common.c:174 [inline]
       exit_to_user_mode_prepare+0x249/0x250 kernel/entry/common.c:201
       __syscall_exit_to_user_mode_work kernel/entry/common.c:291 [inline]
       syscall_exit_to_user_mode+0x19/0x50 kernel/entry/common.c:302
       entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      failed io_uring_install_fd() is a special case, we don't do
      io_ring_ctx_wait_and_kill() directly but defer it to fput, though still
      need to io_disable_sqo_submit() before.
      
      note: it doesn't fix any real problem, just a warning. That's because
      sqring won't be available to the userspace in this case and so SQPOLL
      won't submit anything.
      
      Cc: stable@vger.kernel.org # 5.5+
      Reported-by: syzbot+9c9c35374c0ecac06516@syzkaller.appspotmail.com
      Fixes: d9d05217 ("io_uring: stop SQPOLL submit on creator's death")
      Signed-off-by: NPavel Begunkov <asml.silence@gmail.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NChen Jun <chenjun102@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      43eac3ed
    • P
      io_uring: fix null-deref in io_disable_sqo_submit · 8173ba66
      Pavel Begunkov 提交于
      stable inclusion
      from stable-5.10.12
      commit 0e3562e3b2aeb4a6aa4615185a8f59c51cade61b
      bugzilla: 47876
      
      --------------------------------
      
      [ Upstream commit b4411616 ]
      
      general protection fault, probably for non-canonical address
      	0xdffffc0000000022: 0000 [#1] KASAN: null-ptr-deref
      	in range [0x0000000000000110-0x0000000000000117]
      RIP: 0010:io_ring_set_wakeup_flag fs/io_uring.c:6929 [inline]
      RIP: 0010:io_disable_sqo_submit+0xdb/0x130 fs/io_uring.c:8891
      Call Trace:
       io_uring_create fs/io_uring.c:9711 [inline]
       io_uring_setup+0x12b1/0x38e0 fs/io_uring.c:9739
       do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
       entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      io_disable_sqo_submit() might be called before user rings were
      allocated, don't do io_ring_set_wakeup_flag() in those cases.
      
      Cc: stable@vger.kernel.org # 5.5+
      Reported-by: syzbot+ab412638aeb652ded540@syzkaller.appspotmail.com
      Fixes: d9d05217 ("io_uring: stop SQPOLL submit on creator's death")
      Signed-off-by: NPavel Begunkov <asml.silence@gmail.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NChen Jun <chenjun102@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      8173ba66
    • P
      io_uring: stop SQPOLL submit on creator's death · 63238c74
      Pavel Begunkov 提交于
      stable inclusion
      from stable-5.10.12
      commit a63d9157571b52f7339d6db4c2ab7bc3bfe527c0
      bugzilla: 47876
      
      --------------------------------
      
      [ Upstream commit d9d05217 ]
      
      When the creator of SQPOLL io_uring dies (i.e. sqo_task), we don't want
      its internals like ->files and ->mm to be poked by the SQPOLL task, it
      have never been nice and recently got racy. That can happen when the
      owner undergoes destruction and SQPOLL tasks tries to submit new
      requests in parallel, and so calls io_sq_thread_acquire*().
      
      That patch halts SQPOLL submissions when sqo_task dies by introducing
      sqo_dead flag. Once set, the SQPOLL task must not do any submission,
      which is synchronised by uring_lock as well as the new flag.
      
      The tricky part is to make sure that disabling always happens, that
      means either the ring is discovered by creator's do_exit() -> cancel,
      or if the final close() happens before it's done by the creator. The
      last is guaranteed by the fact that for SQPOLL the creator task and only
      it holds exactly one file note, so either it pins up to do_exit() or
      removed by the creator on the final put in flush. (see comments in
      uring_flush() around file->f_count == 2).
      
      One more place that can trigger io_sq_thread_acquire_*() is
      __io_req_task_submit(). Shoot off requests on sqo_dead there, even
      though actually we don't need to. That's because cancellation of
      sqo_task should wait for the request before going any further.
      
      note 1: io_disable_sqo_submit() does io_ring_set_wakeup_flag() so the
      caller would enter the ring to get an error, but it still doesn't
      guarantee that the flag won't be cleared.
      
      note 2: if final __userspace__ close happens not from the creator
      task, the file note will pin the ring until the task dies.
      
      Cc: stable@vger.kernel.org # 5.5+
      Fixed: b1b6b5a3 ("kernel/io_uring: cancel io_uring before task works")
      Signed-off-by: NPavel Begunkov <asml.silence@gmail.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NChen Jun <chenjun102@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      63238c74
    • P
      io_uring: add warn_once for io_uring_flush() · db9b4d68
      Pavel Begunkov 提交于
      stable inclusion
      from stable-5.10.12
      commit da67631a33c342528245817cc61e36dd945665b0
      bugzilla: 47876
      
      --------------------------------
      
      [ Upstream commit 6b5733eb]
      
      files_cancel() should cancel all relevant requests and drop file notes,
      so we should never have file notes after that, including on-exit fput
      and flush. Add a WARN_ONCE to be sure.
      
      Cc: stable@vger.kernel.org # 5.5+
      Signed-off-by: NPavel Begunkov <asml.silence@gmail.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NChen Jun <chenjun102@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      db9b4d68
    • P
      io_uring: inline io_uring_attempt_task_drop() · 8157becf
      Pavel Begunkov 提交于
      stable inclusion
      from stable-5.10.12
      commit 18f31594ee52ed1f364e376767fb839935fd899c
      bugzilla: 47876
      
      --------------------------------
      
      [ Upstream commit 4f793dc4 ]
      
      A simple preparation change inlining io_uring_attempt_task_drop() into
      io_uring_flush().
      
      Cc: stable@vger.kernel.org # 5.5+
      Signed-off-by: NPavel Begunkov <asml.silence@gmail.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NChen Jun <chenjun102@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      8157becf
    • P
      io_uring: fix short read retries for non-reg files · 3b0df637
      Pavel Begunkov 提交于
      stable inclusion
      from stable-5.10.11
      commit 2df15ef2a9cc58142d7acf1393db3fe5434f44c2
      bugzilla: 47621
      
      --------------------------------
      
      commit 9a173346 upstream.
      
      Sockets and other non-regular files may actually expect short reads to
      happen, don't retry reads for them. Because non-reg files don't set
      FMODE_BUF_RASYNC and so it won't do second/retry do_read, we can filter
      out those cases after first do_read() attempt with ret>0.
      
      Cc: stable@vger.kernel.org # 5.9+
      Suggested-by: NJens Axboe <axboe@kernel.dk>
      Signed-off-by: NPavel Begunkov <asml.silence@gmail.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      3b0df637
    • J
      io_uring: fix SQPOLL IORING_OP_CLOSE cancelation state · dd91344e
      Jens Axboe 提交于
      stable inclusion
      from stable-5.10.11
      commit f3ac7a5996d7cd739664c5f71cab4f8da03937e7
      bugzilla: 47621
      
      --------------------------------
      
      commit 607ec89e upstream.
      
      IORING_OP_CLOSE is special in terms of cancelation, since it has an
      intermediate state where we've removed the file descriptor but hasn't
      closed the file yet. For that reason, it's currently marked with
      IO_WQ_WORK_NO_CANCEL to prevent cancelation. This ensures that the op
      is always run even if canceled, to prevent leaving us with a live file
      but an fd that is gone. However, with SQPOLL, since a cancel request
      doesn't carry any resources on behalf of the request being canceled, if
      we cancel before any of the close op has been run, we can end up with
      io-wq not having the ->files assigned. This can result in the following
      oops reported by Joseph:
      
      BUG: kernel NULL pointer dereference, address: 00000000000000d8
      PGD 800000010b76f067 P4D 800000010b76f067 PUD 10b462067 PMD 0
      Oops: 0000 [#1] SMP PTI
      CPU: 1 PID: 1788 Comm: io_uring-sq Not tainted 5.11.0-rc4 #1
      Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011
      RIP: 0010:__lock_acquire+0x19d/0x18c0
      Code: 00 00 8b 1d fd 56 dd 08 85 db 0f 85 43 05 00 00 48 c7 c6 98 7b 95 82 48 c7 c7 57 96 93 82 e8 9a bc f5 ff 0f 0b e9 2b 05 00 00 <48> 81 3f c0 ca 67 8a b8 00 00 00 00 41 0f 45 c0 89 04 24 e9 81 fe
      RSP: 0018:ffffc90001933828 EFLAGS: 00010002
      RAX: 0000000000000001 RBX: 0000000000000001 RCX: 0000000000000000
      RDX: 0000000000000000 RSI: 0000000000000000 RDI: 00000000000000d8
      RBP: 0000000000000246 R08: 0000000000000001 R09: 0000000000000000
      R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000
      R13: 0000000000000000 R14: ffff888106e8a140 R15: 00000000000000d8
      FS:  0000000000000000(0000) GS:ffff88813bd00000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 00000000000000d8 CR3: 0000000106efa004 CR4: 00000000003706e0
      DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
      DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
      Call Trace:
       lock_acquire+0x31a/0x440
       ? close_fd_get_file+0x39/0x160
       ? __lock_acquire+0x647/0x18c0
       _raw_spin_lock+0x2c/0x40
       ? close_fd_get_file+0x39/0x160
       close_fd_get_file+0x39/0x160
       io_issue_sqe+0x1334/0x14e0
       ? lock_acquire+0x31a/0x440
       ? __io_free_req+0xcf/0x2e0
       ? __io_free_req+0x175/0x2e0
       ? find_held_lock+0x28/0xb0
       ? io_wq_submit_work+0x7f/0x240
       io_wq_submit_work+0x7f/0x240
       io_wq_cancel_cb+0x161/0x580
       ? io_wqe_wake_worker+0x114/0x360
       ? io_uring_get_socket+0x40/0x40
       io_async_find_and_cancel+0x3b/0x140
       io_issue_sqe+0xbe1/0x14e0
       ? __lock_acquire+0x647/0x18c0
       ? __io_queue_sqe+0x10b/0x5f0
       __io_queue_sqe+0x10b/0x5f0
       ? io_req_prep+0xdb/0x1150
       ? mark_held_locks+0x6d/0xb0
       ? mark_held_locks+0x6d/0xb0
       ? io_queue_sqe+0x235/0x4b0
       io_queue_sqe+0x235/0x4b0
       io_submit_sqes+0xd7e/0x12a0
       ? _raw_spin_unlock_irq+0x24/0x30
       ? io_sq_thread+0x3ae/0x940
       io_sq_thread+0x207/0x940
       ? do_wait_intr_irq+0xc0/0xc0
       ? __ia32_sys_io_uring_enter+0x650/0x650
       kthread+0x134/0x180
       ? kthread_create_worker_on_cpu+0x90/0x90
       ret_from_fork+0x1f/0x30
      
      Fix this by moving the IO_WQ_WORK_NO_CANCEL until _after_ we've modified
      the fdtable. Canceling before this point is totally fine, and running
      it in the io-wq context _after_ that point is also fine.
      
      For 5.12, we'll handle this internally and get rid of the no-cancel
      flag, as IORING_OP_CLOSE is the only user of it.
      
      Cc: stable@vger.kernel.org
      Fixes: b5dba59e ("io_uring: add support for IORING_OP_CLOSE")
      Reported-by: "Abaci <abaci@linux.alibaba.com>"
      Reviewed-and-tested-by: NJoseph Qi <joseph.qi@linux.alibaba.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      dd91344e
    • J
      io_uring: iopoll requests should also wake task ->in_idle state · f7aecdbf
      Jens Axboe 提交于
      stable inclusion
      from stable-5.10.11
      commit ca75872dd9f3db7893113b8fca6f2c874a4cbccf
      bugzilla: 47621
      
      --------------------------------
      
      commit c93cc9e1 upstream.
      
      If we're freeing/finishing iopoll requests, ensure we check if the task
      is in idling in terms of cancelation. Otherwise we could end up waiting
      forever in __io_uring_task_cancel() if the task has active iopoll
      requests that need cancelation.
      
      Cc: stable@vger.kernel.org # 5.9+
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      f7aecdbf
    • M
      io_uring: flush timeouts that should already have expired · 057d754e
      Marcelo Diop-Gonzalez 提交于
      stable inclusion
      from stable-5.10.11
      commit 2ca824c79376453e7e3df60437324b36043ff29b
      bugzilla: 47621
      
      --------------------------------
      
      [ Upstream commit f010505b ]
      
      Right now io_flush_timeouts() checks if the current number of events
      is equal to ->timeout.target_seq, but this will miss some timeouts if
      there have been more than 1 event added since the last time they were
      flushed (possible in io_submit_flush_completions(), for example). Fix
      it by recording the last sequence at which timeouts were flushed so
      that the number of events seen can be compared to the number of events
      needed without overflow.
      Signed-off-by: NMarcelo Diop-Gonzalez <marcelo827@gmail.com>
      Reviewed-by: NPavel Begunkov <asml.silence@gmail.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      057d754e
  2. 28 1月, 2021 3 次提交
  3. 27 1月, 2021 4 次提交
  4. 18 1月, 2021 7 次提交
    • P
      io_uring: remove racy overflow list fast checks · 6b0b39ed
      Pavel Begunkov 提交于
      stable inclusion
      from stable-5.10.5
      commit c7b04d27c9107fbc0d22dee67316f8584439df35
      bugzilla: 46931
      
      --------------------------------
      
      [ Upstream commit 9cd2be51 ]
      
      list_empty_careful() is not racy only if some conditions are met, i.e.
      no re-adds after del_init. io_cqring_overflow_flush() does list_move(),
      so it's actually racy.
      
      Remove those checks, we have ->cq_check_overflow for the fast path.
      Signed-off-by: NPavel Begunkov <asml.silence@gmail.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      Signed-off-by: NSasha Levin <sashal@kernel.org>
      Signed-off-by: NChen Jun <chenjun102@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      6b0b39ed
    • X
      io_uring: check kthread stopped flag when sq thread is unparked · c52fc272
      Xiaoguang Wang 提交于
      stable inclusion
      from stable-5.10.5
      commit b5a2f093b6b16db004619d6403f68c75ee85d794
      bugzilla: 46931
      
      --------------------------------
      
      commit 65b2b213 upstream.
      
      syzbot reports following issue:
      INFO: task syz-executor.2:12399 can't die for more than 143 seconds.
      task:syz-executor.2  state:D stack:28744 pid:12399 ppid:  8504 flags:0x00004004
      Call Trace:
       context_switch kernel/sched/core.c:3773 [inline]
       __schedule+0x893/0x2170 kernel/sched/core.c:4522
       schedule+0xcf/0x270 kernel/sched/core.c:4600
       schedule_timeout+0x1d8/0x250 kernel/time/timer.c:1847
       do_wait_for_common kernel/sched/completion.c:85 [inline]
       __wait_for_common kernel/sched/completion.c:106 [inline]
       wait_for_common kernel/sched/completion.c:117 [inline]
       wait_for_completion+0x163/0x260 kernel/sched/completion.c:138
       kthread_stop+0x17a/0x720 kernel/kthread.c:596
       io_put_sq_data fs/io_uring.c:7193 [inline]
       io_sq_thread_stop+0x452/0x570 fs/io_uring.c:7290
       io_finish_async fs/io_uring.c:7297 [inline]
       io_sq_offload_create fs/io_uring.c:8015 [inline]
       io_uring_create fs/io_uring.c:9433 [inline]
       io_uring_setup+0x19b7/0x3730 fs/io_uring.c:9507
       do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
       entry_SYSCALL_64_after_hwframe+0x44/0xa9
      RIP: 0033:0x45deb9
      Code: Unable to access opcode bytes at RIP 0x45de8f.
      RSP: 002b:00007f174e51ac78 EFLAGS: 00000246 ORIG_RAX: 00000000000001a9
      RAX: ffffffffffffffda RBX: 0000000000008640 RCX: 000000000045deb9
      RDX: 0000000000000000 RSI: 0000000020000140 RDI: 00000000000050e5
      RBP: 000000000118bf58 R08: 0000000000000000 R09: 0000000000000000
      R10: 0000000000000000 R11: 0000000000000246 R12: 000000000118bf2c
      R13: 00007ffed9ca723f R14: 00007f174e51b9c0 R15: 000000000118bf2c
      INFO: task syz-executor.2:12399 blocked for more than 143 seconds.
            Not tainted 5.10.0-rc3-next-20201110-syzkaller #0
      "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
      
      Currently we don't have a reproducer yet, but seems that there is a
      race in current codes:
      => io_put_sq_data
            ctx_list is empty now.       |
      ==> kthread_park(sqd->thread);     |
                                         | T1: sq thread is parked now.
      ==> kthread_stop(sqd->thread);     |
          KTHREAD_SHOULD_STOP is set now.|
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      
      ===> kthread_unpark(k);            |
                                         | T2: sq thread is now unparkd, run again.
                                         |
                                         | T3: sq thread is now preempted out.
                                         |
      ===> wake_up_process(k);           |
                                         |
                                         | T4: Since sqd ctx_list is empty, needs_sched will be true,
                                         | then sq thread sets task state to TASK_INTERRUPTIBLE,
                                         | and schedule, now sq thread will never be waken up.
      ===> wait_for_completion           |
      
      I have artificially used mdelay() to simulate above race, will get same
      stack like this syzbot report, but to be honest, I'm not sure this code
      race triggers syzbot report.
      
      To fix this possible code race, when sq thread is unparked, need to check
      whether sq thread has been stopped.
      
      Reported-by: syzbot+03beeb595f074db9cfd1@syzkaller.appspotmail.com
      Signed-off-by: NXiaoguang Wang <xiaoguang.wang@linux.alibaba.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NChen Jun <chenjun102@huawei.com>
      c52fc272
    • P
      io_uring: fix io_sqe_files_unregister() hangs · 72779b06
      Pavel Begunkov 提交于
      stable inclusion
      from stable-5.10.5
      commit ce00a7d0d9523192d0a9dd954f9993358f19a536
      bugzilla: 46931
      
      --------------------------------
      
      commit 1ffc5422 upstream.
      
      io_sqe_files_unregister() uninterruptibly waits for enqueued ref nodes,
      however requests keeping them may never complete, e.g. because of some
      userspace dependency. Make sure it's interruptible otherwise it would
      hang forever.
      
      Cc: stable@vger.kernel.org # 5.6+
      Signed-off-by: NPavel Begunkov <asml.silence@gmail.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NChen Jun <chenjun102@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      72779b06
    • P
      io_uring: add a helper for setting a ref node · dd81dbb9
      Pavel Begunkov 提交于
      stable inclusion
      from stable-5.10.5
      commit b25b86936a8dccd6f6ec9045bede4774b6c7c7cf
      bugzilla: 46931
      
      --------------------------------
      
      commit 1642b445 upstream.
      
      Setting a new reference node to a file data is not trivial, don't repeat
      it, add and use a helper.
      
      Cc: stable@vger.kernel.org # 5.6+
      Signed-off-by: NPavel Begunkov <asml.silence@gmail.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NChen Jun <chenjun102@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      dd81dbb9
    • J
      io_uring: use bottom half safe lock for fixed file data · 94fe557f
      Jens Axboe 提交于
      stable inclusion
      from stable-5.10.5
      commit 25a2de679b5d55ead2f99881c7d3e9b745325f39
      bugzilla: 46931
      
      --------------------------------
      
      commit ac0648a5 upstream.
      
      io_file_data_ref_zero() can be invoked from soft-irq from the RCU core,
      hence we need to ensure that the file_data lock is bottom half safe. Use
      the _bh() variants when grabbing this lock.
      
      Reported-by: syzbot+1f4ba1e5520762c523c6@syzkaller.appspotmail.com
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NChen Jun <chenjun102@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      94fe557f
    • J
      io_uring: don't assume mm is constant across submits · 8b40a98b
      Jens Axboe 提交于
      stable inclusion
      from stable-5.10.5
      commit 7247bc60e8e1458d89ea53179fce02d2307aac7f
      bugzilla: 46931
      
      --------------------------------
      
      commit 77788775 upstream.
      
      If we COW the identity, we assume that ->mm never changes. But this
      isn't true of multiple processes end up sharing the ring. Hence treat
      id->mm like like any other process compontent when it comes to the
      identity mapping. This is pretty trivial, just moving the existing grab
      into io_grab_identity(), and including a check for the match.
      
      Cc: stable@vger.kernel.org # 5.10
      Fixes: 1e6fa521 ("io_uring: COW io_identity on mismatch")
      Reported-by: Christian Brauner <christian.brauner@ubuntu.com>:
      Tested-by: Christian Brauner <christian.brauner@ubuntu.com>:
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NChen Jun <chenjun102@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      8b40a98b
    • P
      io_uring: close a small race gap for files cancel · b3818042
      Pavel Begunkov 提交于
      stable inclusion
      from stable-5.10.5
      commit 52504a61ab999289d406f5dec930d3e3f386365d
      bugzilla: 46931
      
      --------------------------------
      
      commit dfea9fce upstream.
      
      The purpose of io_uring_cancel_files() is to wait for all requests
      matching ->files to go/be cancelled. We should first drop files of a
      request in io_req_drop_files() and only then make it undiscoverable for
      io_uring_cancel_files.
      
      First drop, then delete from list. It's ok to leave req->id->files
      dangling, because it's not dereferenced by cancellation code, only
      compared against. It would potentially go to sleep and be awaken by
      following in io_req_drop_files() wake_up().
      
      Fixes: 0f212204 ("io_uring: don't rely on weak ->files references")
      Cc: <stable@vger.kernel.org> # 5.5+
      Signed-off-by: NPavel Begunkov <asml.silence@gmail.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NChen Jun <chenjun102@huawei.com>
      Acked-by: NXie XiuQi <xiexiuqi@huawei.com>
      b3818042
  5. 12 1月, 2021 11 次提交
  6. 08 12月, 2020 1 次提交
    • H
      io_uring: fix file leak on error path of io ctx creation · f26c08b4
      Hillf Danton 提交于
      Put file as part of error handling when setting up io ctx to fix
      memory leaks like the following one.
      
         BUG: memory leak
         unreferenced object 0xffff888101ea2200 (size 256):
           comm "syz-executor355", pid 8470, jiffies 4294953658 (age 32.400s)
           hex dump (first 32 bytes):
             00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
             20 59 03 01 81 88 ff ff 80 87 a8 10 81 88 ff ff   Y..............
           backtrace:
             [<000000002e0a7c5f>] kmem_cache_zalloc include/linux/slab.h:654 [inline]
             [<000000002e0a7c5f>] __alloc_file+0x1f/0x130 fs/file_table.c:101
             [<000000001a55b73a>] alloc_empty_file+0x69/0x120 fs/file_table.c:151
             [<00000000fb22349e>] alloc_file+0x33/0x1b0 fs/file_table.c:193
             [<000000006e1465bb>] alloc_file_pseudo+0xb2/0x140 fs/file_table.c:233
             [<000000007118092a>] anon_inode_getfile fs/anon_inodes.c:91 [inline]
             [<000000007118092a>] anon_inode_getfile+0xaa/0x120 fs/anon_inodes.c:74
             [<000000002ae99012>] io_uring_get_fd fs/io_uring.c:9198 [inline]
             [<000000002ae99012>] io_uring_create fs/io_uring.c:9377 [inline]
             [<000000002ae99012>] io_uring_setup+0x1125/0x1630 fs/io_uring.c:9411
             [<000000008280baad>] do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46
             [<00000000685d8cf0>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
      
      Reported-by: syzbot+71c4697e27c99fddcf17@syzkaller.appspotmail.com
      Fixes: 0f212204 ("io_uring: don't rely on weak ->files references")
      Cc: Pavel Begunkov <asml.silence@gmail.com>
      Signed-off-by: NHillf Danton <hdanton@sina.com>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      f26c08b4
  7. 07 12月, 2020 1 次提交
  8. 01 12月, 2020 1 次提交