netfilter: xt_connlimit: remove connlimit_rnd_inited
authorChangli Gao <xiaosuo@gmail.com>
Tue, 15 Mar 2011 12:26:32 +0000 (13:26 +0100)
committerPatrick McHardy <kaber@trash.net>
Tue, 15 Mar 2011 12:26:32 +0000 (13:26 +0100)
A potential race condition when generating connlimit_rnd is also fixed.

Signed-off-by: Changli Gao <xiaosuo@gmail.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
net/netfilter/xt_connlimit.c

index da56d6ec13c9278c42fabe026a72e25be6bd2585..c6d5a83450c9b414462c91ab6fb4bf08f48402af 100644 (file)
@@ -44,7 +44,6 @@ struct xt_connlimit_data {
 };
 
 static u_int32_t connlimit_rnd __read_mostly;
-static bool connlimit_rnd_inited __read_mostly;
 
 static inline unsigned int connlimit_iphash(__be32 addr)
 {
@@ -226,9 +225,13 @@ static int connlimit_mt_check(const struct xt_mtchk_param *par)
        unsigned int i;
        int ret;
 
-       if (unlikely(!connlimit_rnd_inited)) {
-               get_random_bytes(&connlimit_rnd, sizeof(connlimit_rnd));
-               connlimit_rnd_inited = true;
+       if (unlikely(!connlimit_rnd)) {
+               u_int32_t rand;
+
+               do {
+                       get_random_bytes(&rand, sizeof(rand));
+               } while (!rand);
+               cmpxchg(&connlimit_rnd, 0, rand);
        }
        ret = nf_ct_l3proto_try_module_get(par->family);
        if (ret < 0) {