From: "Guillaume Knispel" <gknispel@proformatique.com>
To: "Amerigo Wang" <xiyou.wangcong@gmail.com>
Cc: "Guillaume Knispel" <gknispel@proformatique.com>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Arjan van de Ven" <arjan@linux.intel.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
"Heiko Carstens" <heiko.carstens@de.ibm.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Tejun Heo" <tj@kernel.org>
Subject: Re: [PATCH] poll/select: avoid arithmetic overflow in __estimate_accuracy()
Date: Mon, 17 Aug 2009 13:20:50 +0200 (CEST) [thread overview]
Message-ID: <ff6e70f67e2cc619513f8b61828c8dba.squirrel@mail.corp.proformatique.com> (raw)
In-Reply-To: <20090817091116.GD5868@cr0.nay.redhat.com>
> On Sun, Aug 16, 2009 at 10:29:21PM +0200, Guillaume Knispel wrote:
>>__estimate_accuracy() was prone to integer overflow, for example
>>if *tv == {2147, 483648000} on a 32 bit computer (or even for delays
>>as small as {429, 500000000} if the task is niced).
>>
>>Because the result was already forced between 0 and 100ms, the effect
>>of the overflow was not too problematic, but the use of the hrtimer
>>range feature was not optimal in overflow cases.
>>
>>This patch ensures that there can not be an integer overflow in this
>>function.
>>
>>Signed-off-by: Guillaume Knispel <gknispel@proformatique.com>
>>---
>> fs/select.c | 14 ++++++++++----
>> 1 files changed, 10 insertions(+), 4 deletions(-)
>>
>>diff --git a/fs/select.c b/fs/select.c
>>index 8084834..a201fc3 100644
>>--- a/fs/select.c
>>+++ b/fs/select.c
>>@@ -41,22 +41,28 @@
>> * better solutions..
>> */
>>
>>+#define MAX_SLACK (100 * NSEC_PER_MSEC)
>>+
>> static long __estimate_accuracy(struct timespec *tv)
>> {
>> long slack;
>> int divfactor = 1000;
>>
>>+ if (tv->tv_sec < 0)
>>+ return 0;
>>+
>> if (task_nice(current) > 0)
>> divfactor = divfactor / 5;
>>
>>+ if (tv->tv_sec > MAX_SLACK / (NSEC_PER_SEC/divfactor))
>>+ return MAX_SLACK;
>>+
>
>
> Yes? Isn't MAX_SLACK also too big for 'long' on 32bit machine?
>
> Try:
>
> % printf "%d\n" "100*1000000000 > 0x7fffffff"
> 1
>
> Am I missing something here?
100 * NSEC_PER_MSEC => 100 * 1000000
-
The exact same multiplication was already in the existing code,
and this is not the one that can overflow.
Cheers,
Guillaume Knispel
prev parent reply other threads:[~2009-08-17 11:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-16 20:29 [PATCH] poll/select: avoid arithmetic overflow in __estimate_accuracy() Guillaume Knispel
2009-08-17 9:11 ` Amerigo Wang
2009-08-17 11:20 ` Guillaume Knispel [this message]
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=ff6e70f67e2cc619513f8b61828c8dba.squirrel@mail.corp.proformatique.com \
--to=gknispel@proformatique.com \
--cc=akpm@linux-foundation.org \
--cc=arjan@linux.intel.com \
--cc=heiko.carstens@de.ibm.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=xiyou.wangcong@gmail.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;
as well as URLs for NNTP newsgroup(s).