Skip to content

Commit 64e0253

Browse files
committed
Merge tag 'sched-urgent-2023-02-17' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull scheduler fixes from Ingo Molnar: - Fix user-after-free bug in call_usermodehelper_exec() - Fix missing user_cpus_ptr update in __set_cpus_allowed_ptr_locked() - Fix PSI use-after-free bug in ep_remove_wait_queue() * tag 'sched-urgent-2023-02-17' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: sched/psi: Fix use-after-free in ep_remove_wait_queue() sched/core: Fix a missed update of user_cpus_ptr freezer,umh: Fix call_usermode_helper_exec() vs SIGKILL
2 parents ec35307 + c2dbe32 commit 64e0253

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

kernel/sched/core.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2951,8 +2951,11 @@ static int __set_cpus_allowed_ptr_locked(struct task_struct *p,
29512951
}
29522952

29532953
if (!(ctx->flags & SCA_MIGRATE_ENABLE)) {
2954-
if (cpumask_equal(&p->cpus_mask, ctx->new_mask))
2954+
if (cpumask_equal(&p->cpus_mask, ctx->new_mask)) {
2955+
if (ctx->flags & SCA_USER)
2956+
swap(p->user_cpus_ptr, ctx->user_mask);
29552957
goto out;
2958+
}
29562959

29572960
if (WARN_ON_ONCE(p == current &&
29582961
is_migration_disabled(p) &&

kernel/sched/psi.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,10 +1343,11 @@ void psi_trigger_destroy(struct psi_trigger *t)
13431343

13441344
group = t->group;
13451345
/*
1346-
* Wakeup waiters to stop polling. Can happen if cgroup is deleted
1347-
* from under a polling process.
1346+
* Wakeup waiters to stop polling and clear the queue to prevent it from
1347+
* being accessed later. Can happen if cgroup is deleted from under a
1348+
* polling process.
13481349
*/
1349-
wake_up_interruptible(&t->event_wait);
1350+
wake_up_pollfree(&t->event_wait);
13501351

13511352
mutex_lock(&group->trigger_lock);
13521353

kernel/umh.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -438,21 +438,27 @@ int call_usermodehelper_exec(struct subprocess_info *sub_info, int wait)
438438
if (wait == UMH_NO_WAIT) /* task has freed sub_info */
439439
goto unlock;
440440

441-
if (wait & UMH_KILLABLE)
442-
state |= TASK_KILLABLE;
443-
444441
if (wait & UMH_FREEZABLE)
445442
state |= TASK_FREEZABLE;
446443

447-
retval = wait_for_completion_state(&done, state);
448-
if (!retval)
449-
goto wait_done;
450-
451444
if (wait & UMH_KILLABLE) {
445+
retval = wait_for_completion_state(&done, state | TASK_KILLABLE);
446+
if (!retval)
447+
goto wait_done;
448+
452449
/* umh_complete() will see NULL and free sub_info */
453450
if (xchg(&sub_info->complete, NULL))
454451
goto unlock;
452+
453+
/*
454+
* fallthrough; in case of -ERESTARTSYS now do uninterruptible
455+
* wait_for_completion_state(). Since umh_complete() shall call
456+
* complete() in a moment if xchg() above returned NULL, this
457+
* uninterruptible wait_for_completion_state() will not block
458+
* SIGKILL'ed processes for long.
459+
*/
455460
}
461+
wait_for_completion_state(&done, state);
456462

457463
wait_done:
458464
retval = sub_info->retval;

0 commit comments

Comments
 (0)