Skip to contentSkip to conversation

scheduler: access to variable out of scope in sched_slice()

PATCH In review Christian Engelmayer 2 participants 3 messages Jun 16, 2009 – Jun 17, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scheduler: access to variable out of scope in sched_slice()

From: Christian Engelmayer <[email protected]>

Access to local variable lw is aliased by usage of pointer load. Access to pointer load in calc_delta_mine() happens when lw is already out of scope.

--
Reported by static code analysis.

kernel/sched_fair.c renamed from kernel/sched_fair.c.orig +2 -1
@@ -430,12 +430,13 @@ static u64 sched_slice(struct cfs_rq *cf
 
 	for_each_sched_entity(se) {
 		struct load_weight *load;
+		struct load_weight lw;
 
 		cfs_rq = cfs_rq_of(se);
 		load = &cfs_rq->load;
 
 		if (unlikely(!se->on_rq)) {
-			struct load_weight lw = cfs_rq->load;
+			lw = cfs_rq->load;
 
 			update_load_add(&lw, se->load.weight);
 			load = &lw;
#1 lore raw
Quoted 16 lines · Christian Engelmayer

From: Christian Engelmayer <[email protected]>

Access to local variable lw is aliased by usage of pointer load. Access to pointer load in calc_delta_mine() happens when lw is already out of scope.

--
Reported by static code analysis.

kernel/sched_fair.c renamed from kernel/sched_fair.c.orig +1 -0
@@ -430,12 +430,13 @@ static u64 sched_slice(struct cfs_rq *cf
 
 	for_each_sched_entity(se) {
 		struct load_weight *load;
+		struct load_weight lw;

kernel/sched_fair.c static u64 sched_slice(struct cfs_rq *cf · line 442

Quoted 10 lines
kernel/sched_fair.c renamed from kernel/sched_fair.c.orig +1 -1
 
 		cfs_rq = cfs_rq_of(se);
 		load = &cfs_rq->load;
 
 		if (unlikely(!se->on_rq)) {
-			struct load_weight lw = cfs_rq->load;
+			lw = cfs_rq->load;
 
 			update_load_add(&lw, se->load.weight);
 			load = &lw;

Good one!

I suspect it doesnt matter in practice because GCC will just have them all on the same stack frame?

Ingo

#2 lore raw

[tip:sched/urgent] sched: Fix out of scope variable access in sched_slice()

In reply to Christian Engelmayer
Commit-ID:  3104bf03a923c72043a9c5009d9cd56724304916
Gitweb:     http://git.kernel.org/tip/3104bf03a923c72043a9c5009d9cd56724304916
Author:     Christian Engelmayer <[email protected]>
AuthorDate: Tue, 16 Jun 2009 10:35:12 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 17 Jun 2009 18:37:54 +0200

sched: Fix out of scope variable access in sched_slice()

Access to local variable lw is aliased by usage of pointer load. Access to pointer load in calc_delta_mine() happens when lw is already out of scope.

[ Reported by static code analysis. ]

LKML-Reference: <[email protected]>

---
 kernel/sched_fair.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
kernel/sched_fair.c +2 -1
index 5f9650e..ba7fd6e 100644
@@ -430,12 +430,13 @@ static u64 sched_slice(struct cfs_rq *cfs_rq, struct sched_entity *se)
 
 	for_each_sched_entity(se) {
 		struct load_weight *load;
+		struct load_weight lw;
 
 		cfs_rq = cfs_rq_of(se);
 		load = &cfs_rq->load;
 
 		if (unlikely(!se->on_rq)) {
-			struct load_weight lw = cfs_rq->load;
+			lw = cfs_rq->load;
 
 			update_load_add(&lw, se->load.weight);
 			load = &lw;