1. 09 8月, 2021 2 次提交
    • N
      io_uring: Use WRITE_ONCE() when writing to sq_flags · 20c0b380
      Nadav Amit 提交于
      The compiler should be forbidden from any strange optimization for async
      writes to user visible data-structures. Without proper protection, the
      compiler can cause write-tearing or invent writes that would confuse the
      userspace.
      
      However, there are writes to sq_flags which are not protected by
      WRITE_ONCE(). Use WRITE_ONCE() for these writes.
      
      This is purely a theoretical issue. Presumably, any compiler is very
      unlikely to do such optimizations.
      
      Fixes: 75b28aff ("io_uring: allocate the two rings together")
      Cc: Jens Axboe <axboe@kernel.dk>
      Cc: Pavel Begunkov <asml.silence@gmail.com>
      Signed-off-by: NNadav Amit <namit@vmware.com>
      Link: https://lore.kernel.org/r/20210808001342.964634-3-namit@vmware.comSigned-off-by: NJens Axboe <axboe@kernel.dk>
      20c0b380
    • N
      io_uring: clear TIF_NOTIFY_SIGNAL when running task work · ef98eb04
      Nadav Amit 提交于
      When using SQPOLL, the submission queue polling thread calls
      task_work_run() to run queued work. However, when work is added with
      TWA_SIGNAL - as done by io_uring itself - the TIF_NOTIFY_SIGNAL remains
      set afterwards and is never cleared.
      
      Consequently, when the submission queue polling thread checks whether
      signal_pending(), it may always find a pending signal, if
      task_work_add() was ever called before.
      
      The impact of this bug might be different on different kernel versions.
      It appears that on 5.14 it would only cause unnecessary calculation and
      prevent the polling thread from sleeping. On 5.13, where the bug was
      found, it stops the polling thread from finding newly submitted work.
      
      Instead of task_work_run(), use tracehook_notify_signal() that clears
      TIF_NOTIFY_SIGNAL. Test for TIF_NOTIFY_SIGNAL in addition to
      current->task_works to avoid a race in which task_works is cleared but
      the TIF_NOTIFY_SIGNAL is set.
      
      Fixes: 685fe7fe ("io-wq: eliminate the need for a manager thread")
      Cc: Jens Axboe <axboe@kernel.dk>
      Cc: Pavel Begunkov <asml.silence@gmail.com>
      Signed-off-by: NNadav Amit <namit@vmware.com>
      Link: https://lore.kernel.org/r/20210808001342.964634-2-namit@vmware.comSigned-off-by: NJens Axboe <axboe@kernel.dk>
      ef98eb04
  2. 28 7月, 2021 3 次提交
  3. 27 7月, 2021 1 次提交
  4. 26 7月, 2021 1 次提交
  5. 24 7月, 2021 2 次提交
  6. 23 7月, 2021 1 次提交
  7. 20 7月, 2021 3 次提交
    • Y
      io_uring: fix memleak in io_init_wq_offload() · 362a9e65
      Yang Yingliang 提交于
      I got memory leak report when doing fuzz test:
      
      BUG: memory leak
      unreferenced object 0xffff888107310a80 (size 96):
      comm "syz-executor.6", pid 4610, jiffies 4295140240 (age 20.135s)
      hex dump (first 32 bytes):
      01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
      00 00 00 00 ad 4e ad de ff ff ff ff 00 00 00 00 .....N..........
      backtrace:
      [<000000001974933b>] kmalloc include/linux/slab.h:591 [inline]
      [<000000001974933b>] kzalloc include/linux/slab.h:721 [inline]
      [<000000001974933b>] io_init_wq_offload fs/io_uring.c:7920 [inline]
      [<000000001974933b>] io_uring_alloc_task_context+0x466/0x640 fs/io_uring.c:7955
      [<0000000039d0800d>] __io_uring_add_tctx_node+0x256/0x360 fs/io_uring.c:9016
      [<000000008482e78c>] io_uring_add_tctx_node fs/io_uring.c:9052 [inline]
      [<000000008482e78c>] __do_sys_io_uring_enter fs/io_uring.c:9354 [inline]
      [<000000008482e78c>] __se_sys_io_uring_enter fs/io_uring.c:9301 [inline]
      [<000000008482e78c>] __x64_sys_io_uring_enter+0xabc/0xc20 fs/io_uring.c:9301
      [<00000000b875f18f>] do_syscall_x64 arch/x86/entry/common.c:50 [inline]
      [<00000000b875f18f>] do_syscall_64+0x3b/0x90 arch/x86/entry/common.c:80
      [<000000006b0a8484>] entry_SYSCALL_64_after_hwframe+0x44/0xae
      
      CPU0                          CPU1
      io_uring_enter                io_uring_enter
      io_uring_add_tctx_node        io_uring_add_tctx_node
      __io_uring_add_tctx_node      __io_uring_add_tctx_node
      io_uring_alloc_task_context   io_uring_alloc_task_context
      io_init_wq_offload            io_init_wq_offload
      hash = kzalloc                hash = kzalloc
      ctx->hash_map = hash          ctx->hash_map = hash <- one of the hash is leaked
      
      When calling io_uring_enter() in parallel, the 'hash_map' will be leaked,
      add uring_lock to protect 'hash_map'.
      
      Fixes: e941894e ("io-wq: make buffered file write hashed work map per-ctx")
      Reported-by: NHulk Robot <hulkci@huawei.com>
      Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
      Reviewed-by: NPavel Begunkov <asml.silence@gmail.com>
      Link: https://lore.kernel.org/r/20210720083805.3030730-1-yangyingliang@huawei.comSigned-off-by: NJens Axboe <axboe@kernel.dk>
      362a9e65
    • P
      io_uring: remove double poll entry on arm failure · 46fee9ab
      Pavel Begunkov 提交于
      __io_queue_proc() can enqueue both poll entries and still fail
      afterwards, so the callers trying to cancel it should also try to remove
      the second poll entry (if any).
      
      For example, it may leave the request alive referencing a io_uring
      context but not accessible for cancellation:
      
      [  282.599913][ T1620] task:iou-sqp-23145   state:D stack:28720 pid:23155 ppid:  8844 flags:0x00004004
      [  282.609927][ T1620] Call Trace:
      [  282.613711][ T1620]  __schedule+0x93a/0x26f0
      [  282.634647][ T1620]  schedule+0xd3/0x270
      [  282.638874][ T1620]  io_uring_cancel_generic+0x54d/0x890
      [  282.660346][ T1620]  io_sq_thread+0xaac/0x1250
      [  282.696394][ T1620]  ret_from_fork+0x1f/0x30
      
      Cc: stable@vger.kernel.org
      Fixes: 18bceab1 ("io_uring: allow POLL_ADD with double poll_wait() users")
      Reported-and-tested-by: syzbot+ac957324022b7132accf@syzkaller.appspotmail.com
      Signed-off-by: NPavel Begunkov <asml.silence@gmail.com>
      Link: https://lore.kernel.org/r/0ec1228fc5eda4cb524eeda857da8efdc43c331c.1626774457.git.asml.silence@gmail.comSigned-off-by: NJens Axboe <axboe@kernel.dk>
      46fee9ab
    • P
      io_uring: explicitly count entries for poll reqs · 68b11e8b
      Pavel Begunkov 提交于
      If __io_queue_proc() fails to add a second poll entry, e.g. kmalloc()
      failed, but it goes on with a third waitqueue, it may succeed and
      overwrite the error status. Count the number of poll entries we added,
      so we can set pt->error to zero at the beginning and find out when the
      mentioned scenario happens.
      
      Cc: stable@vger.kernel.org
      Fixes: 18bceab1 ("io_uring: allow POLL_ADD with double poll_wait() users")
      Signed-off-by: NPavel Begunkov <asml.silence@gmail.com>
      Link: https://lore.kernel.org/r/9d6b9e561f88bcc0163623b74a76c39f712151c3.1626774457.git.asml.silence@gmail.comSigned-off-by: NJens Axboe <axboe@kernel.dk>
      68b11e8b
  8. 12 7月, 2021 2 次提交
  9. 09 7月, 2021 2 次提交
  10. 08 7月, 2021 1 次提交
  11. 02 7月, 2021 3 次提交
  12. 01 7月, 2021 16 次提交
  13. 24 6月, 2021 2 次提交
  14. 18 6月, 2021 1 次提交