From: Eric Dumazet <hidden> Date: 2021-08-29 22:16:22
From: Eric Dumazet <edumazet@google.com>
This second round of patches is addressing Keyu Man recommendations
to make linux hosts more robust against a class of brute force attacks.
Eric Dumazet (2):
ipv6: make exception cache less predictible
ipv4: make exception cache less predictible
net/ipv4/route.c | 44 +++++++++++++++++++++++++++++---------------
net/ipv6/route.c | 5 ++++-
2 files changed, 33 insertions(+), 16 deletions(-)
--
2.33.0.259.gc128427fd7-goog
From: Eric Dumazet <hidden> Date: 2021-08-29 22:16:23
From: Eric Dumazet <edumazet@google.com>
Even after commit 4785305c05b2 ("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: 35732d01fe31 ("ipv6: introduce a hash table to store dst cache")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Keyu Man <redacted>
Cc: Wei Wang <redacted>
Cc: Martin KaFai Lau <redacted>
---
net/ipv6/route.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
@@ -1657,6 +1657,7 @@ static int rt6_insert_exception(struct rt6_info *nrt,structin6_addr*src_key=NULL;structrt6_exception*rt6_ex;structfib6_nh*nh=res->nh;+intmax_depth;interr=0;spin_lock_bh(&rt6_exception_lock);
@@ -1711,7 +1712,9 @@ static int rt6_insert_exception(struct rt6_info *nrt,bucket->depth++;net->ipv6.rt6_stats->fib_rt_cache++;-if(bucket->depth>FIB6_MAX_DEPTH)+/* Randomize max depth to avoid some side channels attacks. */+max_depth=FIB6_MAX_DEPTH+prandom_u32_max(FIB6_MAX_DEPTH);+while(bucket->depth>max_depth)rt6_exception_remove_oldest(bucket);out:
From: Eric Dumazet <hidden> Date: 2021-08-29 22:16:25
From: Eric Dumazet <edumazet@google.com>
Even after commit 6457378fe796 ("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: 4895c771c7f0 ("ipv4: Add FIB nexthop exceptions.")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Keyu Man <redacted>
Cc: Willy Tarreau <w@1wt.eu>
Signed-off-by: David S. Miller <davem@davemloft.net>
---
net/ipv4/route.c | 44 +++++++++++++++++++++++++++++---------------
1 file changed, 29 insertions(+), 15 deletions(-)
@@ -676,16 +683,21 @@ static void update_or_create_fnhe(struct fib_nh_common *nhc, __be32 daddr,if(rt)fill_route_from_fnhe(rt,fnhe);}else{-if(depth>FNHE_RECLAIM_DEPTH)-fnhe=fnhe_oldest(hash);-else{-fnhe=kzalloc(sizeof(*fnhe),GFP_ATOMIC);-if(!fnhe)-gotoout_unlock;+/* Randomize max depth to avoid some side channels attacks. */+intmax_depth=FNHE_RECLAIM_DEPTH++prandom_u32_max(FNHE_RECLAIM_DEPTH);-fnhe->fnhe_next=hash->chain;-rcu_assign_pointer(hash->chain,fnhe);+while(depth>max_depth){+fnhe_remove_oldest(hash);+depth--;}++fnhe=kzalloc(sizeof(*fnhe),GFP_ATOMIC);+if(!fnhe)+gotoout_unlock;++fnhe->fnhe_next=hash->chain;+fnhe->fnhe_genid=genid;fnhe->fnhe_daddr=daddr;fnhe->fnhe_gw=gw;
@@ -693,6 +705,8 @@ static void update_or_create_fnhe(struct fib_nh_common *nhc, __be32 daddr,fnhe->fnhe_mtu_locked=lock;fnhe->fnhe_expires=max(1UL,expires);+rcu_assign_pointer(hash->chain,fnhe);+/* Exception created; mark the cached routes for the nexthop*stale,soanyonecachingitrechecksifthisexception*appliestothem.
From: David Ahern <hidden> Date: 2021-08-30 00:39:26
On 8/29/21 3:16 PM, Eric Dumazet wrote:
From: Eric Dumazet <edumazet@google.com>
Even after commit 4785305c05b2 ("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: 35732d01fe31 ("ipv6: introduce a hash table to store dst cache")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Keyu Man <redacted>
Cc: Wei Wang <redacted>
Cc: Martin KaFai Lau <redacted>
---
net/ipv6/route.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
From: David Ahern <hidden> Date: 2021-08-30 00:40:17
On 8/29/21 3:16 PM, Eric Dumazet wrote:
From: Eric Dumazet <edumazet@google.com>
Even after commit 6457378fe796 ("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: 4895c771c7f0 ("ipv4: Add FIB nexthop exceptions.")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Keyu Man <redacted>
Cc: Willy Tarreau <w@1wt.eu>
Signed-off-by: David S. Miller <davem@davemloft.net>
---
net/ipv4/route.c | 44 +++++++++++++++++++++++++++++---------------
1 file changed, 29 insertions(+), 15 deletions(-)
Reviewed-by: David Ahern <dsahern@kernel.org>
Tested-by: David Ahern <dsahern@kernel.org>
On Sun, Aug 29, 2021 at 5:39 PM David Ahern [off-list ref] wrote:
On 8/29/21 3:16 PM, Eric Dumazet wrote:
quoted
From: Eric Dumazet <edumazet@google.com>
Even after commit 4785305c05b2 ("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: 35732d01fe31 ("ipv6: introduce a hash table to store dst cache")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Keyu Man <redacted>
Cc: Wei Wang <redacted>
Cc: Martin KaFai Lau <redacted>
---
net/ipv6/route.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
Thanks Eric and others for fixing the bug!
Keyu Man
On 8/29/2021 3:16 PM, Eric Dumazet wrote:
From: Eric Dumazet <edumazet@google.com>
This second round of patches is addressing Keyu Man recommendations
to make linux hosts more robust against a class of brute force attacks.
Eric Dumazet (2):
ipv6: make exception cache less predictible
ipv4: make exception cache less predictible
net/ipv4/route.c | 44 +++++++++++++++++++++++++++++---------------
net/ipv6/route.c | 5 ++++-
2 files changed, 33 insertions(+), 16 deletions(-)