DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	Selwin Sebastian <selwin.sebastian@amd.com>,
	Julien Aube <julien_dpdk@jaube.fr>
Subject: [PATCH 13/18] drivers/net: use secure random for RSS key
Date: Tue, 15 Sep 2026 12:21:11 -0700	[thread overview]
Message-ID: <20260915192207.3926217-14-stephen@networkplumber.org> (raw)
In-Reply-To: <20260915192207.3926217-1-stephen@networkplumber.org>

Both drivers built the default RSS key a word at a time from rte_rand().
That generator is a fast non-cryptographic PRNG whose state is
recoverable from its output, so the resulting key is predictable.

Use rte_random_bytes() which takes randomness from the operating
system, and report the error to the caller.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/axgbe/axgbe_dev.c | 16 +++++++++++-----
 drivers/net/bnx2x/bnx2x.c     | 11 +++++++----
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/drivers/net/axgbe/axgbe_dev.c b/drivers/net/axgbe/axgbe_dev.c
index 482d3d8062..37856fddd9 100644
--- a/drivers/net/axgbe/axgbe_dev.c
+++ b/drivers/net/axgbe/axgbe_dev.c
@@ -3,6 +3,8 @@
  *   Copyright(c) 2018 Synopsys, Inc. All rights reserved.
  */
 
+#include <rte_random.h>
+
 #include "axgbe_ethdev.h"
 #include "axgbe_common.h"
 #include "axgbe_phy.h"
@@ -931,13 +933,15 @@ static void axgbe_rss_options(struct axgbe_port *pdata)
 static int axgbe_config_rss(struct axgbe_port *pdata)
 {
 	uint32_t i;
+	int ret;
 
 	if (pdata->rss_enable) {
 		/* Initialize RSS hash key and lookup table */
-		uint32_t *key = (uint32_t *)pdata->rss_key;
-
-		for (i = 0; i < sizeof(pdata->rss_key) / 4; i++)
-			*key++ = (uint32_t)rte_rand();
+		ret = rte_random_bytes(pdata->rss_key, sizeof(pdata->rss_key));
+		if (ret != 0) {
+			PMD_DRV_LOG_LINE(ERR, "Error generating RSS hash key");
+			return ret;
+		}
 		for (i = 0; i < AXGBE_RSS_MAX_TABLE_SIZE; i++)
 			AXGMAC_SET_BITS(pdata->rss_table[i], MAC_RSSDR, DMCH,
 					i % pdata->eth_dev->data->nb_rx_queues);
@@ -1393,7 +1397,9 @@ static int axgbe_init(struct axgbe_port *pdata)
 	axgbe_config_tx_pbl_val(pdata);
 	axgbe_config_rx_pbl_val(pdata);
 	axgbe_config_rx_buffer_size(pdata);
-	axgbe_config_rss(pdata);
+	ret = axgbe_config_rss(pdata);
+	if (ret)
+		return ret;
 	axgbe_config_tso_mode(pdata);
 	wrapper_tx_desc_init(pdata);
 	ret = wrapper_rx_desc_init(pdata);
diff --git a/drivers/net/bnx2x/bnx2x.c b/drivers/net/bnx2x/bnx2x.c
index 8790c858d5..97ee95a1be 100644
--- a/drivers/net/bnx2x/bnx2x.c
+++ b/drivers/net/bnx2x/bnx2x.c
@@ -28,6 +28,7 @@
 #include <zlib.h>
 
 #include <rte_bitops.h>
+#include <rte_random.h>
 #include <rte_string_fns.h>
 
 #include "eal_firmware.h"
@@ -6643,7 +6644,7 @@ bnx2x_config_rss_pf(struct bnx2x_softc *sc, struct ecore_rss_config_obj *rss_obj
 		  uint8_t config_hash)
 {
 	struct ecore_config_rss_params params = { NULL };
-	uint32_t i;
+	int rc;
 
 	/*
 	 * Although RSS is meaningless when there is a single HW queue we
@@ -6675,9 +6676,11 @@ bnx2x_config_rss_pf(struct bnx2x_softc *sc, struct ecore_rss_config_obj *rss_obj
 			 sizeof(params.ind_table));
 
 	if (config_hash) {
-/* RSS keys */
-		for (i = 0; i < sizeof(params.rss_key) / 4; i++) {
-			params.rss_key[i] = (uint32_t) rte_rand();
+		/* RSS keys */
+		rc = rte_random_bytes(params.rss_key, sizeof(params.rss_key));
+		if (rc != 0) {
+			PMD_DRV_LOG(ERR, sc, "Error generating RSS hash key");
+			return rc;
 		}
 
 		rte_bit_relaxed_set32(ECORE_RSS_SET_SRCH, &params.rss_flags);
-- 
2.53.0


  parent reply	other threads:[~2026-09-15 19:23 UTC|newest]

Thread overview: 27+ 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 ` [PATCH 02/18] random: always use getentropy Stephen Hemminger
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 ` Stephen Hemminger [this message]
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

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-14-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=julien_dpdk@jaube.fr \
    --cc=selwin.sebastian@amd.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox