From: Zheng Zucheng zhengzucheng@huawei.com
hulk inclusion category: bugfix bugzilla: 51828, https://gitee.com/openeuler/kernel/issues/I4K96G CVE: NA
--------------------------------
offline task invokes sched_setscheduler interface to change the scheduling policy to SCHED_OTHER, trigger a system panic.
Signed-off-by: Zheng Zucheng zhengzucheng@huawei.com Reviewed-by: Chen Hui judy.chenhui@huawei.com Reviewed-by: Xiu Jianfeng xiujianfeng@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- kernel/sched/core.c | 12 ++++++++++++ kernel/sched/fair.c | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 1e8fca9b53d84..155391164de11 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4333,6 +4333,18 @@ static int __sched_setscheduler(struct task_struct *p, } change:
+#ifdef CONFIG_QOS_SCHED + /* + * If the scheduling policy of an offline task is set to a policy + * other than SCHED_IDLE, the online task preemption will be invalid, + * so return -EINVAL in this case. + */ + if (unlikely(task_group(p)->qos_level == -1 && !idle_policy(policy))) { + task_rq_unlock(rq, p, &rf); + return -EINVAL; + } +#endif + if (user) { #ifdef CONFIG_RT_GROUP_SCHED /* diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 01ae007760376..1dd1e34f3d596 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6991,7 +6991,8 @@ static bool check_qos_cfs_rq(struct cfs_rq *cfs_rq) return false;
if (cfs_rq && cfs_rq->tg->qos_level < 0 && - !sched_idle_cpu(cpu_of(rq_of(cfs_rq)))) { + !sched_idle_cpu(cpu_of(rq_of(cfs_rq))) && + cfs_rq->h_nr_running == cfs_rq->idle_h_nr_running) { throttle_qos_cfs_rq(cfs_rq); return true; }