linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sched/topology: check variable group before dereferenced
@ 2018-07-23  4:19 Yi Wang
  2018-07-23  8:37 ` Peter Zijlstra
  2018-07-25 14:20 ` [tip:sched/core] sched/topology: Check variable group before dereferencing it tip-bot for Yi Wang
  0 siblings, 2 replies; 3+ messages in thread
From: Yi Wang @ 2018-07-23  4:19 UTC (permalink / raw)
  To: mingo; +Cc: peterz, linux-kernel, jiang.biao2, wang.yi59, zhong.weidong

The variable group in sched_domain_debug_one() is not checked
when firstly used in cpumask_test_cpu(cpu, sched_group_span(group)),
but it maybe NULL(checked later in the following while loop) and may
cause NULL pointer dereference without checking. We need to check it
before using to avoid NULL dereference.

Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
Reviewed-by: Jiang Biao <jiang.biao2@zte.com.cn>
---
 kernel/sched/topology.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index 5ac724b..c7cf87c 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -53,7 +53,7 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
 		printk(KERN_ERR "ERROR: domain->span does not contain "
 				"CPU%d\n", cpu);
 	}
-	if (!cpumask_test_cpu(cpu, sched_group_span(group))) {
+	if (group && !cpumask_test_cpu(cpu, sched_group_span(group))) {
 		printk(KERN_ERR "ERROR: domain->groups does not contain"
 				" CPU%d\n", cpu);
 	}
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] sched/topology: check variable group before dereferenced
  2018-07-23  4:19 [PATCH] sched/topology: check variable group before dereferenced Yi Wang
@ 2018-07-23  8:37 ` Peter Zijlstra
  2018-07-25 14:20 ` [tip:sched/core] sched/topology: Check variable group before dereferencing it tip-bot for Yi Wang
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2018-07-23  8:37 UTC (permalink / raw)
  To: Yi Wang; +Cc: mingo, linux-kernel, jiang.biao2, zhong.weidong

On Mon, Jul 23, 2018 at 12:19:07PM +0800, Yi Wang wrote:
> The variable group in sched_domain_debug_one() is not checked
> when firstly used in cpumask_test_cpu(cpu, sched_group_span(group)),
> but it maybe NULL(checked later in the following while loop) and may
> cause NULL pointer dereference without checking. We need to check it
> before using to avoid NULL dereference.

It being NULL really is a fairly severe error in construction; but sure.
This patch won't hurt.

> Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
> Reviewed-by: Jiang Biao <jiang.biao2@zte.com.cn>
> ---
>  kernel/sched/topology.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
> index 5ac724b..c7cf87c 100644
> --- a/kernel/sched/topology.c
> +++ b/kernel/sched/topology.c
> @@ -53,7 +53,7 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
>  		printk(KERN_ERR "ERROR: domain->span does not contain "
>  				"CPU%d\n", cpu);
>  	}
> -	if (!cpumask_test_cpu(cpu, sched_group_span(group))) {
> +	if (group && !cpumask_test_cpu(cpu, sched_group_span(group))) {
>  		printk(KERN_ERR "ERROR: domain->groups does not contain"
>  				" CPU%d\n", cpu);
>  	}
> -- 
> 1.8.3.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip:sched/core] sched/topology: Check variable group before dereferencing it
  2018-07-23  4:19 [PATCH] sched/topology: check variable group before dereferenced Yi Wang
  2018-07-23  8:37 ` Peter Zijlstra
@ 2018-07-25 14:20 ` tip-bot for Yi Wang
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Yi Wang @ 2018-07-25 14:20 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: mingo, tglx, jiang.biao2, peterz, linux-kernel, torvalds, wang.yi59, hpa

Commit-ID:  6cd0c583b04b2bd9415e07b51b63ab799949dd66
Gitweb:     https://git.kernel.org/tip/6cd0c583b04b2bd9415e07b51b63ab799949dd66
Author:     Yi Wang <wang.yi59@zte.com.cn>
AuthorDate: Mon, 23 Jul 2018 12:19:07 +0800
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 25 Jul 2018 11:25:07 +0200

sched/topology: Check variable group before dereferencing it

The 'group' variable in sched_domain_debug_one() is not checked
when firstly used in cpumask_test_cpu(cpu, sched_group_span(group)),
but it might be NULL (it is checked later in the following while loop)
and may cause NULL pointer dereference.

We need to check it before using to avoid NULL dereference.

Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Jiang Biao <jiang.biao2@zte.com.cn>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: zhong.weidong@zte.com.cn
Link: http://lkml.kernel.org/r/1532319547-33335-1-git-send-email-wang.yi59@zte.com.cn
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/sched/topology.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index 05a831427bc7..56a0fed30c0a 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -47,7 +47,7 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
 	if (!cpumask_test_cpu(cpu, sched_domain_span(sd))) {
 		printk(KERN_ERR "ERROR: domain->span does not contain CPU%d\n", cpu);
 	}
-	if (!cpumask_test_cpu(cpu, sched_group_span(group))) {
+	if (group && !cpumask_test_cpu(cpu, sched_group_span(group))) {
 		printk(KERN_ERR "ERROR: domain->groups does not contain CPU%d\n", cpu);
 	}
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-07-25 14:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-23  4:19 [PATCH] sched/topology: check variable group before dereferenced Yi Wang
2018-07-23  8:37 ` Peter Zijlstra
2018-07-25 14:20 ` [tip:sched/core] sched/topology: Check variable group before dereferencing it tip-bot for Yi Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).