-1

There is a random number generator in Linux kernel. This usually is called LRNG(Linux Random Number Generator). We can use it by calling get_random_bytes(). But stack_canary and stack_top are generated by get_random_int(). Although Linux kernel has own good random number generator(LRNG), why does Linux kernel generates it by get_random_int()? I think that it maybe is because of efficiency. Is it right?

1

Just read the source:

Get a random word for internal kernel use only. Similar to urandom but with the goal of minimal entropy pool depletion. As a result, the random value is not cryptographically secure but for several uses the cost of depleting entropy is too high

That's why get_random_int doesn't just take the output of get_random_bytes. As it happens, the arguments here are wrong for two reasons:

  • Entropy doesn't actually deplete. That's just a bogus calculation inside the kernel.
  • Even if entropy did deplete, it would be no reason not to use a cryptographically secure pseudorandom number generator instead of an ad hoc construct. Just use a separate instance from the one that depletes the entropy for /dev/random. Performance could be a reason, but the difference between a proper CSPRNG such as Hash_DRBG/SHA-2 and the ad hoc construction here using MD5 is tiny.
0

Linux's /dev/random, /dev/urandom, and get_random_bytes() tied to the same internal entropy pool. It is quite possible to drain it when using for just RNG and cause /dev/random to block and /dev/urandom to produce low-entropy output. This low entropy condition creates issues for crypto.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.