Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3378038ybp; Sun, 6 Oct 2019 10:36:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqx0fMydeoREQFCraC0gALUxM28MIXgugqYJUqfcKybj5meI2kVCvXRpIJ1+EWE49M09js3P X-Received: by 2002:a17:906:5644:: with SMTP id v4mr20404201ejr.52.1570383402426; Sun, 06 Oct 2019 10:36:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570383402; cv=none; d=google.com; s=arc-20160816; b=qVCBybFHE8AuguJNKugYjgqf81LlKXW3eV4HFeer2cn5lpdtjIeMJLRffJDq/K9UGI 0EMb5CwTf6bwHb9wGmQP3X60tf5N02E/tRytxXFHPcJzK0f+I+Q8Dal7GDV5CgQ7DZqV E0+65r3Vus+PH8QtXaKj0rZjcbmhRXynQxmh1jM2+td9+cJBOFkFewSq864rsvgvhzP8 uYTE/x+wg/AZ5EHJYGX7wXdQSQiEFfX3FOIwwapkF+8Nc+VfeXBVIm41iAoRgTpVyVyT BwT00GYQfzQ/EljQ9GtjebmeO1YBlmeqN8LxOmuFKLvqRNIQP4X8bxA9QYB/jSJ8RpVo CMTg== 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=YSeDEQ8KKeX5LogkPyb+EuiMpqCXNKD+nNY3ztVRhhs=; b=wK7MVijP7QqmwS3WfZHELAEe2XjmZW2Plhs1AXsma/JcufyFN2fnR1iDLyQjsCYOvU IKZKNOGFVsonGc+fAeDCbUs9OrhU4olPNpXKnR6acN5oR2bixxsfQ0bSwAqMXDl68lat dwJPxGt3eCvE/AvQjBukqK0t88AQccIGjTlekjRIc11bTLvjW8WyY1l4mwPbHCfxCC/h ciXO9DxB3zJqoCrbJ0aGEJpVWxQ/wi7h/5M/Pj8etAACFv20r42ThkAIUoLTbCwJsx2g qdyiPNVhyZUhPaR0ex5YiyqsiPfXFoGQEZq0oNhO+Kn595wRbgKW+uZ6v16W53jprO+h tWIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oXjpLcpt; 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 n19si5787043ejk.264.2019.10.06.10.36.18; Sun, 06 Oct 2019 10:36:42 -0700 (PDT) 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=oXjpLcpt; 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 S1727634AbfJFRci (ORCPT + 99 others); Sun, 6 Oct 2019 13:32:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:59106 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729587AbfJFRch (ORCPT ); Sun, 6 Oct 2019 13:32:37 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 759A421479; Sun, 6 Oct 2019 17:32:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570383157; bh=gdHNW3mAEvu4BnX73bfXuOIPRkCfTjZItelUJaGKSVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oXjpLcptemXeEC9SZPFM2O6SbAP9+bnzVQgKpjYjJCybfper5l1wMiy/EOz3vJQ3c CWgsS/WR23KjMKGZLxg9FcXLMb+hc8B09+VaoDOpzaDzBzHKgwtjeEq2p2BF3yAkHO Eedl5AoTZG6pPGGbrpQ6ALaZoEF4AmKXbiHB0ONk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiumei Mu , Paolo Abeni , Lorenzo Bianconi , "David S. Miller" Subject: [PATCH 4.19 085/106] net: ipv4: avoid mixed n_redirects and rate_tokens usage Date: Sun, 6 Oct 2019 19:21:31 +0200 Message-Id: <20191006171158.470390199@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171124.641144086@linuxfoundation.org> References: <20191006171124.641144086@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Paolo Abeni [ Upstream commit b406472b5ad79ede8d10077f0c8f05505ace8b6d ] 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 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 Acked-by: Lorenzo Bianconi Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/ipv4/route.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -908,16 +908,15 @@ void ip_rt_send_redirect(struct sk_buff 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);