LWN: Comments on "OpenBSD routes around POSIX" https://lwn.net/Articles/625506/ This is a special feed containing comments posted to the individual LWN article titled "OpenBSD routes around POSIX". en-us Sun, 26 Oct 2025 22:26:26 +0000 Sun, 26 Oct 2025 22:26:26 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net OpenBSD routes around POSIX https://lwn.net/Articles/627311/ https://lwn.net/Articles/627311/ raven667 <div class="FormattedComment"> I'm pretty sure that any PRNG given the same inputs will produce the same outputs and that is randomness that is suitable for crypto purposes. The randomness is introduced by seeding with something unpredictable and not knowing how far into the stream you have read not that the values produced will be unpredictable if you know the seed and how many bytes have been read.<br> </div> Mon, 22 Dec 2014 16:33:41 +0000 OpenBSD routes around POSIX https://lwn.net/Articles/627237/ https://lwn.net/Articles/627237/ mirabilos <div class="FormattedComment"> If you want something that can be replayed, it’s not “random”. You list valid use cases, but I question that they can be use cases for an RNG. Sure, do it, but please don’t call it RNG, not even PRNG. Implementing an LFSR, LCG, etc. is dead easy.<br> <p> Besides, POSIX doesn’t guarantee reproducibility between exec() anyway…<br> </div> Mon, 22 Dec 2014 15:51:11 +0000 Per-process choosing could be problematic https://lwn.net/Articles/625949/ https://lwn.net/Articles/625949/ cesarb <div class="FormattedComment"> <font class="QuotedText">&gt; So what happens when some library calls srand_deterministic() and changes the behaviour for the rest of the program? Or when the main program calls srand_deterministic() and thus affects any libraries it calls?</font><br> <p> If your program or library uses the rand()/random()/etc family of calls, it's supposed to be able to work fine with a deterministic RNG (after all, that's what you get in non-OpenBSD systems).<br> <p> The non-deterministic RNG for rand()/random()/etc is a bonus, like ASLR: if your program's security depends on it, you're doing something wrong.<br> </div> Fri, 12 Dec 2014 12:57:25 +0000 Per-process choosing could be problematic https://lwn.net/Articles/625945/ https://lwn.net/Articles/625945/ epa <div class="FormattedComment"> So what happens when some library calls srand_deterministic() and changes the behaviour for the rest of the program? Or when the main program calls srand_deterministic() and thus affects any libraries it calls?<br> <p> I want to be able to choose a seed so that I can repeat the same pseudo-random test case I did last time, but that doesn't mean I want any https: requests made by my test code to silently start using a weaker RNG. Partly this can be solved by having an explicit API for stronger random numbers: arc4random() will always be strong, no matter what srand() type things have gone on in the background. But it would also be good to have an explicit API for pseudo-random number generation, ideally with the new seed value returned each time so it can be passed along by the caller.<br> </div> Fri, 12 Dec 2014 12:38:29 +0000 OpenBSD routes around POSIX https://lwn.net/Articles/625806/ https://lwn.net/Articles/625806/ marcH <div class="FormattedComment"> Every time anyone says or writes "Everyone just do this!", a kitten dies. Or worse.<br> <p> This is why OpenBSD strives to be "secure by default" in all possible ways. Seems reasonably successful so far.<br> <p> <p> </div> Thu, 11 Dec 2014 18:01:34 +0000 OpenBSD routes around POSIX https://lwn.net/Articles/625803/ https://lwn.net/Articles/625803/ alankila <div class="FormattedComment"> Since you mention MT, I thought I'll add a bit here. My new geek hero, Melissa O'Neill, recently invented a new family of random number generators called PCG, where P stands for permuted. It's basically linear congruential generator combined to an output improving step, usually some variant of xor and shifting, but the consequence is a generator whose performance is near theoretical optimum, as it seems to pass statistical tests using fewest possible bits of state, e.g. mere 32 bits suffice to pass the SmallCrush test suite.<br> </div> Thu, 11 Dec 2014 17:46:07 +0000 OpenBSD routes around POSIX https://lwn.net/Articles/625802/ https://lwn.net/Articles/625802/ itvirta <div class="FormattedComment"> Yes. <br> <p> But it's hard to know if a given use of rand() is security-sensitive or not. <br> It seems the argument here is that this is an easy solution to a certain class of<br> possible problems. Certainly easier than actually going through all the uses and,<br> educating the coders and replacing the calls with something more suitable.<br> Supposedly computers are fast enough to use a better rng, too.<br> <p> <p> <p> <p> </div> Thu, 11 Dec 2014 17:40:48 +0000 OpenBSD routes around POSIX https://lwn.net/Articles/625748/ https://lwn.net/Articles/625748/ lambda <blockquote>3) Emit a warning whenever an application makes a call to time() and subsequently makes a call to seed the RNG with the same value.</blockquote> <p>Ted Unangst wrote <a href="http://www.tedunangst.com/flak/post/random-in-the-wild">a good blog post on all of the broken, bizarre ways that people seed random number generators in programs</a>. Theo de Raadt also listed <a href="http://marc.info/?l=openbsd-tech&m=141776286105814&w=2">all of the arbitrary constant values people use as seeds</a>. It goes way beyond just seeding it with time(). <p>The sheer amount of dubious use of constant and other arbitrary seed values, coupled with the relatively low number of packages that actually depend on deterministic behavior, is part of the justification they used for doing the breaking change. Now, such a breaking change really wouldn't work well in the Linux world, but if you want to root this out, you're going to need to do better than just looking for the output of time(). Thu, 11 Dec 2014 15:52:11 +0000 OpenBSD routes around POSIX https://lwn.net/Articles/625724/ https://lwn.net/Articles/625724/ mpr22 Anyone who uses <tt>rand()</tt> for anything <em>remotely</em> security sensitive is sufficiently clueless about security (and C programming) that trying to remove the "sharp implements" from their environment is a lost cause. Thu, 11 Dec 2014 14:14:26 +0000 OpenBSD routes around POSIX https://lwn.net/Articles/625680/ https://lwn.net/Articles/625680/ marcH <div class="FormattedComment"> <font class="QuotedText">&gt; "If rand() is called before any calls to srand() are made, the same sequence shall be generated as when srand() is first called with a seed value of 1."</font><br> <p> I imagine that the number of packages rely on this (not terribly useful...) property is even smaller than the number of OpenBSD that Theo wants to "break".<br> <p> Breaking backward compatibility is bad. Preserving "insecure by default" behaviours is worse?<br> <p> </div> Thu, 11 Dec 2014 09:57:03 +0000 OpenBSD routes around POSIX https://lwn.net/Articles/625657/ https://lwn.net/Articles/625657/ butlerm <div class="FormattedComment"> Generating non-deterministic output if no seed is set is a violation of the POSIX and ISO C standards, unfortunately, which state:<br> <p> "If rand() is called before any calls to srand() are made, the same sequence shall be generated as when srand() is first called with a seed value of 1."<br> <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/rand.html">http://pubs.opengroup.org/onlinepubs/9699919799/functions...</a><br> <p> Emitting a warning could be problematic too, unless it were done during compilation instead of at runtime of course.<br> <p> <p> </div> Thu, 11 Dec 2014 07:29:23 +0000 OpenBSD routes around POSIX https://lwn.net/Articles/625651/ https://lwn.net/Articles/625651/ rsidd <div class="FormattedComment"> Most people who do scientific simulations don't use the OS RNG functions -- they use, eg, the GSL versions (which support specifying a seed and replaying) or something else. Mainly, the OS-supplied versions are unreliable -- even if the OpenBSD version is excellent, the program needs to be portable. <br> </div> Thu, 11 Dec 2014 05:44:01 +0000 OpenBSD routes around POSIX https://lwn.net/Articles/625646/ https://lwn.net/Articles/625646/ jzbiciak <P>I actually use a deterministic random number generator in many of my programs, exactly for the purpose of reproducibility. But, I'm writing programs such as "random test generators" where a given input plus a given seed should produce the same test every time.</P> <P>I <I>also</I> therefore use a dedicated random number class. (C++11 makes this very easy and very nice.) In fact, I use what I call "forked" random number generators, where a master generator (seeded by the test case seed) seeds child generators that I then hand to various subsystems. (Those children can be forked further for sub-subsystems, etc.)</P> <P>The behavior of the whole tree depends on the original seed, but a tweak in behavior in one subsystem doesn't disturb the stream of pseudo-random numbers in another subsystem. This makes debugging and testing go much more smoothly.</P> <P>All this to say: If you're writing simulation software that relies on the quality of the random numbers, reproducibility, and portability across multiple platforms, you likely abandoned the standard library rand()/random()/xrand48() a long time ago. You probably grabbed a copy of Mersenne Twister or any number of other, better generators and wrote your own wrappers around these things. I know I did eons ago. (And now with C++11's excellent random number library, I'm doing it with much less pain.)</P> <P>I guess a part of me is a little surprised that 8800 packages showed up using rand() and friends. Then again, how many of them are <I>actually</I> negatively affected by bad random numbers?</P> Thu, 11 Dec 2014 04:38:40 +0000 OpenBSD routes around POSIX https://lwn.net/Articles/625642/ https://lwn.net/Articles/625642/ mathstuf <div class="FormattedComment"> I think that de Raadt probably sees the problem as serious enough to warrant the change. There are functions such as srand_deterministic and rand_deterministic already. But these have always been platform-specific anyways (so expecting Windows to give the same stream as Linux (or even glibc and musl) was already a lost cause for replays and such). de Raadt was also nice enough to come up with a list of projects which seem to actually expect the "deterministic" API, but that is of course limited to the OpenBSD ports selection.<br> </div> Thu, 11 Dec 2014 03:45:55 +0000 OpenBSD routes around POSIX https://lwn.net/Articles/625628/ https://lwn.net/Articles/625628/ josh <div class="FormattedComment"> It seems like glibc could safely use a similar but slightly more conservative approach. rand() and family are deterministic but system-specific; the same seed value is *not* guaranteed to produce the same result on other systems, or even on a different version of the same system. So:<br> <p> 1) For applications that never seed the RNG, automatically use a cryptographically secure RNG.<br> <p> 2) For applications that do seed the RNG, use the result to seed a deterministic but otherwise secure PRNG (*not* a simple linear congruential generator).<br> <p> 3) Emit a warning whenever an application makes a call to time() and subsequently makes a call to seed the RNG with the same value.<br> </div> Thu, 11 Dec 2014 02:28:52 +0000 OpenBSD routes around POSIX https://lwn.net/Articles/625625/ https://lwn.net/Articles/625625/ JoeBuck For uses of random numbers that are unrelated to cryptography, the ability to replay the sequence is an important feature. This is particularly true for simulation: if a bug is found from random simulation, fuzzing, or the like, you want to be able to find it again. If the seed is recorded the interesting traces can be replayed, and seeds can be produced using truly random processes to sample more of the simulation space. <p> Seems to me that it would be better to use a new API for applications that need truly random numbers rather than breaking portability on the old one. Thu, 11 Dec 2014 02:02:29 +0000