netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: ipv4: avoid mixed n_redirects and rate_tokens usage
@ 2019-10-04 13:11 Paolo Abeni
  2019-10-04 15:27 ` Lorenzo Bianconi
  2019-10-05  0:28 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Paolo Abeni @ 2019-10-04 13:11 UTC (permalink / raw)
  To: netdev; +Cc: David S. Miller, lbianconi, xmu

Since commit c09551c6ff7f ("net: ipv4: use a dedicated counter
for icmp_v4 redirect packets") we use 'n_redirects' to account
for redirect packets, but we still use 'rate_tokens' to compute
the redirect packets exponential backoff.

If the device sent to the relevant peer any ICMP error packet
after sending a redirect, it will also update 'rate_token' according
to the leaking bucket schema; typically 'rate_token' will raise
above BITS_PER_LONG and the redirect packets backoff algorithm
will produce undefined behavior.

Fix the issue using 'n_redirects' to compute the exponential backoff
in ip_rt_send_redirect().

Note that we still clear rate_tokens after a redirect silence period,
to avoid changing an established behaviour.

The root cause predates git history; before the mentioned commit in
the critical scenario, the kernel stopped sending redirects, after
the mentioned commit the behavior more randomic.

Reported-by: Xiumei Mu <xmu@redhat.com>
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Fixes: c09551c6ff7f ("net: ipv4: use a dedicated counter for icmp_v4 redirect packets")
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
---
 net/ipv4/route.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 7dcce724c78b..14654876127e 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -916,16 +916,15 @@ void ip_rt_send_redirect(struct sk_buff *skb)
 	if (peer->rate_tokens == 0 ||
 	    time_after(jiffies,
 		       (peer->rate_last +
-			(ip_rt_redirect_load << peer->rate_tokens)))) {
+			(ip_rt_redirect_load << peer->n_redirects)))) {
 		__be32 gw = rt_nexthop(rt, ip_hdr(skb)->daddr);
 
 		icmp_send(skb, ICMP_REDIRECT, ICMP_REDIR_HOST, gw);
 		peer->rate_last = jiffies;
-		++peer->rate_tokens;
 		++peer->n_redirects;
 #ifdef CONFIG_IP_ROUTE_VERBOSE
 		if (log_martians &&
-		    peer->rate_tokens == ip_rt_redirect_number)
+		    peer->n_redirects == ip_rt_redirect_number)
 			net_warn_ratelimited("host %pI4/if%d ignores redirects for %pI4 to %pI4\n",
 					     &ip_hdr(skb)->saddr, inet_iif(skb),
 					     &ip_hdr(skb)->daddr, &gw);
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: ipv4: avoid mixed n_redirects and rate_tokens usage
  2019-10-04 13:11 [PATCH net] net: ipv4: avoid mixed n_redirects and rate_tokens usage Paolo Abeni
@ 2019-10-04 15:27 ` Lorenzo Bianconi
  2019-10-05  0:28 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Lorenzo Bianconi @ 2019-10-04 15:27 UTC (permalink / raw)
  To: Paolo Abeni; +Cc: netdev, David S. Miller, lbianconi, xmu

[-- Attachment #1: Type: text/plain, Size: 2360 bytes --]

> Since commit c09551c6ff7f ("net: ipv4: use a dedicated counter
> for icmp_v4 redirect packets") we use 'n_redirects' to account
> for redirect packets, but we still use 'rate_tokens' to compute
> the redirect packets exponential backoff.
> 
> If the device sent to the relevant peer any ICMP error packet
> after sending a redirect, it will also update 'rate_token' according
> to the leaking bucket schema; typically 'rate_token' will raise
> above BITS_PER_LONG and the redirect packets backoff algorithm
> will produce undefined behavior.
> 
> Fix the issue using 'n_redirects' to compute the exponential backoff
> in ip_rt_send_redirect().
> 
> Note that we still clear rate_tokens after a redirect silence period,
> to avoid changing an established behaviour.
> 
> The root cause predates git history; before the mentioned commit in
> the critical scenario, the kernel stopped sending redirects, after
> the mentioned commit the behavior more randomic.
> 
> Reported-by: Xiumei Mu <xmu@redhat.com>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Fixes: c09551c6ff7f ("net: ipv4: use a dedicated counter for icmp_v4 redirect packets")
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>

Acked-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>

> ---
>  net/ipv4/route.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/net/ipv4/route.c b/net/ipv4/route.c
> index 7dcce724c78b..14654876127e 100644
> --- a/net/ipv4/route.c
> +++ b/net/ipv4/route.c
> @@ -916,16 +916,15 @@ void ip_rt_send_redirect(struct sk_buff *skb)
>  	if (peer->rate_tokens == 0 ||
>  	    time_after(jiffies,
>  		       (peer->rate_last +
> -			(ip_rt_redirect_load << peer->rate_tokens)))) {
> +			(ip_rt_redirect_load << peer->n_redirects)))) {
>  		__be32 gw = rt_nexthop(rt, ip_hdr(skb)->daddr);
>  
>  		icmp_send(skb, ICMP_REDIRECT, ICMP_REDIR_HOST, gw);
>  		peer->rate_last = jiffies;
> -		++peer->rate_tokens;
>  		++peer->n_redirects;
>  #ifdef CONFIG_IP_ROUTE_VERBOSE
>  		if (log_martians &&
> -		    peer->rate_tokens == ip_rt_redirect_number)
> +		    peer->n_redirects == ip_rt_redirect_number)
>  			net_warn_ratelimited("host %pI4/if%d ignores redirects for %pI4 to %pI4\n",
>  					     &ip_hdr(skb)->saddr, inet_iif(skb),
>  					     &ip_hdr(skb)->daddr, &gw);
> -- 
> 2.21.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: ipv4: avoid mixed n_redirects and rate_tokens usage
  2019-10-04 13:11 [PATCH net] net: ipv4: avoid mixed n_redirects and rate_tokens usage Paolo Abeni
  2019-10-04 15:27 ` Lorenzo Bianconi
@ 2019-10-05  0:28 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2019-10-05  0:28 UTC (permalink / raw)
  To: pabeni; +Cc: netdev, lbianconi, xmu

From: Paolo Abeni <pabeni@redhat.com>
Date: Fri,  4 Oct 2019 15:11:17 +0200

> Since commit c09551c6ff7f ("net: ipv4: use a dedicated counter
> for icmp_v4 redirect packets") we use 'n_redirects' to account
> for redirect packets, but we still use 'rate_tokens' to compute
> the redirect packets exponential backoff.
> 
> If the device sent to the relevant peer any ICMP error packet
> after sending a redirect, it will also update 'rate_token' according
> to the leaking bucket schema; typically 'rate_token' will raise
> above BITS_PER_LONG and the redirect packets backoff algorithm
> will produce undefined behavior.
> 
> Fix the issue using 'n_redirects' to compute the exponential backoff
> in ip_rt_send_redirect().
> 
> Note that we still clear rate_tokens after a redirect silence period,
> to avoid changing an established behaviour.
> 
> The root cause predates git history; before the mentioned commit in
> the critical scenario, the kernel stopped sending redirects, after
> the mentioned commit the behavior more randomic.
> 
> Reported-by: Xiumei Mu <xmu@redhat.com>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> Fixes: c09551c6ff7f ("net: ipv4: use a dedicated counter for icmp_v4 redirect packets")
> Signed-off-by: Paolo Abeni <pabeni@redhat.com>

Applied and queued up for -stable.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-10-05  0:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-04 13:11 [PATCH net] net: ipv4: avoid mixed n_redirects and rate_tokens usage Paolo Abeni
2019-10-04 15:27 ` Lorenzo Bianconi
2019-10-05  0:28 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).