From: Changli Gao <xiaosuo@gmail.com>
To: Patrick McHardy <kaber@trash.net>
Cc: "David S. Miller" <davem@davemloft.net>,
netfilter-devel@vger.kernel.org, netdev@vger.kernel.org,
Changli Gao <xiaosuo@gmail.com>
Subject: [PATCH 4/4] netfilter: xt_connlimit: remove connlimit_rnd_inited
Date: Mon, 14 Mar 2011 14:50:14 +0800 [thread overview]
Message-ID: <1300085414-27275-4-git-send-email-xiaosuo@gmail.com> (raw)
In-Reply-To: <1300085414-27275-1-git-send-email-xiaosuo@gmail.com>
A potential race condition when generating connlimit_rnd is also fixed.
Signed-off-by: Changli Gao <xiaosuo@gmail.com>
---
net/netfilter/xt_connlimit.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/net/netfilter/xt_connlimit.c b/net/netfilter/xt_connlimit.c
index da56d6e..c6d5a83 100644
--- a/net/netfilter/xt_connlimit.c
+++ b/net/netfilter/xt_connlimit.c
@@ -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) {
next prev parent reply other threads:[~2011-03-14 6:50 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-14 6:50 [PATCH 1/4] netfilter: xt_connlimit: fix daddr connlimit in SNAT scenario Changli Gao
2011-03-14 6:50 ` [PATCH 2/4] netfilter: xt_connlimit: use kmalloc() instead of kzalloc() Changli Gao
2011-03-15 12:25 ` Patrick McHardy
2011-03-14 6:50 ` [PATCH 3/4] netfilter: xt_connlimit: use hlist instead Changli Gao
2011-03-15 12:26 ` Patrick McHardy
2011-03-14 6:50 ` Changli Gao [this message]
2011-03-15 12:26 ` [PATCH 4/4] netfilter: xt_connlimit: remove connlimit_rnd_inited Patrick McHardy
2011-03-14 12:26 ` [PATCH 1/4] netfilter: xt_connlimit: fix daddr connlimit in SNAT scenario Jan Engelhardt
2011-03-14 12:42 ` Changli Gao
2011-03-14 18:32 ` Patrick McHardy
2011-03-14 19:00 ` Jan Engelhardt
2011-03-14 23:49 ` Changli Gao
2011-03-15 1:16 ` Jan Engelhardt
2011-03-15 1:30 ` Changli Gao
2011-03-15 2:05 ` Jan Engelhardt
2011-03-15 12:21 ` Patrick McHardy
2011-03-15 12:24 ` Patrick McHardy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1300085414-27275-4-git-send-email-xiaosuo@gmail.com \
--to=xiaosuo@gmail.com \
--cc=davem@davemloft.net \
--cc=kaber@trash.net \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).