io_uring: if we see flush on exit, cancel related tasks
authorJens Axboe <axboe@kernel.dk>
Sat, 23 Jan 2021 22:51:11 +0000 (15:51 -0700)
committerJens Axboe <axboe@kernel.dk>
Mon, 25 Jan 2021 01:13:56 +0000 (18:13 -0700)
Ensure we match tasks that belong to a dead or dying task as well, as we
need to reap those in addition to those belonging to the exiting task.

Cc: stable@vger.kernel.org # 5.9+
Reported-by: Josef Grieb <josef.grieb@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
fs/io_uring.c

index c07913ec0ccac43aa0f765ab9734c6ef1fab84c6..695fe00bafdcd46b7206e95735c684d61c4ad612 100644 (file)
@@ -1069,8 +1069,12 @@ static bool io_match_task(struct io_kiocb *head,
 {
        struct io_kiocb *req;
 
-       if (task && head->task != task)
+       if (task && head->task != task) {
+               /* in terms of cancelation, always match if req task is dead */
+               if (head->task->flags & PF_EXITING)
+                       return true;
                return false;
+       }
        if (!files)
                return true;
 
@@ -9136,6 +9140,9 @@ static int io_uring_flush(struct file *file, void *data)
        struct io_uring_task *tctx = current->io_uring;
        struct io_ring_ctx *ctx = file->private_data;
 
+       if (fatal_signal_pending(current) || (current->flags & PF_EXITING))
+               io_uring_cancel_task_requests(ctx, NULL);
+
        if (!tctx)
                return 0;