Skip to content

random: fix initial seed entropy

Stephen Hemminger dpdk-dev 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest5 patches 0 repliesNew
  2. v118 patches 3 repliesSuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5eal/windows: add getentropy shimlib/eal/common/rte_random.c lib/eal/windows/include/rte_os_shim.h lib/eal/windows/meson.build+36 -10 replies
2/5random: always use getentropydoc/guides/rel_notes/release_26_11.rst lib/eal/common/rte_random.c lib/eal/include/rte_random.h +1 more+12 -80 replies
3/5random: use all 64 bits of the seeddoc/guides/rel_notes/release_26_11.rst lib/eal/common/rte_random.c+40 -380 replies
4/5random: remove RDSEED fallback for initial seedlib/eal/common/rte_random.c+2 -150 replies
5/5test: allow setting random seed for testsapp/test/test.c doc/guides/contributing/unit_test.rst doc/guides/rel_notes/release_26_11.rst+65 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/5] random: fix initial seed entropy

This series is about how the random number generator is seeded: where the seed comes from, how it is expanded into the generator state, and being able to pin it for repeatable test runs.

The build detection of getentropy() does not work, so DPDK has been seeding its PRNG from RDSEED or the TSC on systems that do have getentropy(). cc.has_function() probes with -std=c11, but glibc hides getentropy() behind _DEFAULT_SOURCE, so the probe always fails.

A TSC derived seed only varies by process start time, which a local attacker can determine.

1/5 adds a Windows getentropy() shim over BCryptGenRandom(), so the
EAL can call getentropy() unconditionally.
2/5 drops the broken probe and always uses getentropy(). The TSC
fallback remains but now logs at ERR with the errno, so a blocked syscall can be told apart from other failures.
3/5 expands the seed with SplitMix64. The two halves of the seed
were folded together and run through a 32 bit LCG, so only 32 bits of the seed had any effect and the five state words had correlated low bits. Per-lcore seeds were the seed plus the lcore id, leaving neighbouring lcores with nearly identical state; that sum now goes through SplitMix64 as well. A given seed therefore produces a different sequence than in previous releases.
4/5 removes the RDSEED fallback. It is unreachable once getentropy()
is always used, and RDSEED has known reliability problems and errata. The kernel already mixes RDSEED into the pool that getentropy() draws from.
5/5 adds a DPDK_TEST_SEED environment variable to the test
application, so runs that build input data with rte_rand() can be made repeatable. Unset behaves as before.

Bugzilla ID: 2035

v2: - rebased
- reduced patch series to only seedinr related changes

Two checks warn deliberately:

1/5 carries Cc: [email protected] without a Fixes: tag. 2/5 is the stable candidate and does not build on Windows without the shim, so 1/5 has to go back with it. The commit message says so.

3/5 has a Fixes: tag and no Cc: stable. It changes the sequence a given seed produces, so a backport would change output for anyone relying on rte_srand() reproducibility on a stable branch.

Stephen Hemminger (5):
eal/windows: add getentropy shim
random: always use getentropy
random: use all 64 bits of the seed
random: remove RDSEED fallback for initial seed
test: allow setting random seed for tests

 app/test/test.c                        | 48 +++++++++++++
 doc/guides/contributing/unit_test.rst  | 15 ++++
 doc/guides/rel_notes/release_26_11.rst | 10 +++
 lib/eal/common/rte_random.c            | 98 +++++++++++---------------
 lib/eal/include/rte_random.h           |  7 +-
 lib/eal/meson.build                    |  3 -
 lib/eal/windows/include/rte_os_shim.h  | 30 ++++++++
 lib/eal/windows/meson.build            |  6 +-
 8 files changed, 155 insertions(+), 62 deletions(-)
Signature · 1 line
2.53.0