From: Andrew Morton <akpm@linux-foundation.org>
To: Rusty Russell <rusty@rustcorp.com.au>
Cc: David Howells <dhowells@redhat.com>,
linux-arch@vger.kernel.org, randy.dunlap@oracle.com
Subject: Re: + expose-range-checking-functions-from-arch-specific.patch added to -mm tree
Date: Tue, 10 Apr 2007 19:48:34 -0700 [thread overview]
Message-ID: <20070410194834.b688ce55.akpm@linux-foundation.org> (raw)
In-Reply-To: <1176257950.26372.50.camel@localhost.localdomain>
On Wed, 11 Apr 2007 12:19:10 +1000 Rusty Russell <rusty@rustcorp.com.au> wrote:
> On Tue, 2007-04-10 at 11:17 +0100, David Howells wrote:
> > akpm@linux-foundation.org wrote:
> >
> > > + * @limit: the first invalid value
> >
> > If this is the case, ...
> >
> > > + *
> > > + * Like val + len > limit, except with overflow checking.
> > > + */
> > > +static inline bool val_outside(unsigned long val, unsigned long len,
> > > + unsigned long limit)
> > > +
> > > +{
> > > + return val + len > limit || val + len < val;
> >
> > ... then shouldn't that be "val + len >= limit"?
>
> You're the second one to ask this. I'm pretty sure it's still right
> (and it's what the old code used to do).
>
> Consider the case where limit is 0xC0000000, val is 0xBFFFFFFF and len
> is 1.
>
I probably shouldn't look at this after a glass of red, but otoh, perhaps
that's a good way of ensuring that we have a built-in margin.
I find this function incomprehensible. I'd just avoid using the sorry
thing, personally.
To me, "val_outside" means "true if the value is outside":
bool val_outside(val, start, len)
{
return val < start || val > (start+len-1);
}
that's what my function does. I don't have a clue what yours does.
For starters, wtf is a "limit"? A length? Or an offset relative to "len"?
And wtf is "len" anyway? Absolute? Relative?
<reworks it>
return val > (limit - len) || val < (val - len);
nope, that didn't help.
The consequences of people getting this wrong are oopses, memory
corruption, root holes and other such pleasantry, in rare (or deliberately
invoked) circumstances. Can we try to make it easier for them?
next prev parent reply other threads:[~2007-04-11 2:48 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-06 21:27 + expose-range-checking-functions-from-arch-specific.patch added to -mm tree akpm
2007-04-10 10:17 ` David Howells
2007-04-11 2:19 ` Rusty Russell
2007-04-11 2:48 ` Andrew Morton [this message]
2007-04-11 10:49 ` David Howells
2007-04-11 18:24 ` Andrew Morton
2007-04-11 23:28 ` Rusty Russell
2007-04-12 16:05 ` + expose-range-checking-functions-from-arch-specific.patchadded " Luck, Tony
2007-04-13 0:08 ` Rusty Russell
2007-04-11 23:41 ` + expose-range-checking-functions-from-arch-specific.patch added " Rusty Russell
2007-04-12 10:47 ` David Howells
2007-04-12 14:51 ` Randy Dunlap
2007-04-12 7:42 ` Geert Uytterhoeven
2007-04-11 13:17 ` Rusty Russell
2007-04-11 17:03 ` David Howells
2007-04-11 18:31 ` Andrew Morton
2007-04-11 19:17 ` David Howells
2007-04-11 22:52 ` Rusty Russell
2007-04-12 10:49 ` David Howells
2007-04-11 10:47 ` David Howells
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=20070410194834.b688ce55.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=dhowells@redhat.com \
--cc=linux-arch@vger.kernel.org \
--cc=randy.dunlap@oracle.com \
--cc=rusty@rustcorp.com.au \
/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).