提交 b43a1c9e 编写于 作者: H Hui Tang 提交者: zhangchangzhong

sched: fix dereference NULL pointers

hulk inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I7EA1X
CVE: NA

-------------------------------

tg->auto_affinity is NULL if init_auto_affinity() failed.
So add checking for tg->auto_affinity before derefrence.

Fixes: 713cfd26 ("sched: Introduce smart grid scheduling strategy for cfs")
Signed-off-by: NHui Tang <tanghui20@huawei.com>
Reviewed-by: NZhang Qiao <zhangqiao22@huawei.com>
Signed-off-by: NZhang Changzhong <zhangchangzhong@huawei.com>
上级 12521356
......@@ -6989,6 +6989,9 @@ int tg_set_dynamic_affinity_mode(struct task_group *tg, u64 mode)
{
struct auto_affinity *auto_affi = tg->auto_affinity;
if (unlikely(!auto_affi))
return -EPERM;
/* auto mode*/
if (mode == 1) {
start_auto_affinity(auto_affi);
......@@ -7006,6 +7009,9 @@ static u64 cpu_affinity_mode_read_u64(struct cgroup_subsys_state *css,
{
struct task_group *tg = css_tg(css);
if (unlikely(!tg->auto_affinity))
return -EPERM;
return tg->auto_affinity->mode;
}
......@@ -7017,6 +7023,9 @@ static int cpu_affinity_mode_write_u64(struct cgroup_subsys_state *css,
int tg_set_affinity_period(struct task_group *tg, u64 period_ms)
{
if (unlikely(!tg->auto_affinity))
return -EPERM;
if (period_ms > U64_MAX / NSEC_PER_MSEC)
return -EINVAL;
......@@ -7028,6 +7037,9 @@ int tg_set_affinity_period(struct task_group *tg, u64 period_ms)
u64 tg_get_affinity_period(struct task_group *tg)
{
if (unlikely(!tg->auto_affinity))
return -EPERM;
return ktime_to_ms(tg->auto_affinity->period);
}
......@@ -7048,9 +7060,14 @@ static int cpu_affinity_domain_mask_write_u64(struct cgroup_subsys_state *css,
u64 mask)
{
struct task_group *tg = css_tg(css);
struct affinity_domain *ad = &tg->auto_affinity->ad;
u16 full = (1 << ad->dcount) - 1;
struct affinity_domain *ad;
u16 full;
if (unlikely(!tg->auto_affinity))
return -EPERM;
ad = &tg->auto_affinity->ad;
full = (1 << ad->dcount) - 1;
if (mask > full)
return -EINVAL;
......@@ -7065,6 +7082,9 @@ static u64 cpu_affinity_domain_mask_read_u64(struct cgroup_subsys_state *css,
{
struct task_group *tg = css_tg(css);
if (unlikely(!tg->auto_affinity))
return -EPERM;
return tg->auto_affinity->ad.domain_mask;
}
......@@ -7072,9 +7092,13 @@ static int cpu_affinity_stat_show(struct seq_file *sf, void *v)
{
struct task_group *tg = css_tg(seq_css(sf));
struct auto_affinity *auto_affi = tg->auto_affinity;
struct affinity_domain *ad = &auto_affi->ad;
struct affinity_domain *ad;
int i;
if (unlikely(!auto_affi))
return -EPERM;
ad = &auto_affi->ad;
seq_printf(sf, "period_active %d\n", auto_affi->period_active);
seq_printf(sf, "dcount %d\n", ad->dcount);
seq_printf(sf, "domain_mask 0x%x\n", ad->domain_mask);
......
......@@ -5697,6 +5697,9 @@ static void destroy_auto_affinity(struct task_group *tg)
{
struct auto_affinity *auto_affi = tg->auto_affinity;
if (unlikely(!auto_affi))
return;
if (auto_affi->period_active)
smart_grid_usage_dec();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册