diff options
author | Peter Zijlstra <peterz@infradead.org> | 2021-04-08 12:46:12 +0300 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2021-04-08 22:43:53 +0300 |
commit | 40c7fd3fdfba97a18724a0b96d132335fd419e98 (patch) | |
tree | c7e5ed9dc17a58d49a9f5444c58bd311765d8a40 /block/ioprio.c | |
parent | 3212135a718b06be38811f2d9a320ae842e76409 (diff) | |
download | linux-40c7fd3fdfba97a18724a0b96d132335fd419e98.tar.xz |
block: Fix sys_ioprio_set(.which=IOPRIO_WHO_PGRP) task iteration
do_each_pid_thread() { } while_each_pid_thread() is a double loop and
thus break doesn't work as expected. Also, it should be used under
tasklist_lock because otherwise we can race against change_pid() for
PGID/SID.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/YG7Q5C4Rb5dx5GFx@hirez.programming.kicks-ass.net
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/ioprio.c')
-rw-r--r-- | block/ioprio.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/block/ioprio.c b/block/ioprio.c index 364d2294ba90..bee628f9f1b2 100644 --- a/block/ioprio.c +++ b/block/ioprio.c @@ -119,11 +119,17 @@ SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio) pgrp = task_pgrp(current); else pgrp = find_vpid(who); + + read_lock(&tasklist_lock); do_each_pid_thread(pgrp, PIDTYPE_PGID, p) { ret = set_task_ioprio(p, ioprio); - if (ret) - break; + if (ret) { + read_unlock(&tasklist_lock); + goto out; + } } while_each_pid_thread(pgrp, PIDTYPE_PGID, p); + read_unlock(&tasklist_lock); + break; case IOPRIO_WHO_USER: uid = make_kuid(current_user_ns(), who); @@ -153,6 +159,7 @@ free_uid: ret = -EINVAL; } +out: rcu_read_unlock(); return ret; } |