Commit 656c8e9c authored by Dirk Morris's avatar Dirk Morris Committed by Pablo Neira Ayuso

netfilter: conntrack: Use consistent ct id hash calculation

Change ct id hash calculation to only use invariants.

Currently the ct id hash calculation is based on some fields that can
change in the lifetime on a conntrack entry in some corner cases. The
current hash uses the whole tuple which contains an hlist pointer which
will change when the conntrack is placed on the dying list resulting in
a ct id change.

This patch also removes the reply-side tuple and extension pointer from
the hash calculation so that the ct id will will not change from
initialization until confirmation.

Fixes: 3c791076 ("netfilter: ctnetlink: don't use conntrack/expect object addresses as id")
Signed-off-by: default avatarDirk Morris <dmorris@metaloft.com>
Acked-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 1e5b2471
...@@ -453,13 +453,12 @@ EXPORT_SYMBOL_GPL(nf_ct_invert_tuple); ...@@ -453,13 +453,12 @@ EXPORT_SYMBOL_GPL(nf_ct_invert_tuple);
* table location, we assume id gets exposed to userspace. * table location, we assume id gets exposed to userspace.
* *
* Following nf_conn items do not change throughout lifetime * Following nf_conn items do not change throughout lifetime
* of the nf_conn after it has been committed to main hash table: * of the nf_conn:
* *
* 1. nf_conn address * 1. nf_conn address
* 2. nf_conn->ext address * 2. nf_conn->master address (normally NULL)
* 3. nf_conn->master address (normally NULL) * 3. the associated net namespace
* 4. tuple * 4. the original direction tuple
* 5. the associated net namespace
*/ */
u32 nf_ct_get_id(const struct nf_conn *ct) u32 nf_ct_get_id(const struct nf_conn *ct)
{ {
...@@ -469,9 +468,10 @@ u32 nf_ct_get_id(const struct nf_conn *ct) ...@@ -469,9 +468,10 @@ u32 nf_ct_get_id(const struct nf_conn *ct)
net_get_random_once(&ct_id_seed, sizeof(ct_id_seed)); net_get_random_once(&ct_id_seed, sizeof(ct_id_seed));
a = (unsigned long)ct; a = (unsigned long)ct;
b = (unsigned long)ct->master ^ net_hash_mix(nf_ct_net(ct)); b = (unsigned long)ct->master;
c = (unsigned long)ct->ext; c = (unsigned long)nf_ct_net(ct);
d = (unsigned long)siphash(&ct->tuplehash, sizeof(ct->tuplehash), d = (unsigned long)siphash(&ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
sizeof(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple),
&ct_id_seed); &ct_id_seed);
#ifdef CONFIG_64BIT #ifdef CONFIG_64BIT
return siphash_4u64((u64)a, (u64)b, (u64)c, (u64)d, &ct_id_seed); return siphash_4u64((u64)a, (u64)b, (u64)c, (u64)d, &ct_id_seed);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment