From: "George Spelvin" <linux@horizon.com>
To: linux-kernel@vger.kernel.org, sqazi@google.com
Cc: allan.stephens@windriver.com, linux@horizon.com,
peterz@infradead.org, torvalds@linux-foundation.org
Subject: Re: [PATCH] Fix a race in pid generation that causes pids to be reused
Date: 11 Jun 2010 14:29:54 -0400 [thread overview]
Message-ID: <20100611182954.20294.qmail@science.horizon.com> (raw)
> Isn't: return a - base < b - base, the natural way to express this?
Quite right.
I see people managed to figure it out, but my, what a lot of angst
over something so familiar to any network hacker trying to figure out
if a received sequence number is in the receive window or not.
See include/net/tcp.h:
265: /* is s2<=s1<=s3 ? */
266: static inline int between(__u32 seq1, __u32 seq2, __u32 seq3)
267: {
268: return seq3 - seq2 >= seq1 - seq2;
269: }
(If someone wants to fix the far uglier version in net/tipc/link.h...
Allan, Cc: to you.)
If you want to handle strictly conforming ANSI C, then you have to
cast everything to unsigned before the subtraction, but in practice,
casting afterward works just as well:
return (unsigned)a - (unsigned)base < (unsigned)b - (unsigned)base;
return (unsigned)(a - base) < (unsigned)(b - base)
Conceptually, it's "is the distance forward from base to a less than
the distance forward from base to b"? The "forward" is enforced by the
unsigned cast.
If the numbers wrap before UINT_MAX, the logic still works; it doesn't
care if values between PID_MAX_LIMIT and UINT_MAX are "illegal and may not
be assigned" or "by merest chance happen to not be assigned".
reply other threads:[~2010-06-11 18:29 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20100611182954.20294.qmail@science.horizon.com \
--to=linux@horizon.com \
--cc=allan.stephens@windriver.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=sqazi@google.com \
--cc=torvalds@linux-foundation.org \
/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
Powered by JetHome