Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp559194imp; Thu, 21 Feb 2019 06:51:17 -0800 (PST) X-Google-Smtp-Source: AHgI3IblyGyhmbNtIkQ4j+5zoIDVy1+JX/jlQLTPJwLDwItgPDKw2BQmMYbWNFiKxw0IXDf07T9G X-Received: by 2002:a65:6658:: with SMTP id z24mr38836244pgv.189.1550760677838; Thu, 21 Feb 2019 06:51:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550760677; cv=none; d=google.com; s=arc-20160816; b=GcODgtYFKB7z1xPdY5me80MYsuxj+UddUFpA53m9twbiKk9uKB1r+JJMCBNxtDGNz2 2mWJdEHAIxsbeGD0W3/O+XcM78ajQ3RGr22djITZqxolpklUxkLdkXMDNhFEwSHcH5Wk XIQ/K7Gk+ITndMbifyhXbnnSZKHjsu3ldE/25/iEug8U7ztEKJO9vzGHr/kB450HEr2f GwQAObTAmME6hhxBGjdWvPWXuRgYoDLIcEIFYOF2vMmJYYAQUkCZV9qwkn3up7QgWoKd Sn9zuR1x27oVCvLJzieBVRGhwfjHiQV5+fMakIl34TCGiELlvXN8B2qEMg2kLKDMMolB Ncww== 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=qt9774/H82/2SdUa3EikLWSLNJ+s6Qxa/NWOINa9kWI=; b=KFD78+Bc6HTm1blwA5NCTnawGQXdh+y8VnJZjztP+nU0E81mjrTo+2BkalUbG59/Ry UHrIyu54ICNo/DVCWQzwZ1r1GJ/MM6l6Xh39GKtHa44pWH0o0lDuvep5yF+7nyKEds7u c4NteDwTFMeTmBWa6/Dovp842rDhBKfwgdv77DCRYvQvxrUHfpbALiLHY3KhVFbzN1ur 5duJcYXQmvLDvMVbu7J+1aniVkgVIBcjfMQLFj9He06wtnw3EwGzHZRZWCbyBXZB7ekk Hld2vUGhzc0AfimfTtpwEVF8Hd2BLdXDyVAz+Zj/gh7MGmSxPl8cNhbh24R1y1oHxKIX LmgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=aDCrzloR; 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 s4si17312945pfb.190.2019.02.21.06.51.02; Thu, 21 Feb 2019 06:51:17 -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=aDCrzloR; 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 S1728839AbfBUOjO (ORCPT + 99 others); Thu, 21 Feb 2019 09:39:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:33024 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728823AbfBUOjM (ORCPT ); Thu, 21 Feb 2019 09:39:12 -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 D84642084D; Thu, 21 Feb 2019 14:39:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550759951; bh=EqN6E9PQo+6dSHq/kIYUe61z61UPtShXJPrKztkMYoY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aDCrzloRSrhwIchHcLv0UFh50OniekPlKQtnUW0DTLL5DuoLBLksYPr5vZCqjHCTE JEBqMKJeI7k79biKv6lVFxTLdhVoyG5dwDlUGmIxDfE7798fFCwuPlkIL6REPmrD4I vx77VAIAHNEyl8xjF+qqjMO11eEaAmvb8shHQMVo= 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.9 16/20] net: ipv4: use a dedicated counter for icmp_v4 redirect packets Date: Thu, 21 Feb 2019 15:35:54 +0100 Message-Id: <20190221125243.943518850@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190221125242.153179182@linuxfoundation.org> References: <20190221125242.153179182@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.9-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 @@ -882,13 +882,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; } @@ -905,6 +907,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)