Skip to content

Commit b406472

Browse files
Paolo Abenidavem330
authored andcommitted
net: ipv4: avoid mixed n_redirects and rate_tokens usage
Since commit c09551c ("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 <[email protected]> Fixes: 1da177e ("Linux-2.6.12-rc2") Fixes: c09551c ("net: ipv4: use a dedicated counter for icmp_v4 redirect packets") Signed-off-by: Paolo Abeni <[email protected]> Acked-by: Lorenzo Bianconi <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a54cdee commit b406472

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

net/ipv4/route.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -916,16 +916,15 @@ void ip_rt_send_redirect(struct sk_buff *skb)
916916
if (peer->rate_tokens == 0 ||
917917
time_after(jiffies,
918918
(peer->rate_last +
919-
(ip_rt_redirect_load << peer->rate_tokens)))) {
919+
(ip_rt_redirect_load << peer->n_redirects)))) {
920920
__be32 gw = rt_nexthop(rt, ip_hdr(skb)->daddr);
921921

922922
icmp_send(skb, ICMP_REDIRECT, ICMP_REDIR_HOST, gw);
923923
peer->rate_last = jiffies;
924-
++peer->rate_tokens;
925924
++peer->n_redirects;
926925
#ifdef CONFIG_IP_ROUTE_VERBOSE
927926
if (log_martians &&
928-
peer->rate_tokens == ip_rt_redirect_number)
927+
peer->n_redirects == ip_rt_redirect_number)
929928
net_warn_ratelimited("host %pI4/if%d ignores redirects for %pI4 to %pI4\n",
930929
&ip_hdr(skb)->saddr, inet_iif(skb),
931930
&ip_hdr(skb)->daddr, &gw);

0 commit comments

Comments
 (0)