io_uring: close a small race gap for files cancel
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 io_uring: close a small race gap for files cancel
commit dfea9fce29fda6f2f91161677e0e0d9b671bc099 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().
--- fs/io_uring.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/io_uring.c +4 -4
@@ -5854,15 +5854,15 @@ static void io_req_drop_files(struct io_kiocb *req)struct io_ring_ctx *ctx = req->ctx;unsigned long flags; +put_files_struct (req->work.identity->files); +put_nsproxy (req->work.identity->nsproxy);spin_lock_irqsave (&ctx->inflight_lock, flags);list_del (&req->inflight_entry); -if (waitqueue_active (&ctx->inflight_wait)) -wake_up (&ctx->inflight_wait);spin_unlock_irqrestore (&ctx->inflight_lock, flags); req->flags &= ~REQ_F_INFLIGHT ; -put_files_struct (req->work.identity->files); -put_nsproxy (req->work.identity->nsproxy); req->work.flags &= ~IO_WQ_WORK_FILES ; +if (waitqueue_active (&ctx->inflight_wait)) +wake_up (&ctx->inflight_wait); }static void __io_clean_op (struct io_kiocb *req)
Signature · 1 line
2.24.0
Greg KH
maintainerQuoted 12 lines · Pavel Begunkov
commit
dfea9fce29fda6f2f91161677e0e0d9b671bc099upstream.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 inio_req_drop_files()and only then make it undiscoverable forio_uring_cancel_files.First drop, then delete from list. It's ok to leave
req->id->filesdangling, because it's not dereferenced by cancellation code, only compared against. It would potentially go to sleep and be awaken by following inio_req_drop_files()wake_up().
Quoted 7 lines
Fixes 0f2122045b946 ("io_uring: don't rely on weak ->files references")Cc <[email protected]> # 5.5+Signed-off-by Pavel Begunkov <[email protected]>Signed-off-by Jens Axboe <[email protected]>--- fs/io_uring.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Now applied, thanks.
greg k-h