Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=be776281aee54626a474ba06f91926b98bdd180d
Commit:     be776281aee54626a474ba06f91926b98bdd180d
Parent:     35fc92a9deee0da6e35fdc3150bb134e58f2fd63
Author:     Eric Dumazet <[EMAIL PROTECTED]>
AuthorDate: Tue Mar 27 13:53:04 2007 -0700
Committer:  David S. Miller <[EMAIL PROTECTED]>
CommitDate: Wed Apr 25 22:28:17 2007 -0700

    [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 <[EMAIL PROTECTED]>
    Signed-off-by: David S. Miller <[EMAIL PROTECTED]>
---
 net/ipv4/af_inet.c |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index b7b7278..45ced52 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -218,13 +218,23 @@ out:
        return err;
 }
 
-u32 inet_ehash_secret;
+u32 inet_ehash_secret __read_mostly;
 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)
 {
-       while (!inet_ehash_secret)
-               get_random_bytes(&inet_ehash_secret, 4);
+       u32 rnd;
+       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);
 
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to