->flush() fixes
cover ->flush() fixes
It might fix flush() problems reported by syzkaller, but I haven't verified it. Jens, please tell if there was a good reason to have io_sq_thread_stop() in io_uring_flush().
Pavel Begunkov (2):
io_uring: fix use-after-free ->files
io_uring: fix unsynchronised removal of sq_data
fs/io_uring.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
Signature · 1 line
2.24.0
PATCH 1/2 io_uring: fix use-after-free ->files
io_uring_flush() should first clear ->sqo_files and only then trying to cancel requests with io_uring_cancel_files(). Otherwise, SQ thread may wake up right after io_uring_cancel_file() and submit new requests with the going away files.
--- fs/io_uring.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/io_uring.c +2 -2
@@ -8548,8 +8548,6 @@ static int io_uring_flush(struct file *file, void *data) {struct io_ring_ctx *ctx = file->private_data; -io_uring_cancel_files (ctx, data); -/* * If the task is going away, cancel work it may have pending */
@@ -8570,6 +8568,8 @@ static int io_uring_flush(struct file *file, void *data)io_sq_thread_unpark (sqd); } +io_uring_cancel_files (ctx, data); +return 0 ; }
Signature · 1 line
2.24.0
PATCH 2/2 io_uring: fix unsynchronised removal of sq_data
In reply to Pavel BegunkovRemove io_sq_thread_stop() from io_uring_flush() and just clear ->sqo_files, etc. instead. The first reason is that io_sq_thread_stop() null's ctx->sq_data without any lock held, that's racy. Also, it kills an SQPOLL thread even though there may be other processes wanting to continue using the io_uring instance.
--- fs/io_uring.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
fs/io_uring.c +7 -7
@@ -8548,13 +8548,7 @@ static int io_uring_flush(struct file *file, void *data) {struct io_ring_ctx *ctx = file->private_data; -/* -* If the task is going away, cancel work it may have pending -*/ -if (fatal_signal_pending (current) || (current->flags &PF_EXITING )) { -io_sq_thread_stop (ctx); -io_wq_cancel_cb (ctx->io_wq, io_cancel_task_cb, current, true); - }else if (ctx->flags &IORING_SETUP_SQPOLL ) { +if (ctx->flags &IORING_SETUP_SQPOLL ) {struct io_sq_data *sqd = ctx->sq_data;/* Ring is being closed, mark us as neding new assignment */
@@ -8568,6 +8562,12 @@ static int io_uring_flush(struct file *file, void *data)io_sq_thread_unpark (sqd); } +/* +* If the task is going away, cancel work it may have pending +*/ +if (fatal_signal_pending (current) || (current->flags &PF_EXITING )) +io_wq_cancel_cb (ctx->io_wq, io_cancel_task_cb, current, true); +io_uring_cancel_files (ctx, data);return 0 ;
Signature · 1 line
2.24.0
Quoted 3 lines · Pavel Begunkov
It might fix
flush()problems reported by syzkaller, but I haven't verified it. Jens, please tell if there was a good reason to haveio_sq_thread_stop()inio_uring_flush().
It looks like it shouldn't be a problem removing it, because an sqpoll task sets req->task to itself, and such requests are cancelled and waited by io_uring_release() if that is required.
Quoted 8 lines
Pavel Begunkov (2):
io_uring: fix use-after-free ->files
io_uring: fix unsynchronised removal ofsq_datafs/io_uring.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
Signature · 1 line
Pavel Begunkov
Jens Axboe
maintainerQuoted 3 lines · Pavel Begunkov
It might fix
flush()problems reported by syzkaller, but I haven't verified it. Jens, please tell if there was a good reason to haveio_sq_thread_stop()inio_uring_flush().
No, it's not needed.
Signature · 1 line
Jens Axboe