From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: "Stephen Hemminger" <stephen@networkplumber.org>,
stable@dpdk.org,
"Mattias Rönnblom" <mattias.ronnblom@ericsson.com>,
"Bruce Richardson" <bruce.richardson@intel.com>
Subject: [PATCH 02/18] random: always use getentropy
Date: Tue, 15 Sep 2026 12:21:00 -0700 [thread overview]
Message-ID: <20260915192207.3926217-3-stephen@networkplumber.org> (raw)
In-Reply-To: <20260915192207.3926217-1-stephen@networkplumber.org>
The cc.has_function() check compiled its test program under strict
-std=c11, where glibc hides the getentropy() declaration behind
_DEFAULT_SOURCE. The probe therefore always failed on Linux and
RTE_LIBEAL_USE_GETENTROPY was never defined, silently falling back
to RDSEED or TSC for the initial PRNG seed.
Now that a getentropy() wrapper exists for Windows it can always be
enabled. Removing the conditional means any future regression is a
link error rather than a silent downgrade of seed quality.
Falling back to the TSC now logs at ERR level, including the errno
from getentropy() so that a blocked syscall can be told apart from
other failures. A TSC derived seed only varies by process start time,
which a co-resident attacker can bound.
This requires glibc >= 2.25, which all supported distributions meet.
A backport needs the preceding patch which adds the Windows
getentropy() shim, otherwise the Windows build breaks.
Bugzilla ID: 2035
Fixes: faf8fd252785 ("eal: improve entropy for initial PRNG seed")
Cc: stable@dpdk.org
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
doc/guides/rel_notes/release_26_11.rst | 4 ++++
lib/eal/common/rte_random.c | 6 ++++--
lib/eal/include/rte_random.h | 7 ++++---
lib/eal/meson.build | 3 ---
4 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/doc/guides/rel_notes/release_26_11.rst b/doc/guides/rel_notes/release_26_11.rst
index 87c7e81bde..5852f7acfb 100644
--- a/doc/guides/rel_notes/release_26_11.rst
+++ b/doc/guides/rel_notes/release_26_11.rst
@@ -55,6 +55,10 @@ New Features
Also, make sure to start the actual text at the margin.
=======================================================
+* **Updated random number generation.**
+
+ * The initial seed is now always taken from ``getentropy()``.
+
Removed Items
-------------
diff --git a/lib/eal/common/rte_random.c b/lib/eal/common/rte_random.c
index 537fa035ee..b036c50349 100644
--- a/lib/eal/common/rte_random.c
+++ b/lib/eal/common/rte_random.c
@@ -7,6 +7,8 @@
#include <x86intrin.h>
#endif
#endif
+#include <errno.h>
+#include <string.h>
#include <unistd.h>
#include <rte_bitops.h>
@@ -219,7 +221,6 @@ rte_drand(void)
static uint64_t
__rte_random_initial_seed(void)
{
-#ifdef RTE_LIBEAL_USE_GETENTROPY
int ge_rc;
uint64_t ge_seed;
@@ -227,7 +228,6 @@ __rte_random_initial_seed(void)
if (ge_rc == 0)
return ge_seed;
-#endif
#ifdef __RDSEED__
unsigned int rdseed_low;
unsigned int rdseed_high;
@@ -238,6 +238,8 @@ __rte_random_initial_seed(void)
return (uint64_t)rdseed_low | ((uint64_t)rdseed_high << 32);
#endif
/* second fallback: seed using rdtsc */
+ EAL_LOG(ERR, "getentropy() failed (%s), seeding PRNG from TSC: seed has low entropy",
+ strerror(errno));
return rte_get_tsc_cycles();
}
diff --git a/lib/eal/include/rte_random.h b/lib/eal/include/rte_random.h
index 15cbe6215a..978ecda203 100644
--- a/lib/eal/include/rte_random.h
+++ b/lib/eal/include/rte_random.h
@@ -20,9 +20,10 @@ extern "C" {
/**
* Seed the pseudo-random generator.
*
- * The generator is automatically seeded by the EAL init with a timer
- * value. It may need to be re-seeded by the user with a real random
- * value.
+ * The generator is automatically seeded by the EAL init from the
+ * random source provided by the operating system, so there is no need
+ * to re-seed it to get unpredictable values. Seeding it explicitly is
+ * useful to make a run repeatable.
*
* This function is not multi-thread safe in regards to other
* rte_srand() calls, nor is it in relation to concurrent rte_rand(),
diff --git a/lib/eal/meson.build b/lib/eal/meson.build
index f9fcee24ee..2bf3c67439 100644
--- a/lib/eal/meson.build
+++ b/lib/eal/meson.build
@@ -24,9 +24,6 @@ endif
if dpdk_conf.has('RTE_HAS_LIBARCHIVE')
ext_deps += libarchive
endif
-if cc.has_function('getentropy', prefix : '#include <unistd.h>')
- cflags += '-DRTE_LIBEAL_USE_GETENTROPY'
-endif
if is_freebsd
annotate_locks = false
--
2.53.0
next prev parent reply other threads:[~2026-09-15 19:22 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 19:20 [PATCH 00/18] random number generator improvements Stephen Hemminger
2026-09-15 19:20 ` [PATCH 01/18] eal/windows: add getentropy shim Stephen Hemminger
2026-09-15 19:21 ` Stephen Hemminger [this message]
2026-11-10 18:51 ` [PATCH 02/18] random: always use getentropy Bruce Richardson
2026-09-15 19:21 ` [PATCH 03/18] eal: add 32 bit random number function Stephen Hemminger
2026-09-15 19:21 ` [PATCH 04/18] sched: fix data race in RED random number generation Stephen Hemminger
2026-09-15 19:21 ` [PATCH 05/18] eal/windows: add getrandom shim Stephen Hemminger
2026-09-15 19:21 ` [PATCH 06/18] eal: add function to get random bytes Stephen Hemminger
2026-09-15 19:21 ` [PATCH 07/18] hash: use secure random for Toeplitz hash key Stephen Hemminger
2026-09-15 19:21 ` [PATCH 08/18] pipeline: use secure random for IPsec salt Stephen Hemminger
2026-09-15 19:21 ` [PATCH 09/18] net: use secure random for random MAC address Stephen Hemminger
2026-09-15 19:21 ` [PATCH 10/18] ipsec: use secure random for SAD hash seed Stephen Hemminger
2026-09-15 19:21 ` [PATCH 11/18] net/intel: use secure random for default RSS key Stephen Hemminger
2026-09-15 19:21 ` [PATCH 12/18] random: use all 64 bits of the seed Stephen Hemminger
2026-09-15 19:21 ` [PATCH 13/18] drivers/net: use secure random for RSS key Stephen Hemminger
2026-09-15 19:21 ` [PATCH 14/18] drivers/net: use common random MAC address helper Stephen Hemminger
2026-09-15 19:21 ` [PATCH 15/18] random: remove RDSEED fallback for initial seed Stephen Hemminger
2026-09-16 7:44 ` Bruce Richardson
2026-09-15 19:21 ` [PATCH 16/18] test: allow setting random seed for tests Stephen Hemminger
2026-09-15 19:21 ` [PATCH 17/18] test: add random number generator tests Stephen Hemminger
2026-09-15 19:21 ` [PATCH 18/18] doc: recommend secure random for unpredictable values Stephen Hemminger
2026-09-22 12:32 ` Aaron Conole
2026-10-10 2:27 ` [PATCH v2 0/5] random: fix initial seed entropy Stephen Hemminger
2026-10-10 2:27 ` [PATCH v2 1/5] eal/windows: add getentropy shim Stephen Hemminger
2026-10-10 2:27 ` [PATCH v2 2/5] random: always use getentropy Stephen Hemminger
2026-10-10 2:27 ` [PATCH v2 3/5] random: use all 64 bits of the seed Stephen Hemminger
2026-10-10 2:27 ` [PATCH v2 4/5] random: remove RDSEED fallback for initial seed Stephen Hemminger
2026-10-10 2:27 ` [PATCH v2 5/5] test: allow setting random seed for tests Stephen Hemminger
2026-11-27 19:39 ` [PATCH v3 0/5] random: fix initial seed entropy Stephen Hemminger
2026-11-27 19:39 ` [PATCH v3 1/5] eal/windows: add getentropy shim Stephen Hemminger
2026-11-27 19:39 ` [PATCH v3 2/5] random: always use getentropy Stephen Hemminger
2026-11-27 19:39 ` [PATCH v3 3/5] random: use all 64 bits of the seed Stephen Hemminger
2026-11-27 19:39 ` [PATCH v3 4/5] random: remove RDSEED fallback for initial seed Stephen Hemminger
2026-11-27 19:39 ` [PATCH v3 5/5] test: allow setting random seed for tests Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260915192207.3926217-3-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=mattias.ronnblom@ericsson.com \
--cc=stable@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.