Skip to content

Commit af07d24

Browse files
hgnkaber
authored andcommitted
netfilter: fix hardcoded size assumptions
get_random_bytes() is sometimes called with a hard coded size assumption of an integer. This could not be true for next centuries. This patch replace it with a compile time statement. Signed-off-by: Hagen Paul Pfeifer <[email protected]> Signed-off-by: Patrick McHardy <[email protected]>
1 parent e478075 commit af07d24

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

net/netfilter/nf_conntrack_core.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,8 @@ struct nf_conn *nf_conntrack_alloc(struct net *net,
472472
struct nf_conn *ct;
473473

474474
if (unlikely(!nf_conntrack_hash_rnd_initted)) {
475-
get_random_bytes(&nf_conntrack_hash_rnd, 4);
475+
get_random_bytes(&nf_conntrack_hash_rnd,
476+
sizeof(nf_conntrack_hash_rnd));
476477
nf_conntrack_hash_rnd_initted = 1;
477478
}
478479

@@ -1103,7 +1104,7 @@ int nf_conntrack_set_hashsize(const char *val, struct kernel_param *kp)
11031104

11041105
/* We have to rehahs for the new table anyway, so we also can
11051106
* use a newrandom seed */
1106-
get_random_bytes(&rnd, 4);
1107+
get_random_bytes(&rnd, sizeof(rnd));
11071108

11081109
/* Lookups in the old hash might happen in parallel, which means we
11091110
* might get false negatives during connection lookup. New connections

net/netfilter/nf_conntrack_expect.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ static unsigned int nf_ct_expect_dst_hash(const struct nf_conntrack_tuple *tuple
7272
unsigned int hash;
7373

7474
if (unlikely(!nf_ct_expect_hash_rnd_initted)) {
75-
get_random_bytes(&nf_ct_expect_hash_rnd, 4);
75+
get_random_bytes(&nf_ct_expect_hash_rnd,
76+
sizeof(nf_ct_expect_hash_rnd));
7677
nf_ct_expect_hash_rnd_initted = 1;
7778
}
7879

net/netfilter/xt_hashlimit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ dsthash_alloc_init(struct xt_hashlimit_htable *ht,
149149
/* initialize hash with random val at the time we allocate
150150
* the first hashtable entry */
151151
if (!ht->rnd_initialized) {
152-
get_random_bytes(&ht->rnd, 4);
152+
get_random_bytes(&ht->rnd, sizeof(ht->rnd));
153153
ht->rnd_initialized = 1;
154154
}
155155

0 commit comments

Comments
 (0)