Yes. If you had yielded that claim I wouldn't have had any reason to
answer. But since you haven't, I had to object.
And I still don't. You are describing a situation where an
application programmer makes an erroneous assumption, and that
assumption results in a security problem.
The pid has traditionally always been a simple wrap-around counter. Any
unix programmer should know this.
That depends on your definition of "traditionally." Yes, the
standard code base from AT&T did this, and many of the derivative
systems also did this. However, that is irrelevant, as it was not
guaranteed by either the system specification or a published
standard. (And, I know of systems at least as far back as 1982 that
used non-sequential PIDs.). A programmer may know that this is the
way that things often work, but he/she shouldn't depend on something
that isn't *documented* as a permanent characteristic of the
system. And, if you are targeting a portable platform, such as
POSIX, you need to be aware of possible differences across
implementations of that platform.
Using it in a context where a random
number (much less a cryptographically strong random number) is required
is just using the wrong tool for the job. Such an error may lead to a
security problem, but that's the fault of the programmer, not the tool.
(In your scenario, the real error is probably not using O_EXCL, btw, not
using the pid, but that depends on the intended use).
Yes, *one* underlying error was not using O_EXCL -- as I implied
by my reference to O_EXCL in that post.
As decoded in a parallel sub-thread, it would appear that a real
problem underlying your concern was a dependence on a time delay
before reuse of PIDs. That characteristic, of course, is not
currently a guarantee of the POSIX/UNIX standard, and I can find
no instances of any system documentation promising that.
The question we have before us seems to be how to attribute the
blame of being a security flaw. Consider the case of using an
uninitialized variable in a program. It can be the case that that
variable happens to inherit a value that causes the the program
to behave reasonably. As time elapses that accidental value can
change for any number of reasons: the level of optimization changes,
the compiler changes, other code in the program changes and happens
to leave a different value in that location, or the program is
moved to a different platform.
When that program later misbehaves, leaving a loss of data (and a
security problem using your definition), one shouldn't point to
the new compiler or the different platform as the security problem.
The security flaw is the improper coding in the original program.
In the case of the example that you provide in a parallel sub-thread,
the basic security flaw is clearly at the hands of the designers
of the maildir format (assuming your description is correct, which
I don't doubt). They made an assumption that wasn't true across
the targeted platforms.
Security experts, for both computers and otherwise, note that
vulnerability is the product of the existence of security
vulnerabilities and the presence of security threats. In this
case, the introduction of a system with randomized PIDs increased
the level of security threat, but that doesn't mean that the use
of randomized PIDs is itself a security threat, which is an
implication, but not explicit claim, of your earlier message to
which I was reacting.
So, with that said, let me react to the rest of your message:
Yes. A linearly incrementing pid has some minimum time between the start
time of two processes with the same pid. Typically, about 30000 forks
are needed before the same pid can be reused.
A programmer which knows this may assume that the start time of the
process with suitably high resolution (for example 1 millisecond - 1
second is already too grainy given current computer speeds) together
with the pid is always unique: The system would need to be able to fork
30000 processes within 1 ms, which is far beyond the capabilities of
current systems and will stay impossible for some time.
Right, and that programmer is creating a bug by depending on a
characteristic that is not guaranteed by any spec.
I know a number of applications which didn't work correctly on BSD
systems after randomized pids were introduced. The results were usually
lost data or data leaked to a different user, so that was at least
potentially security-critical.
Agreed, and the security problem was in the application. The
introduction of the use of the "BSD" system (I'm presuming that
this was likely OpenBSD) increased the security threat by altering
more characteristics of the platform.
Personally, I think it's a good thing that these applications were
broken, because it alerted the maintainers that the assumption
"timestamp + pid is unique" was faulty way before it became faulty on
systems on which it may have been possible to systematically exploit the
bug (IIRC all these applications used a one-second timestamp which is
now getting too short).
I'm not saying that random pids are bad /per se/. But the average unix
programmer probably doesn't know that they exist so he cannot consider
their consequences.
OK, and the way to deal with that is to teach those programmers
how to write portable applications by not depending on accidental
characteristics.
(As an aside: Is the randomness of the pids on BSD systems
cryptographically strong? If not, a programmer might assume they are and
make the same error as a programmer who thinks that linearly incremented
pids are "non-predictable". If they are, how about other systems with
random pids?)
I don't know about those particular systems, but often such algorithms
are pluggable and can be replaced depending upon the security
requirements of the deployed environment. Given that the rate of
production of PIDs is slower, and the visibility of PIDs is lower
than communication data, the tolerable level of strength would be
lower.
- dmw