Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix use of rand + improve entropy-exhaustion
Possible fix for containers/podman#12155 The golang docs for `math/rand` specifically mention that `rand.Seed()` should never ever be used in conjunction with any other rand method. Fix this with a simple/local mutex to protect critical code sections. This could be made more safe by exposing the mutex to downstream callers. This is left up to a future commit as/if needed. Also, in entropy-exhaustion situations it's possible for multiple concurrent *processes* to obtain the same fallback seed value, where the lock will not provide any protection. Clashes here are especially bad given the large number of downstream users of `GenerateNonCryptoID()`. Since the Linux kernel guarantees process ID uniqueness within a reasonable timespan, include this value into the fallback seed (along with the time). This is *not* a perfect solution, it is still possible for two processes to generate the same fallback seed value, given extremely unlucky timing. However, this is an improvement versus simplistic reliance on the clock. Signed-off-by: Chris Evich <[email protected]>
- Loading branch information