member: fix PRNG seed reset in NitroSketch mode
PATCH 1/1 member: fix PRNG seed reset in NitroSketch mode
Sketch creation seeded the global PRNG
using the supplied seed for hashing.
The use of this seed by SKETCH set summary was not documented. SKETCH set summary does not require two independent hash seeds, unlike other set summary types.
Seeding the global PRNG at sketch creation
does not make the sketch operation deterministic:
it uses rte_rand() later, the PRNG may be seeded again by that point. On the other hand, seeding the global PRNG with a hash seed, is likely undesired, because it may be low-entropy or even constant. Deterministic operation can be achieved by seeding the PRNG externally.
Remove the call to rte_srand() at sketch creation. Document that hash seeds are not used by SKETCH set summary type.
--- lib/member/rte_member.h | 1 + lib/member/rte_member_sketch.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-)
lib/member/rte_member.h +1 -0
@@ -314,6 +314,7 @@ struct rte_member_parameters {* for bucket location. * For vBF type, these two hashes and their combinations are used as * hash locations to index the bit array. +* For Sketch type, these seeds are not used. */ uint32_t prim_hash_seed;
lib/member/rte_member_sketch.c +0 -1
@@ -227,7 +227,6 @@ rte_member_create_sketch(struct rte_member_setsum *ss, goto error_runtime; } -rte_srand (ss->prim_hash_seed);for (i =0 ; i < ss->num_row; i++) ss->hash_seeds[i] =rte_rand ();
Signature · 1 line
2.38.4
Any comment?
20/06/2023 23:17, Dmitry Kozlyuk:
Quoted 49 lines
Sketch creation seeded the global PRNG
using the supplied seed for hashing.
The use of this seed by SKETCH set summary was not documented. SKETCH set summary does not require two independent hash seeds, unlike other set summary types.
Seeding the global PRNG at sketch creation
does not make the sketch operation deterministic:
it usesrte_rand()later, the PRNG may be seeded again by that point. On the other hand, seeding the global PRNG with a hash seed, is likely undesired, because it may be low-entropy or even constant. Deterministic operation can be achieved by seeding the PRNG externally.Remove the call to
rte_srand()at sketch creation. Document that hash seeds are not used by SKETCH set summary type.Fixes db354bd2e1f8 ("member: add NitroSketch mode")Signed-off-by Dmitry Kozlyuk <[email protected]>--- lib/member/rte_member.h | 1 + lib/member/rte_member_sketch.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-)lib/member/rte_member.h +1
-0@@ -314,6 +314,7 @@ struct rte_member_parameters {* for bucket location. * For vBF type, these two hashes and their combinations are used as * hash locations to index the bit array. +* For Sketch type, these seeds are not used. */ uint32_t prim_hash_seed;lib/member/rte_member_sketch.c +0
-1@@ -227,7 +227,6 @@ rte_member_create_sketch(struct rte_member_setsum *ss, goto error_runtime; } -rte_srand (ss->prim_hash_seed);for (i =0 ; i < ss->num_row; i++) ss->hash_seeds[i] =rte_rand ();
Quoted 7 lines · On Wed, 21 Jun 2023 00:17:20 +0300 Dmitry Kozlyuk <[email protected]>…
Seeding the global PRNG at sketch creation
does not make the sketch operation deterministic:
it usesrte_rand()later, the PRNG may be seeded again by that point. On the other hand, seeding the global PRNG with a hash seed, is likely undesired, because it may be low-entropy or even constant. Deterministic operation can be achieved by seeding the PRNG externally.
Quoted 7 lines
Remove the call to
rte_srand()at sketch creation. Document that hash seeds are not used by SKETCH set summary type.Fixes db354bd2e1f8 ("member: add NitroSketch mode")Signed-off-by Dmitry Kozlyuk <[email protected]>
This raises a more global issue.rte_srand() overrides the system seed which is set during startup. This is a bad thing, it reduces the entropy in the random number generator.
There are two possible solutions to this:
1. Remove all all calls to rte_srand() and deprecate it.
2. Make rte_srand() add a fixed value to existing entropy. This is what the kernel PRNG does. It adds any user supplied additional entropy to original state.
Looking at current source.
- code in tests seeding PRNG with TSC. This is unnecessary and can be removed.
- this code in member library. Should be removed.
Thomas Monjalon
Applied03/07/2023 17:54, Stephen Hemminger:
Quoted 28 lines
Quoted 7 lines · On Wed, 21 Jun 2023 00:17:20 +0300 Dmitry Kozlyuk <[email protected]>…
Seeding the global PRNG at sketch creation
does not make the sketch operation deterministic:
it usesrte_rand()later, the PRNG may be seeded again by that point. On the other hand, seeding the global PRNG with a hash seed, is likely undesired, because it may be low-entropy or even constant. Deterministic operation can be achieved by seeding the PRNG externally.Quoted 7 lines
Remove the call to
rte_srand()at sketch creation. Document that hash seeds are not used by SKETCH set summary type.Fixes db354bd2e1f8 ("member: add NitroSketch mode")Signed-off-by Dmitry Kozlyuk <[email protected]>This raises a more global issue.
rte_srand()overrides the system seed which is set during startup. This is a bad thing, it reduces the entropy in the random number generator.There are two possible solutions to this:
1. Remove all all calls torte_srand()and deprecate it.
2. Makerte_srand()add a fixed value to existing entropy. This is what the kernel PRNG does. It adds any user supplied additional entropy to original state.
Quoted 5 lines
Looking at current source.
- code in tests seeding PRNG with TSC. This is unnecessary and can be removed.
- this code in member library. Should be removed.
Applied, thanks.
What's next regarding rte_srand?
Quoted 15 lines · On Thu, 06 Jul 2023 18:20:19 +0200 Thomas Monjalon <[email protected]> wrote:
Quoted 15 lines
This raises a more global issue.
rte_srand()overrides the system seed which is set during startup. This is a bad thing, it reduces the entropy in the random number generator.There are two possible solutions to this:
1. Remove all all calls torte_srand()and deprecate it.
2. Makerte_srand()add a fixed value to existing entropy. This is what the kernel PRNG does. It adds any user supplied additional entropy to original state.Looking at current source.
- code in tests seeding PRNG with TSC. This is unnecessary and can be removed.
- this code in member library. Should be removed.
Quoted 5 lines
Quoted 1 line
Applied, thanks.
What's next regarding
rte_srand?
I am not a random number expert and the topic gets complex with tradeoffs. How secure do you want versus how fast versus how paranoid.
OpenBSD is paranoid. Linux kernel chooses secure. Looks like DPDK is choosing fast like FreeBSD prng.
The problem is (despite documentation) applications end up needing a crypto-graphic secure random numbers. Examples are hash seeds or session keys.