Skip to contentSkip to conversation

net: use get_random_u32() for net_namespace hash_mix initialization

PATCH In review David Carlier 2 participants 3 messages Apr 3

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: use get_random_u32() for net_namespace hash_mix initialization

Use get_random_u32() instead of get_random_bytes() to initialize net->hash_mix. This is the preferred API for obtaining a single random u32 value, as it returns the value directly rather than writing through a pointer, and requires no size parameter.

---
 net/core/net_namespace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/net_namespace.c +1 -1
index 1057d16d5dd2..deb8b2ec5674 100644
@@ -411,7 +411,7 @@ static __net_init int preinit_net(struct net *net, struct user_namespace *user_n
 	ref_tracker_dir_init(&net->refcnt_tracker, 128, "net_refcnt");
 	ref_tracker_dir_init(&net->notrefcnt_tracker, 128, "net_notrefcnt");
 
-	get_random_bytes(&net->hash_mix, sizeof(u32));
+	net->hash_mix = get_random_u32();
 	net->dev_base_seq = 1;
 	net->user_ns = user_ns;
 
Signature · 1 line
2.53.0
#1 lore raw
Quoted 8 lines · David Carlier

Use get_random_u32() instead of get_random_bytes() to initialize net->hash_mix. This is the preferred API for obtaining a single random u32 value, as it returns the value directly rather than writing through a pointer, and requires no size parameter.

---

I feel a tree-wide patch could be attempted ?

Thanks.

#2 lore raw

Sure !

Quoted 14 lines · Eric Dumazet
Quoted 8 lines · David Carlier

Use get_random_u32() instead of get_random_bytes() to initialize net->hash_mix. This is the preferred API for obtaining a single random u32 value, as it returns the value directly rather than writing through a pointer, and requires no size parameter.

---

I feel a tree-wide patch could be attempted ?

Thanks.