From: George Anzinger <george@mvista.com>
To: Andrew Morton <akpm@osdl.org>
Cc: tmarshall@real.com, pmarques@grupopie.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Re: itimer oddness in 2.6.12
Date: Tue, 26 Jul 2005 07:36:38 -0700 [thread overview]
Message-ID: <42E64A76.50504@mvista.com> (raw)
In-Reply-To: <20050725231720.507d4b38.akpm@osdl.org>
Andrew Morton wrote:
> George Anzinger <george@mvista.com> wrote:
>
>>+ while (time_before_eq(p->signal->real_timer.expires, jiffies))
>>+ p->signal->real_timer.expires += inc;
>
>
> It gives me the creeps when I see timer code doing this, and it seems to be
> done relatively frequently.
>
> Surely it can be calculated arithmetically? If not, are you really sure
> that it is not exploitable by malicious code?
Hm.. the system only falls into a loop here if the system is loaded to
the point where we are a jiffie or more late. The prior code just did
the "+=" and called add_timer, possibly with a time in the past. I
suspect that way of doing this would never catch up if the user asked
for a one jiffie repeat time. Also, this is faster than the div, mpy if
you are not late (or even if you are several jiffies late).
A possible alternative might be:
p->signal->real_timer.expires += inc;
if (time_before_eq(p->signal->real_timer.expires, jiffies))
p->signal->real_timer.expires += ((jiffies -
p->signal->real_timer.expires + inc -1) / inc) * inc;
Both a div and a mpy in there. I really think the "while" is ok, but if
you prefer...
The last time you questioned this sort of thing was in the code to
correct an absolute timer. In that case we were adjusting after a clock
set and, yes, it was possibly exploitable (assuming you could set the
clock). Here we don't have that possibility, i.e. we only get into the
loop if the system is late.
> -
--
George Anzinger george@mvista.com
HRT (High-res-timers): http://sourceforge.net/projects/high-res-timers/
prev parent reply other threads:[~2005-07-26 14:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-22 17:16 itimer oddness in 2.6.12 Tom Marshall
2005-07-22 19:21 ` Paulo Marques
2005-07-22 20:58 ` Tom Marshall
2005-07-23 1:48 ` [PATCH] " George Anzinger
2005-07-25 11:58 ` Paulo Marques
2005-07-25 19:04 ` Bill Davidsen
2005-07-26 6:17 ` Andrew Morton
2005-07-26 14:36 ` George Anzinger [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=42E64A76.50504@mvista.com \
--to=george@mvista.com \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmarques@grupopie.com \
--cc=tmarshall@real.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