From: Peter Zijlstra <peterz@infradead.org>
To: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: mingo@redhat.com, linux-kernel@vger.kernel.org,
yuyang.du@intel.com, Morten Rasmussen <morten.rasmussen@arm.com>,
Paul Turner <pjt@google.com>, Ben Segall <bsegall@google.com>
Subject: Re: [PATCH] sched/fair: fix mul overflow on 32-bit systems
Date: Fri, 11 Dec 2015 14:25:51 +0100 [thread overview]
Message-ID: <20151211132551.GO6356@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <1449838518-26543-1-git-send-email-aryabinin@virtuozzo.com>
On Fri, Dec 11, 2015 at 03:55:18PM +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>
> ---
> kernel/sched/fair.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index e3266eb..733f0b8 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -2780,14 +2780,14 @@ 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);
This makes sense, because sched_avg::load_sum is u64.
> removed = 1;
> }
>
> if (atomic_long_read(&cfs_rq->removed_util_avg)) {
> - long r = atomic_long_xchg(&cfs_rq->removed_util_avg, 0);
> + s64 r = atomic_long_xchg(&cfs_rq->removed_util_avg, 0);
> sa->util_avg = max_t(long, sa->util_avg - r, 0);
> sa->util_sum = max_t(s32, sa->util_sum - r * LOAD_AVG_MAX, 0);
> }
However sched_avg::util_sum is u32, so this is still wrecked.
next prev parent reply other threads:[~2015-12-11 13:25 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-11 12:55 [PATCH] sched/fair: fix mul overflow on 32-bit systems Andrey Ryabinin
2015-12-11 13:25 ` Peter Zijlstra [this message]
2015-12-11 13:36 ` Peter Zijlstra
2015-12-11 14:00 ` Andrey Ryabinin
2015-12-11 17:57 ` Morten Rasmussen
2015-12-11 18:32 ` Dietmar Eggemann
2015-12-11 19:18 ` bsegall
2015-12-13 21:02 ` Yuyang Du
2015-12-14 12:32 ` Morten Rasmussen
2015-12-14 17:51 ` bsegall
2015-12-13 22:42 ` Yuyang Du
2015-12-14 11:54 ` Peter Zijlstra
2015-12-14 13:07 ` Morten Rasmussen
2015-12-14 14:20 ` Peter Zijlstra
2015-12-14 14:46 ` Morten Rasmussen
2015-12-15 2:22 ` Yuyang Du
2015-12-15 21:56 ` Steve Muckle
2015-12-18 2:33 ` Yuyang Du
2016-01-03 23:14 ` Yuyang Du
2015-12-11 17:58 ` bsegall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151211132551.GO6356@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=aryabinin@virtuozzo.com \
--cc=bsegall@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=morten.rasmussen@arm.com \
--cc=pjt@google.com \
--cc=yuyang.du@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox