Commit be776281 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

[NET]: inet_ehash_secret should be __read_mostly and set only once

There is a very tiny probability that build_ehash_secret() is called
at the same time by different CPUS.

Also, using __read_mostly is a must for inet_ehash_secret
Signed-off-by: default avatarEric Dumazet <dada1@cosmosbay.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 35fc92a9
...@@ -218,13 +218,23 @@ int inet_listen(struct socket *sock, int backlog) ...@@ -218,13 +218,23 @@ int inet_listen(struct socket *sock, int backlog)
return err; return err;
} }
u32 inet_ehash_secret; u32 inet_ehash_secret __read_mostly;
EXPORT_SYMBOL(inet_ehash_secret); EXPORT_SYMBOL(inet_ehash_secret);
/*
* inet_ehash_secret must be set exactly once
* Instead of using a dedicated spinlock, we (ab)use inetsw_lock
*/
void build_ehash_secret(void) void build_ehash_secret(void)
{ {
while (!inet_ehash_secret) u32 rnd;
get_random_bytes(&inet_ehash_secret, 4); do {
get_random_bytes(&rnd, sizeof(rnd));
} while (rnd == 0);
spin_lock_bh(&inetsw_lock);
if (!inet_ehash_secret)
inet_ehash_secret = rnd;
spin_unlock_bh(&inetsw_lock);
} }
EXPORT_SYMBOL(build_ehash_secret); EXPORT_SYMBOL(build_ehash_secret);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment