sched: fair: avoid integer overflow
PATCH 1/1 sched: fair: avoid integer overflow
From: Michal Nazarewicz <[email protected]>
sa->runnable_avg_sum is of type u32 but after shifting it by NICE_0_SHIFT bits it is promoted to u64. This of course makes no sense, since the result will never be more then 32-bit long. Casting sa->runnable_avg_sum to u64 before it is shifted, fixes this problem.
--- kernel/sched/fair.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +1 -1
@@ -2153,7 +2153,7 @@ static inline void __update_tg_runnable_avg(struct sched_avg *sa,long contrib;/* The fraction of a cpu used by this cfs_rq */ - contrib =div_u64 (sa->runnable_avg_sum <<NICE_0_SHIFT , + contrib =div_u64 ((u64 )sa->runnable_avg_sum <<NICE_0_SHIFT , sa->runnable_avg_period +1 ); contrib -= cfs_rq->tg_runnable_contrib;
Signature · 1 line
1.8.3.2
Quoted 8 lines · Michal Nazarewicz
From: Michal Nazarewicz <[email protected]>
sa->runnable_avg_sumis of type u32 but after shifting it byNICE_0_SHIFTbits it is promoted to u64. This of course makes no sense, since the result will never be more then 32-bit long. Castingsa->runnable_avg_sumto u64 before it is shifted, fixes this problem.Signed-off-by Michal Nazarewicz <[email protected]>
Quoted 16 lines
--- kernel/sched/fair.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/sched/fair.c +1
-1@@ -2153,7 +2153,7 @@ static inline void __update_tg_runnable_avg(struct sched_avg *sa,long contrib;/* The fraction of a cpu used by this cfs_rq */ - contrib =div_u64 (sa->runnable_avg_sum <<NICE_0_SHIFT , + contrib =div_u64 ((u64 )sa->runnable_avg_sum <<NICE_0_SHIFT , sa->runnable_avg_period +1 ); contrib -= cfs_rq->tg_runnable_contrib;
tip-bot for Michal Nazarewicz
merge bot[tip:sched/urgent] sched/fair: Avoid integer overflow
In reply to Michal Nazarewiczsched/fair: Avoid integer overflow
Commit-ID: 85b088e934b9943322bfe37077289ae60f1b3414 Gitweb: http://git.kernel.org/tip/85b088e934b9943322bfe37077289ae60f1b3414 Author: Michal Nazarewicz <[email protected]> AuthorDate: Sun, 10 Nov 2013 20:42:01 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 13 Nov 2013 13:33:55 +0100
sched/fair: Avoid integer overflow
sa->runnable_avg_sum is of type u32 but after shifting it by NICE_0_SHIFT bits it is promoted to u64. This of course makes no sense, since the result will never be more then 32-bit long. Casting sa->runnable_avg_sum to u64 before it is shifted, fixes this problem.
--- kernel/sched/fair.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sched/fair.c +1 -1
@@ -2178,7 +2178,7 @@ static inline void __update_tg_runnable_avg(struct sched_avg *sa,long contrib;/* The fraction of a cpu used by this cfs_rq */ - contrib =div_u64 (sa->runnable_avg_sum <<NICE_0_SHIFT , + contrib =div_u64 ((u64 )sa->runnable_avg_sum <<NICE_0_SHIFT , sa->runnable_avg_period +1 ); contrib -= cfs_rq->tg_runnable_contrib;