block: fix ioprio_get(IOPRIO_WHO_PGRP) vs setuid(2)
PATCH 1/1 block: fix ioprio_get(IOPRIO_WHO_PGRP) vs setuid(2)
do_each_pid_thread(PIDTYPE_PGID) can race with a concurrent change_pid(PIDTYPE_PGID) that can move the task from one hlist to another while iterating. Serialize ioprio_get to take the tasklist_lock in this case, just like it's set counterpart.
---
This is basically a resend of https://lore.kernel.org/all/[email protected]/
with Oleg's ack and without the ioprio_set part as this was fixed
later after this patch was lost for whatever reason.
block/ioprio.c | 3 +++ 1 file changed, 3 insertions(+)
block/ioprio.c +3 -0
@@ -220,6 +220,7 @@ SYSCALL_DEFINE2(ioprio_get, int, which, int, who) pgrp =task_pgrp (current); else pgrp =find_vpid (who); +read_lock (&tasklist_lock); do_each_pid_thread(pgrp, PIDTYPE_PGID, p) { tmpio =get_task_ioprio (p);if (tmpio <0 )
@@ -229,6 +230,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which, int, who)else ret =ioprio_best (ret, tmpio); }while_each_pid_thread (pgrp,PIDTYPE_PGID , p); +read_unlock (&tasklist_lock); +break ;case IOPRIO_WHO_USER : uid =make_kuid (current_user_ns (), who);
Signature · 1 line
2.26.2
Quoted 6 lines · Davidlohr Bueso
do_each_pid_thread(PIDTYPE_PGID)can race with a concurrentchange_pid(PIDTYPE_PGID)that can move the task from one hlist to another while iterating. Serializeioprio_getto take thetasklist_lockin this case, just like it's set counterpart.
Applied, thanks!
[1/1] block: fix ioprio_get(IOPRIO_WHO_PGRP) vs setuid(2)
commit: e6a59aac8a8713f335a37d762db0dbe80e7f6d38
Best regards,
Signature · 1 line
Jens Axboe