Skip to content

Commit b119057

Browse files
strssndktndavem330
authored andcommitted
ipv6: split inet6_hash_frag for netfilter and initialize secrets with net_get_random_once
Defer the fragmentation hash secret initialization for IPv6 like the previous patch did for IPv4. Because the netfilter logic reuses the hash secret we have to split it first. Thus introduce a new nf_hash_frag function which takes care to seed the hash secret. Cc: David S. Miller <davem@davemloft.net> Cc: Eric Dumazet <edumazet@google.com> Cc: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e7b519b commit b119057

3 files changed

Lines changed: 20 additions & 10 deletions

File tree

‎include/net/ipv6.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,8 +805,6 @@ int ip6_mc_source(int add, int omode, struct sock *sk,
805805
int ip6_mc_msfilter(struct sock *sk, struct group_filter *gsf);
806806
int ip6_mc_msfget(struct sock *sk, struct group_filter *gsf,
807807
struct group_filter __user *optval, int __user *optlen);
808-
unsigned int inet6_hash_frag(__be32 id, const struct in6_addr *saddr,
809-
const struct in6_addr *daddr, u32 rnd);
810808

811809
#ifdef CONFIG_PROC_FS
812810
int ac6_proc_init(struct net *net);

‎net/ipv6/netfilter/nf_conntrack_reasm.c‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,24 @@ static inline u8 ip6_frag_ecn(const struct ipv6hdr *ipv6h)
144144
return 1 << (ipv6_get_dsfield(ipv6h) & INET_ECN_MASK);
145145
}
146146

147+
static unsigned int nf_hash_frag(__be32 id, const struct in6_addr *saddr,
148+
const struct in6_addr *daddr)
149+
{
150+
u32 c;
151+
152+
net_get_random_once(&nf_frags.rnd, sizeof(nf_frags.rnd));
153+
c = jhash_3words(ipv6_addr_hash(saddr), ipv6_addr_hash(daddr),
154+
(__force u32)id, nf_frags.rnd);
155+
return c & (INETFRAGS_HASHSZ - 1);
156+
}
157+
158+
147159
static unsigned int nf_hashfn(struct inet_frag_queue *q)
148160
{
149161
const struct frag_queue *nq;
150162

151163
nq = container_of(q, struct frag_queue, q);
152-
return inet6_hash_frag(nq->id, &nq->saddr, &nq->daddr, nf_frags.rnd);
164+
return nf_hash_frag(nq->id, &nq->saddr, &nq->daddr);
153165
}
154166

155167
static void nf_skb_free(struct sk_buff *skb)
@@ -185,7 +197,7 @@ static inline struct frag_queue *fq_find(struct net *net, __be32 id,
185197
arg.ecn = ecn;
186198

187199
read_lock_bh(&nf_frags.lock);
188-
hash = inet6_hash_frag(id, src, dst, nf_frags.rnd);
200+
hash = nf_hash_frag(id, src, dst);
189201

190202
q = inet_frag_find(&net->nf_frag.frags, &nf_frags, &arg, hash);
191203
local_bh_enable();

‎net/ipv6/reassembly.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,24 @@ static int ip6_frag_reasm(struct frag_queue *fq, struct sk_buff *prev,
8282
* callers should be careful not to use the hash value outside the ipfrag_lock
8383
* as doing so could race with ipfrag_hash_rnd being recalculated.
8484
*/
85-
unsigned int inet6_hash_frag(__be32 id, const struct in6_addr *saddr,
86-
const struct in6_addr *daddr, u32 rnd)
85+
static unsigned int inet6_hash_frag(__be32 id, const struct in6_addr *saddr,
86+
const struct in6_addr *daddr)
8787
{
8888
u32 c;
8989

90+
net_get_random_once(&ip6_frags.rnd, sizeof(ip6_frags.rnd));
9091
c = jhash_3words(ipv6_addr_hash(saddr), ipv6_addr_hash(daddr),
91-
(__force u32)id, rnd);
92+
(__force u32)id, ip6_frags.rnd);
9293

9394
return c & (INETFRAGS_HASHSZ - 1);
9495
}
95-
EXPORT_SYMBOL_GPL(inet6_hash_frag);
9696

9797
static unsigned int ip6_hashfn(struct inet_frag_queue *q)
9898
{
9999
struct frag_queue *fq;
100100

101101
fq = container_of(q, struct frag_queue, q);
102-
return inet6_hash_frag(fq->id, &fq->saddr, &fq->daddr, ip6_frags.rnd);
102+
return inet6_hash_frag(fq->id, &fq->saddr, &fq->daddr);
103103
}
104104

105105
bool ip6_frag_match(struct inet_frag_queue *q, void *a)
@@ -193,7 +193,7 @@ fq_find(struct net *net, __be32 id, const struct in6_addr *src,
193193
arg.ecn = ecn;
194194

195195
read_lock(&ip6_frags.lock);
196-
hash = inet6_hash_frag(id, src, dst, ip6_frags.rnd);
196+
hash = inet6_hash_frag(id, src, dst);
197197

198198
q = inet_frag_find(&net->ipv6.frags, &ip6_frags, &arg, hash);
199199
if (IS_ERR_OR_NULL(q)) {

0 commit comments

Comments
 (0)