• Eric Dumazet's avatar
    ipv4: make exception cache less predictible · 67d6d681
    Eric Dumazet authored
    Even after commit 6457378f ("ipv4: use siphash instead of Jenkins in
    fnhe_hashfun()"), 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,
    by 50% in average, we do not expect this to be a problem.
    
    This patch is more complex than the prior one (IPv6 equivalent),
    because IPv4 was reusing the oldest entry.
    Since we need to be able to evict more than one entry per
    update_or_create_fnhe() call, I had to replace
    fnhe_oldest() with fnhe_remove_oldest().
    
    Also note that we will queue extra kfree_rcu() calls under stress,
    which hopefully wont be a too big issue.
    
    Fixes: 4895c771 ("ipv4: Add FIB nexthop exceptions.")
    Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
    Reported-by: default avatarKeyu Man <kman001@ucr.edu>
    Cc: Willy Tarreau <w@1wt.eu>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    Reviewed-by: default avatarDavid Ahern <dsahern@kernel.org>
    Tested-by: default avatarDavid Ahern <dsahern@kernel.org>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    67d6d681
route.c 93.5 KB