block: fix error in handling dead task for ioprio setting
authorJens Axboe <axboe@kernel.dk>
Tue, 21 Dec 2021 03:32:24 +0000 (20:32 -0700)
committerJens Axboe <axboe@kernel.dk>
Tue, 21 Dec 2021 03:32:24 +0000 (20:32 -0700)
Don't combine the task exiting and "already have io_context" case, we
need to just abort if the task is marked as dead. Return -ESRCH, which
is the documented value for ioprio_set() if the specified task could not
be found.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Reported-by: syzbot+8836466a79f4175961b0@syzkaller.appspotmail.com
Fixes: 5fc11eebb4a9 ("block: open code create_task_io_context in set_task_ioprio")
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-ioc.c

index 87bdc9ca82959987c60797926430b98fb751c19b..71c3a933cf161c3b9f11c9e827ef2e06ca8e2b60 100644 (file)
@@ -279,7 +279,12 @@ int set_task_ioprio(struct task_struct *task, int ioprio)
                        return -ENOMEM;
 
                task_lock(task);
-               if (task->io_context || (task->flags & PF_EXITING)) {
+               if (task->flags & PF_EXITING) {
+                       err = -ESRCH;
+                       kmem_cache_free(iocontext_cachep, ioc);
+                       goto out;
+               }
+               if (task->io_context) {
                        kmem_cache_free(iocontext_cachep, ioc);
                        ioc = task->io_context;
                } else {
@@ -287,8 +292,9 @@ int set_task_ioprio(struct task_struct *task, int ioprio)
                }
        }
        task->io_context->ioprio = ioprio;
+out:
        task_unlock(task);
-       return 0;
+       return err;
 }
 EXPORT_SYMBOL_GPL(set_task_ioprio);