linux/kernel/sched
Tadeusz Struk 4c47eaa7c8 BACKPORT: sched/fair: Fix fault in reweight_entity
Syzbot found a GPF in reweight_entity. This has been bisected to
commit 4ef0c5c6b5 ("kernel/sched: Fix sched_fork() access an invalid
sched_task_group")

There is a race between sched_post_fork() and setpriority(PRIO_PGRP)
within a thread group that causes a null-ptr-deref in
reweight_entity() in CFS. The scenario is that the main process spawns
number of new threads, which then call setpriority(PRIO_PGRP, 0, -20),
wait, and exit.  For each of the new threads the copy_process() gets
invoked, which adds the new task_struct and calls sched_post_fork()
for it.

In the above scenario there is a possibility that
setpriority(PRIO_PGRP) and set_one_prio() will be called for a thread
in the group that is just being created by copy_process(), and for
which the sched_post_fork() has not been executed yet. This will
trigger a null pointer dereference in reweight_entity(), as it will
try to access the run queue pointer, which hasn't been set.

Before the mentioned change the cfs_rq pointer for the task  has been
set in sched_fork(), which is called much earlier in copy_process(),
before the new task is added to the thread_group.  Now it is done in
the sched_post_fork(), which is called after that.  To fix the issue
the remove the update_load param from the update_load param() function
and call reweight_task() only if the task flag doesn't have the
TASK_NEW flag set.

Change-Id: I5324ce174190919cec268c281fb92dfeee830b00
Fixes: 4ef0c5c6b5 ("kernel/sched: Fix sched_fork() access an invalid sched_task_group")
Reported-by: syzbot+af7a719bc92395ee41b3@syzkaller.appspotmail.com
Signed-off-by: Tadeusz Struk <tadeusz.struk@linaro.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: stable@vger.kernel.org
Link: https://lkml.kernel.org/r/20220203161846.1160750-1-tadeusz.struk@linaro.org
Bug: 219676849
(cherry picked from commit 13765de814)
[quic_ashayj: Resolved minor compilation failure, replaced __state to state ]
Signed-off-by: Ashay Jaiswal <quic_ashayj@quicinc.com>
2022-02-16 23:52:09 +05:30
..
autogroup.c
autogroup.h
clock.c
completion.c
core.c BACKPORT: sched/fair: Fix fault in reweight_entity 2022-02-16 23:52:09 +05:30
cpuacct.c
cpudeadline.c
cpudeadline.h
cpufreq_schedutil.c This is the 5.10.71 stable release 2021-10-06 17:33:06 +02:00
cpufreq.c ANDROID: android: Export symbols for invoking cpufreq_update_util() 2021-06-29 10:44:12 +00:00
cpupri.c ANDROID: sched: Export symbol for vendor RT hook funcion 2021-01-12 12:57:37 -08:00
cpupri.h
cputime.c ANDROID: vendor_hooks: Add hooks for account irqtime process tick 2021-05-13 08:26:15 +00:00
deadline.c This is the 5.10.65 stable release 2021-09-15 14:16:47 +02:00
debug.c This is the 5.10.44 stable release 2021-06-16 13:14:03 +02:00
fair.c Revert portions of "ANDROID: sched: Add vendor hooks for sched." 2022-01-20 10:04:49 +01:00
features.h Revert "Revert "sched,fair: Alternative sched_slice()"" 2021-05-21 13:17:06 -07:00
idle.c This is the 5.10.69 stable release 2021-09-30 18:36:17 +02:00
isolation.c
loadavg.c
Makefile
membarrier.c sched/membarrier: fix missing local execution of ipi_sync_rq_state() 2021-03-17 17:06:35 +01:00
pelt.c ANDROID: sched: add a helper function to change PELT half-life 2021-08-07 00:03:23 +08:00
pelt.h sched/fair: Fix util_est UTIL_AVG_UNCHANGED handling 2021-06-16 12:01:46 +02:00
psi.c Merge branch 'android12-5.10' into android12-5.10-lts 2021-07-15 17:17:09 +02:00
rt.c ANDROID: vendor_hooks: Add hooks to record the time of the process in various states 2021-11-11 22:15:49 +08:00
sched-pelt.h ANDROID: sched: pelt: Fix the PELT arrays 2021-03-04 11:53:51 +00:00
sched.h sched/deadline: Fix reset_on_fork reporting of DL tasks 2021-09-15 09:50:24 +02:00
smp.h
stats.c
stats.h
stop_task.c treewide: Convert macro and uses of __section(foo) to __section("foo") 2020-10-25 14:51:49 -07:00
swait.c
topology.c ANDROID: vendor_hooks: Add hooks for scheduler 2021-03-16 09:08:22 +00:00
wait_bit.c
wait.c UPSTREAM: wait: add wake_up_pollfree() 2021-12-14 13:54:22 +01:00