Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp559948imp; Thu, 21 Feb 2019 06:52:09 -0800 (PST) X-Google-Smtp-Source: AHgI3IYQYMoPjJ3v3QsteHCor0VXVC/DFrhEZ6/A6qrt9YYB1EeYGVnpomSNejorzNBi/Uf2X91B X-Received: by 2002:a62:d10b:: with SMTP id z11mr40558248pfg.84.1550760729918; Thu, 21 Feb 2019 06:52:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550760729; cv=none; d=google.com; s=arc-20160816; b=rW2rynwRUHfEluxDTnBTIRAA9NLiJabdmALmFSGpQyH5KzTlqg1MIoAIgXxdue+8TZ 6jlpQVi2N0t1Lc6JuPb6qovYhc7fgC0/knyOVaBI2U5QeCBPrWYR5usIqv40w3s9sanS oIya1iUawalp854lGwDTx60baNmxIO52lzDUCe6qkidig6mK3/iCVnLXzEx+8Iie0d8U cLY3hwNqBeFuZ+4WJuNJA6Bjnmb6mCEI8lPDg6p/vkTy+wBkubqMfIHXU794jwsdZKUS POCME21cvhkMTGcegIKU1MuS0o5JMF8cdedq++K93JhKANHTUf3AUgUwwQ+XlZr25EfN vYTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uG5i5OCZZUtCGsYqwGiPpbh8mHkR4FwsnHao6Kitk+M=; b=kqGx4GTktp9aQb/ZULX2aik4QYOBrSpSydxnFQpfFthhZlRGPLSNxXoIpgc7wim0tp go1yGTPEsTDhciUk+Xt6zYZvrCQhEjZQg2fMEE+0zFjBIfKkg+9vLFHfObYy1KN1ux/S ZTyfh7yR6feh+k7sgNoaO3lTOemCkRhkL9eucbcc4RNSic5ooyXyiaeTqz4UNmU5mXQU vokxKaF4m6fAN0LjTCLvAVGdSKkEJkIMjbiZQ0e/wJaZL+IRuuFWrwd4ixR3zWQjLnDt MhLrkCJEjsUQm4DS7JY3yLQoyKAYjJ3zGCaUXlWNOz077y1UNqUkA7yqxmiOqI43NrV0 8uZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DIOuloeF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h94si6641377plb.51.2019.02.21.06.51.54; Thu, 21 Feb 2019 06:52:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DIOuloeF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728424AbfBUOhd (ORCPT + 99 others); Thu, 21 Feb 2019 09:37:33 -0500 Received: from mail.kernel.org ([198.145.29.99]:58788 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728356AbfBUOhc (ORCPT ); Thu, 21 Feb 2019 09:37:32 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AFF492084D; Thu, 21 Feb 2019 14:37:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550759851; bh=qA9z0f0GzJgDWA9kGJPh3oNiW9V5QPeLt8ebDY15Gr4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DIOuloeF2rlXQG9IRKVMJb+WLBSgztan9leZx1/PiYFV/IJNSQqGGNb99Le3lTSBD XWZyU+JlTtTTuahSFyLg/g71zEIBjwDDAd+GI/oa3PVBDYW22zWPnR8+FlDUnvufeg pBTqumAzrW6S1R/c1asQHMmfIgAzvEAJoNlVPwSU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lorenzo Bianconi , "David S. Miller" Subject: [PATCH 4.4 12/20] net: ipv4: use a dedicated counter for icmp_v4 redirect packets Date: Thu, 21 Feb 2019 15:35:42 +0100 Message-Id: <20190221141947.124105601@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190221141946.772985220@linuxfoundation.org> References: <20190221141946.772985220@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lorenzo Bianconi [ Upstream commit c09551c6ff7fe16a79a42133bcecba5fc2fc3291 ] According to the algorithm described in the comment block at the beginning of ip_rt_send_redirect, the host should try to send 'ip_rt_redirect_number' ICMP redirect packets with an exponential backoff and then stop sending them at all assuming that the destination ignores redirects. If the device has previously sent some ICMP error packets that are rate-limited (e.g TTL expired) and continues to receive traffic, the redirect packets will never be transmitted. This happens since peer->rate_tokens will be typically greater than 'ip_rt_redirect_number' and so it will never be reset even if the redirect silence timeout (ip_rt_redirect_silence) has elapsed without receiving any packet requiring redirects. Fix it by using a dedicated counter for the number of ICMP redirect packets that has been sent by the host I have not been able to identify a given commit that introduced the issue since ip_rt_send_redirect implements the same rate-limiting algorithm from commit 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Lorenzo Bianconi Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/net/inetpeer.h | 1 + net/ipv4/inetpeer.c | 1 + net/ipv4/route.c | 7 +++++-- 3 files changed, 7 insertions(+), 2 deletions(-) --- a/include/net/inetpeer.h +++ b/include/net/inetpeer.h @@ -40,6 +40,7 @@ struct inet_peer { u32 metrics[RTAX_MAX]; u32 rate_tokens; /* rate limiting for ICMP */ + u32 n_redirects; unsigned long rate_last; union { struct list_head gc_list; --- a/net/ipv4/inetpeer.c +++ b/net/ipv4/inetpeer.c @@ -448,6 +448,7 @@ relookup: atomic_set(&p->rid, 0); p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW; p->rate_tokens = 0; + p->n_redirects = 0; /* 60*HZ is arbitrary, but chosen enough high so that the first * calculation of tokens is at its maximum. */ --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -876,13 +876,15 @@ void ip_rt_send_redirect(struct sk_buff /* No redirected packets during ip_rt_redirect_silence; * reset the algorithm. */ - if (time_after(jiffies, peer->rate_last + ip_rt_redirect_silence)) + if (time_after(jiffies, peer->rate_last + ip_rt_redirect_silence)) { peer->rate_tokens = 0; + peer->n_redirects = 0; + } /* Too many ignored redirects; do not send anything * set dst.rate_last to the last seen redirected packet. */ - if (peer->rate_tokens >= ip_rt_redirect_number) { + if (peer->n_redirects >= ip_rt_redirect_number) { peer->rate_last = jiffies; goto out_put_peer; } @@ -899,6 +901,7 @@ void ip_rt_send_redirect(struct sk_buff 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)