From: Vegard Nossum <vegard.nossum@oracle.com>
To: Richard Cochran <richardcochran@gmail.com>,
John Stultz <john.stultz@linaro.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@kernel.org>,
Prarit Bhargava <prarit@redhat.com>
Subject: Re: [PATCH 4/6] time: Avoid undefined behaviour in timespec64_add_safe()
Date: Thu, 1 Sep 2016 11:37:07 +0200 [thread overview]
Message-ID: <80e2b00b-659c-7c0a-0f96-ca6fa2375b42@oracle.com> (raw)
In-Reply-To: <20160901080255.GA2386@localhost.localdomain>
On 09/01/2016 10:02 AM, Richard Cochran wrote:
> On Wed, Aug 31, 2016 at 02:50:20PM -0700, John Stultz wrote:
>> UBSAN: Undefined behaviour in kernel/time/time.c:783:2
>> signed integer overflow:
>> 5273 + 9223372036854771711 cannot be represented in type 'long int'
>
> ...
>
>> Line 783 is this:
>>
>> 783 set_normalized_timespec64(&res, lhs.tv_sec + rhs.tv_sec,
>> 784 lhs.tv_nsec + rhs.tv_nsec);
>
> ...
>
>> Note that this is not currently a huge concern since the kernel should be
>> built with -fno-strict-overflow by default, but could be a problem in the
>> future, a problem with older compilers, or other compilers than gcc.
>
> Is this really a concern at all? The value 9223372036854771711 is a
> huge number of seconds.
The problem is that "undefined behaviour" means the compiler is
technically free to do whatever it wants -- it could issue an invalid
opcode, which would crash the kernel -- and this bit of code is easily
reached from userspace, making this a potential DOS vector (or worse,
depending on what exactly the compiler chooses to do).
Now the kernel is compiled with -fno-strict-overflow when it is
supported by the compiler, which in practice makes signed integer
overflow defined the same way as unsigned integer overflow (i.e. it
wraps around).
As the patch message says, this could be a problem with older and
non-gcc compilers.
So the concern is not the huge value or an overflow in itself, the
concern is the undefined behaviour where we may not be in control
of what happens.
There's probably at least a dozen other easily reachable overflows like
this in the kernel currently and I have no evidence of any actual
compilers doing really bad things, so yes, this is all somewhat
theoretical, but it's easy to fix which doesn't complicate the code and
adheres to the C language standard, so why not?
Vegard
next prev parent reply other threads:[~2016-09-01 9:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-31 21:50 [GIT PULL][PATCH 0/6] 4.9 timekeeping changes for tip/timers/core John Stultz
2016-08-31 21:50 ` [PATCH 1/6] hrtimer: Spelling fixes John Stultz
2016-08-31 21:50 ` [PATCH 2/6] clocksource: Defer override invalidation unless clock is unstable John Stultz
2016-08-31 21:50 ` [PATCH 3/6] timekeeping: Prints the amounts of time spent during suspend John Stultz
2016-08-31 21:50 ` [PATCH 4/6] time: Avoid undefined behaviour in timespec64_add_safe() John Stultz
2016-09-01 8:02 ` Richard Cochran
2016-09-01 9:37 ` Vegard Nossum [this message]
2016-08-31 21:50 ` [PATCH 5/6] time: Avoid undefined behaviour in ktime_add_safe() John Stultz
2016-08-31 21:50 ` [PATCH 6/6] time: alarmtimer: Add tracepoints for alarmtimers John Stultz
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=80e2b00b-659c-7c0a-0f96-ca6fa2375b42@oracle.com \
--to=vegard.nossum@oracle.com \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=prarit@redhat.com \
--cc=richardcochran@gmail.com \
--cc=tglx@linutronix.de \
/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
all inboxes | Powered by JetHome®