Skip to content

Commit a00df2c

Browse files
edumazetdavem330
authored andcommitted
ipv6: make exception cache less predictible
Even after commit 4785305 ("ipv6: use siphash in rt6_exception_hash()"), an attacker can still use brute force to learn some secrets from a victim linux host. One way to defeat these attacks is to make the max depth of the hash table bucket a random value. Before this patch, each bucket of the hash table used to store exceptions could contain 6 items under attack. After the patch, each bucket would contains a random number of items, between 6 and 10. The attacker can no longer infer secrets. This is slightly increasing memory size used by the hash table, we do not expect this to be a problem. Following patch is dealing with the same issue in IPv4. Fixes: 35732d0 ("ipv6: introduce a hash table to store dst cache") Signed-off-by: Eric Dumazet <edumazet@google.com> Reported-by: Keyu Man <kman001@ucr.edu> Cc: Wei Wang <weiwan@google.com> Cc: Martin KaFai Lau <kafai@fb.com> Reviewed-by: David Ahern <dsahern@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9dfa859 commit a00df2c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

net/ipv6/route.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,7 @@ static int rt6_insert_exception(struct rt6_info *nrt,
16571657
struct in6_addr *src_key = NULL;
16581658
struct rt6_exception *rt6_ex;
16591659
struct fib6_nh *nh = res->nh;
1660+
int max_depth;
16601661
int err = 0;
16611662

16621663
spin_lock_bh(&rt6_exception_lock);
@@ -1711,7 +1712,9 @@ static int rt6_insert_exception(struct rt6_info *nrt,
17111712
bucket->depth++;
17121713
net->ipv6.rt6_stats->fib_rt_cache++;
17131714

1714-
if (bucket->depth > FIB6_MAX_DEPTH)
1715+
/* Randomize max depth to avoid some side channels attacks. */
1716+
max_depth = FIB6_MAX_DEPTH + prandom_u32_max(FIB6_MAX_DEPTH);
1717+
while (bucket->depth > max_depth)
17151718
rt6_exception_remove_oldest(bucket);
17161719

17171720
out:

0 commit comments

Comments
 (0)