aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4
diff options
context:
space:
mode:
authorEric Dumazet <dada1@cosmosbay.com>2007-03-27 16:53:04 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-04-26 01:28:17 -0400
commitbe776281aee54626a474ba06f91926b98bdd180d (patch)
tree7f397daec3c52ca04267186450f290f5e0ea3c5f /net/ipv4
parent35fc92a9deee0da6e35fdc3150bb134e58f2fd63 (diff)
[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: Eric Dumazet <dada1@cosmosbay.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r--net/ipv4/af_inet.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index b7b7278d801c..45ced52c03d4 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -218,13 +218,23 @@ out:
218 return err; 218 return err;
219} 219}
220 220
221u32 inet_ehash_secret; 221u32 inet_ehash_secret __read_mostly;
222EXPORT_SYMBOL(inet_ehash_secret); 222EXPORT_SYMBOL(inet_ehash_secret);
223 223
224/*
225 * inet_ehash_secret must be set exactly once
226 * Instead of using a dedicated spinlock, we (ab)use inetsw_lock
227 */
224void build_ehash_secret(void) 228void build_ehash_secret(void)
225{ 229{
226 while (!inet_ehash_secret) 230 u32 rnd;
227 get_random_bytes(&inet_ehash_secret, 4); 231 do {
232 get_random_bytes(&rnd, sizeof(rnd));
233 } while (rnd == 0);
234 spin_lock_bh(&inetsw_lock);
235 if (!inet_ehash_secret)
236 inet_ehash_secret = rnd;
237 spin_unlock_bh(&inetsw_lock);
228} 238}
229EXPORT_SYMBOL(build_ehash_secret); 239EXPORT_SYMBOL(build_ehash_secret);
230 240