acrn-kernel/kernel/sched
Suren Baghdasaryan aff037078e sched/psi: use kernfs polling functions for PSI trigger polling
Destroying psi trigger in cgroup_file_release causes UAF issues when
a cgroup is removed from under a polling process. This is happening
because cgroup removal causes a call to cgroup_file_release while the
actual file is still alive. Destroying the trigger at this point would
also destroy its waitqueue head and if there is still a polling process
on that file accessing the waitqueue, it will step on the freed pointer:

do_select
  vfs_poll
                           do_rmdir
                             cgroup_rmdir
                               kernfs_drain_open_files
                                 cgroup_file_release
                                   cgroup_pressure_release
                                     psi_trigger_destroy
                                       wake_up_pollfree(&t->event_wait)
// vfs_poll is unblocked
                                       synchronize_rcu
                                       kfree(t)
  poll_freewait -> UAF access to the trigger's waitqueue head

Patch [1] fixed this issue for epoll() case using wake_up_pollfree(),
however the same issue exists for synchronous poll() case.
The root cause of this issue is that the lifecycles of the psi trigger's
waitqueue and of the file associated with the trigger are different. Fix
this by using kernfs_generic_poll function when polling on cgroup-specific
psi triggers. It internally uses kernfs_open_node->poll waitqueue head
with its lifecycle tied to the file's lifecycle. This also renders the
fix in [1] obsolete, so revert it.

[1] commit c2dbe32d5d ("sched/psi: Fix use-after-free in ep_remove_wait_queue()")

Fixes: 0e94682b73 ("psi: introduce psi monitor")
Closes: https://lore.kernel.org/all/20230613062306.101831-1-lujialin4@huawei.com/
Reported-by: Lu Jialin <lujialin4@huawei.com>
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20230630005612.1014540-1-surenb@google.com
2023-07-10 09:52:30 +02:00
..
Makefile
autogroup.c
autogroup.h
build_policy.c
build_utility.c
clock.c Locking changes for v6.5: 2023-06-27 14:14:30 -07:00
completion.c
core.c cgroup: Changes for v6.5 2023-06-27 16:54:21 -07:00
core_sched.c
cpuacct.c
cpudeadline.c
cpudeadline.h
cpufreq.c
cpufreq_schedutil.c sched/fair, cpufreq: Introduce 'runnable boosting' 2023-06-05 21:13:44 +02:00
cpupri.c
cpupri.h
cputime.c
deadline.c cgroup: Changes for v6.5 2023-06-27 16:54:21 -07:00
debug.c sched/debug: Correct printing for rq->nr_uninterruptible 2023-05-08 10:58:39 +02:00
fair.c sched/fair: Use recent_used_cpu to test p->cpus_ptr 2023-07-10 09:52:30 +02:00
features.h
idle.c
isolation.c
loadavg.c
membarrier.c
pelt.c
pelt.h
psi.c sched/psi: use kernfs polling functions for PSI trigger polling 2023-07-10 09:52:30 +02:00
rt.c
sched-pelt.h
sched.h cgroup: Changes for v6.5 2023-06-27 16:54:21 -07:00
smp.h
stats.c
stats.h
stop_task.c
swait.c
topology.c sched/core: Fixed missing rq clock update before calling set_rq_offline() 2023-06-16 22:08:12 +02:00
wait.c sched/wait: Fix a kthread_park race with wait_woken() 2023-06-16 17:08:01 +02:00
wait_bit.c