* [PATCH next 1/2] net: netfilter: avoid get_random_bytes calls
@ 2013-12-19 17:25 Florian Westphal
2013-12-19 17:25 ` [PATCH next 2/2] netfilter: ctnetlink: honor CTA_MARK_MASK when setting ctmark Florian Westphal
2013-12-20 9:33 ` [PATCH next 1/2] net: netfilter: avoid get_random_bytes calls Pablo Neira Ayuso
0 siblings, 2 replies; 4+ messages in thread
From: Florian Westphal @ 2013-12-19 17:25 UTC (permalink / raw)
To: netfilter-devel; +Cc: Florian Westphal
All these users need an initial seed value for jhash, prandom is
perfectly fine. This avoids draining the entropy pool where
its not strictly required.
nfnetlink_log did not use the random value at all.
Signed-off-by: Florian Westphal <fw@strlen.de>
---
Did not convert NFQUEUE since Eric Leblond already sent patches for it.
net/netfilter/nfnetlink_log.c | 8 --------
net/netfilter/nft_hash.c | 2 +-
net/netfilter/xt_RATEEST.c | 2 +-
net/netfilter/xt_connlimit.c | 2 +-
net/netfilter/xt_hashlimit.c | 2 +-
net/netfilter/xt_recent.c | 2 +-
6 files changed, 5 insertions(+), 13 deletions(-)
diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
index 3c4b69e..7d4254b 100644
--- a/net/netfilter/nfnetlink_log.c
+++ b/net/netfilter/nfnetlink_log.c
@@ -28,8 +28,6 @@
#include <linux/proc_fs.h>
#include <linux/security.h>
#include <linux/list.h>
-#include <linux/jhash.h>
-#include <linux/random.h>
#include <linux/slab.h>
#include <net/sock.h>
#include <net/netfilter/nf_log.h>
@@ -75,7 +73,6 @@ struct nfulnl_instance {
};
#define INSTANCE_BUCKETS 16
-static unsigned int hash_init;
static int nfnl_log_net_id __read_mostly;
@@ -1066,11 +1063,6 @@ static int __init nfnetlink_log_init(void)
{
int status = -ENOMEM;
- /* it's not really all that important to have a random value, so
- * we can do this from the init function, even if there hasn't
- * been that much entropy yet */
- get_random_bytes(&hash_init, sizeof(hash_init));
-
netlink_register_notifier(&nfulnl_rtnl_notifier);
status = nfnetlink_subsys_register(&nfulnl_subsys);
if (status < 0) {
diff --git a/net/netfilter/nft_hash.c b/net/netfilter/nft_hash.c
index 3d3f8fc..6aae699 100644
--- a/net/netfilter/nft_hash.c
+++ b/net/netfilter/nft_hash.c
@@ -164,7 +164,7 @@ static int nft_hash_init(const struct nft_set *set,
unsigned int cnt, i;
if (unlikely(!nft_hash_rnd_initted)) {
- get_random_bytes(&nft_hash_rnd, 4);
+ nft_hash_rnd = prandom_u32();
nft_hash_rnd_initted = true;
}
diff --git a/net/netfilter/xt_RATEEST.c b/net/netfilter/xt_RATEEST.c
index 370adf6..190854b 100644
--- a/net/netfilter/xt_RATEEST.c
+++ b/net/netfilter/xt_RATEEST.c
@@ -100,7 +100,7 @@ static int xt_rateest_tg_checkentry(const struct xt_tgchk_param *par)
int ret;
if (unlikely(!rnd_inited)) {
- get_random_bytes(&jhash_rnd, sizeof(jhash_rnd));
+ jhash_rnd = prandom_u32();
rnd_inited = true;
}
diff --git a/net/netfilter/xt_connlimit.c b/net/netfilter/xt_connlimit.c
index c40b269..7671e82 100644
--- a/net/netfilter/xt_connlimit.c
+++ b/net/netfilter/xt_connlimit.c
@@ -229,7 +229,7 @@ static int connlimit_mt_check(const struct xt_mtchk_param *par)
u_int32_t rand;
do {
- get_random_bytes(&rand, sizeof(rand));
+ rand = prandom_u32();
} while (!rand);
cmpxchg(&connlimit_rnd, 0, rand);
}
diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
index 9ff035c..a83a35c 100644
--- a/net/netfilter/xt_hashlimit.c
+++ b/net/netfilter/xt_hashlimit.c
@@ -177,7 +177,7 @@ dsthash_alloc_init(struct xt_hashlimit_htable *ht,
/* initialize hash with random val at the time we allocate
* the first hashtable entry */
if (unlikely(!ht->rnd_initialized)) {
- get_random_bytes(&ht->rnd, sizeof(ht->rnd));
+ ht->rnd = prandom_u32();
ht->rnd_initialized = true;
}
diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
index 1e657cf..bfdc29f 100644
--- a/net/netfilter/xt_recent.c
+++ b/net/netfilter/xt_recent.c
@@ -334,7 +334,7 @@ static int recent_mt_check(const struct xt_mtchk_param *par,
size_t sz;
if (unlikely(!hash_rnd_inited)) {
- get_random_bytes(&hash_rnd, sizeof(hash_rnd));
+ hash_rnd = prandom_u32();
hash_rnd_inited = true;
}
if (info->check_set & ~XT_RECENT_VALID_FLAGS) {
--
1.8.1.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH next 2/2] netfilter: ctnetlink: honor CTA_MARK_MASK when setting ctmark
2013-12-19 17:25 [PATCH next 1/2] net: netfilter: avoid get_random_bytes calls Florian Westphal
@ 2013-12-19 17:25 ` Florian Westphal
2013-12-20 9:33 ` Pablo Neira Ayuso
2013-12-20 9:33 ` [PATCH next 1/2] net: netfilter: avoid get_random_bytes calls Pablo Neira Ayuso
1 sibling, 1 reply; 4+ messages in thread
From: Florian Westphal @ 2013-12-19 17:25 UTC (permalink / raw)
To: netfilter-devel; +Cc: Florian Westphal
Useful to only set a particular range of the conntrack mark while
leaving exisiting parts of the value alone, e.g. when setting
conntrack marks via NFQUEUE.
Follows same scheme as MARK/CONNMARK targets, i.e. the mask defines
those bits that should be altered. No mask is equal to '~0', ie.
the old value is replaced by new one.
Signed-off-by: Florian Westphal <fw@strlen.de>
---
net/netfilter/nf_conntrack_netlink.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index 08870b8..bb322d0 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -2118,8 +2118,16 @@ ctnetlink_nfqueue_parse_ct(const struct nlattr *cda[], struct nf_conn *ct)
return err;
}
#if defined(CONFIG_NF_CONNTRACK_MARK)
- if (cda[CTA_MARK])
- ct->mark = ntohl(nla_get_be32(cda[CTA_MARK]));
+ if (cda[CTA_MARK]) {
+ u32 mask = 0, mark, newmark;
+ if (cda[CTA_MARK_MASK])
+ mask = ~ntohl(nla_get_be32(cda[CTA_MARK_MASK]));
+
+ mark = ntohl(nla_get_be32(cda[CTA_MARK]));
+ newmark = (ct->mark & mask) ^ mark;
+ if (newmark != ct->mark)
+ ct->mark = newmark;
+ }
#endif
return 0;
}
--
1.8.1.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH next 1/2] net: netfilter: avoid get_random_bytes calls
2013-12-19 17:25 [PATCH next 1/2] net: netfilter: avoid get_random_bytes calls Florian Westphal
2013-12-19 17:25 ` [PATCH next 2/2] netfilter: ctnetlink: honor CTA_MARK_MASK when setting ctmark Florian Westphal
@ 2013-12-20 9:33 ` Pablo Neira Ayuso
1 sibling, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2013-12-20 9:33 UTC (permalink / raw)
To: Florian Westphal; +Cc: netfilter-devel
On Thu, Dec 19, 2013 at 06:25:14PM +0100, Florian Westphal wrote:
> All these users need an initial seed value for jhash, prandom is
> perfectly fine. This avoids draining the entropy pool where
> its not strictly required.
>
> nfnetlink_log did not use the random value at all.
Applied, thanks Florian.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH next 2/2] netfilter: ctnetlink: honor CTA_MARK_MASK when setting ctmark
2013-12-19 17:25 ` [PATCH next 2/2] netfilter: ctnetlink: honor CTA_MARK_MASK when setting ctmark Florian Westphal
@ 2013-12-20 9:33 ` Pablo Neira Ayuso
0 siblings, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2013-12-20 9:33 UTC (permalink / raw)
To: Florian Westphal; +Cc: netfilter-devel
On Thu, Dec 19, 2013 at 06:25:15PM +0100, Florian Westphal wrote:
> Useful to only set a particular range of the conntrack mark while
> leaving exisiting parts of the value alone, e.g. when setting
> conntrack marks via NFQUEUE.
>
> Follows same scheme as MARK/CONNMARK targets, i.e. the mask defines
> those bits that should be altered. No mask is equal to '~0', ie.
> the old value is replaced by new one.
Also applied, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-12-20 9:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-19 17:25 [PATCH next 1/2] net: netfilter: avoid get_random_bytes calls Florian Westphal
2013-12-19 17:25 ` [PATCH next 2/2] netfilter: ctnetlink: honor CTA_MARK_MASK when setting ctmark Florian Westphal
2013-12-20 9:33 ` Pablo Neira Ayuso
2013-12-20 9:33 ` [PATCH next 1/2] net: netfilter: avoid get_random_bytes calls Pablo Neira Ayuso
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).