* [PATCH v2] sched/fair: fix mul overflow on 32-bit systems
@ 2015-12-14 12:47 Andrey Ryabinin
2015-12-14 14:35 ` Peter Zijlstra
2016-01-06 18:47 ` [tip:sched/core] sched/fair: Fix multiplication " tip-bot for Andrey Ryabinin
0 siblings, 2 replies; 3+ messages in thread
From: Andrey Ryabinin @ 2015-12-14 12:47 UTC (permalink / raw)
To: mingo, peterz
Cc: bsegall, dietmar.eggemann, linux-kernel, yuyang.du, pjt,
morten.rasmussen, Andrey Ryabinin
Make 'r' 64-bit type to avoid overflow in 'r * LOAD_AVG_MAX'
on 32-bit systems:
UBSAN: Undefined behaviour in kernel/sched/fair.c:2785:18
signed integer overflow:
87950 * 47742 cannot be represented in type 'int'
Fixes: 9d89c257dfb9 ("sched/fair: Rewrite runnable load and utilization average tracking")
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
Changes since v1:
- Removed wrong second hunk. Anyway, if fix for util_avg is needed,
it deserves a separte patch.
kernel/sched/fair.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 90e26b1..cfdc0e6 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -2689,7 +2689,7 @@ static inline int update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq)
int decayed, removed = 0;
if (atomic_long_read(&cfs_rq->removed_load_avg)) {
- long r = atomic_long_xchg(&cfs_rq->removed_load_avg, 0);
+ s64 r = atomic_long_xchg(&cfs_rq->removed_load_avg, 0);
sa->load_avg = max_t(long, sa->load_avg - r, 0);
sa->load_sum = max_t(s64, sa->load_sum - r * LOAD_AVG_MAX, 0);
removed = 1;
--
2.4.10
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] sched/fair: fix mul overflow on 32-bit systems
2015-12-14 12:47 [PATCH v2] sched/fair: fix mul overflow on 32-bit systems Andrey Ryabinin
@ 2015-12-14 14:35 ` Peter Zijlstra
2016-01-06 18:47 ` [tip:sched/core] sched/fair: Fix multiplication " tip-bot for Andrey Ryabinin
1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2015-12-14 14:35 UTC (permalink / raw)
To: Andrey Ryabinin
Cc: mingo, bsegall, dietmar.eggemann, linux-kernel, yuyang.du, pjt,
morten.rasmussen
On Mon, Dec 14, 2015 at 03:47:23PM +0300, Andrey Ryabinin wrote:
> Make 'r' 64-bit type to avoid overflow in 'r * LOAD_AVG_MAX'
> on 32-bit systems:
> UBSAN: Undefined behaviour in kernel/sched/fair.c:2785:18
> signed integer overflow:
> 87950 * 47742 cannot be represented in type 'int'
>
> Fixes: 9d89c257dfb9 ("sched/fair: Rewrite runnable load and utilization average tracking")
> Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
* [tip:sched/core] sched/fair: Fix multiplication overflow on 32-bit systems
2015-12-14 12:47 [PATCH v2] sched/fair: fix mul overflow on 32-bit systems Andrey Ryabinin
2015-12-14 14:35 ` Peter Zijlstra
@ 2016-01-06 18:47 ` tip-bot for Andrey Ryabinin
1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Andrey Ryabinin @ 2016-01-06 18:47 UTC (permalink / raw)
To: linux-tip-commits
Cc: aryabinin, tglx, mingo, torvalds, linux-kernel, hpa, peterz
Commit-ID: 9e0e83a1eca66f8369e5a02973f85aad65c32416
Gitweb: http://git.kernel.org/tip/9e0e83a1eca66f8369e5a02973f85aad65c32416
Author: Andrey Ryabinin <aryabinin@virtuozzo.com>
AuthorDate: Mon, 14 Dec 2015 15:47:23 +0300
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 6 Jan 2016 11:01:05 +0100
sched/fair: Fix multiplication overflow on 32-bit systems
Make 'r' 64-bit type to avoid overflow in 'r * LOAD_AVG_MAX'
on 32-bit systems:
UBSAN: Undefined behaviour in kernel/sched/fair.c:2785:18
signed integer overflow:
87950 * 47742 cannot be represented in type 'int'
The most likely effect of this bug are bad load average numbers
resulting in weird scheduling. It's also likely that this can
persist for a longer time - until the system goes idle for
a long time so that all load avg numbers get reset.
[ This is the CFS load average metric, not the procfs output, which
is separate. ]
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: 9d89c257dfb9 ("sched/fair: Rewrite runnable load and utilization average tracking")
Link: http://lkml.kernel.org/r/1450097243-30137-1-git-send-email-aryabinin@virtuozzo.com
[ Improved the changelog. ]
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
kernel/sched/fair.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 90e26b1..cfdc0e6 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -2689,7 +2689,7 @@ static inline int update_cfs_rq_load_avg(u64 now, struct cfs_rq *cfs_rq)
int decayed, removed = 0;
if (atomic_long_read(&cfs_rq->removed_load_avg)) {
- long r = atomic_long_xchg(&cfs_rq->removed_load_avg, 0);
+ s64 r = atomic_long_xchg(&cfs_rq->removed_load_avg, 0);
sa->load_avg = max_t(long, sa->load_avg - r, 0);
sa->load_sum = max_t(s64, sa->load_sum - r * LOAD_AVG_MAX, 0);
removed = 1;
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-01-06 18:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-14 12:47 [PATCH v2] sched/fair: fix mul overflow on 32-bit systems Andrey Ryabinin
2015-12-14 14:35 ` Peter Zijlstra
2016-01-06 18:47 ` [tip:sched/core] sched/fair: Fix multiplication " tip-bot for Andrey Ryabinin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox