Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3368609ybp; Sun, 6 Oct 2019 10:24:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqxzfIaF+QOpLw37WUdXyCkOzAjAKw+h/8MiW5BxN8ahHxW5RoSnCchz8tcHjxnGRP0Attts X-Received: by 2002:a50:cf8b:: with SMTP id h11mr24325372edk.236.1570382671313; Sun, 06 Oct 2019 10:24:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570382671; cv=none; d=google.com; s=arc-20160816; b=Q/vncQtHsJofvOok7wvz8bO0yq2+ZT9ICORTnusuPK2K4SP9oNRm7r8Ymz/YIanjqG hri/0+i3iyAo03mgUonaCFeH+TA8JfU29xX1ebU06vYXapzhuaqYdngbJ5ivybLVEqB1 pkRmVCDElh1PvzVZb6t9vFvsiB8WtyEc8hOgu7EwIynAVIxsO6sDWlPEhEAIxAEvwXgJ RtQ6Zn11EFM4MiR65GQ4TWFsMY5Pi9w8DmEBbeAr26Ey3k+e8mTiBfN/Bxh4SUWXXpXr NrGmSpuIzNBc8CZtppN+iSz4arPoPswDqSKkdwQDv1sGYCseXjkbEDfjz8AFuPHcB7u6 7g1Q== 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=3cf9qQTLa+mdxLZ1OvGJrAmoIJfwiGYtgmcE0oZ7ajw=; b=wkbMXInA8eLDUCFp9+/sa+wka/99iYu6pnqx02AKTi6v85uj1MB3Yij0JuVbNVrUAR A9lPaSQvoOV/Mj4gpXyXsFH0AR/wn6Nx0t8RxbldBbDQXHPy8KSkI9wxXoq5eNzMNCYx PbrAtYEPXCYUizBSqI9EmG4tJbc57Is9ItxDsfZLi+6JHkC+HZpJBi+ZAwuOqguxZ4lW OT1rXt5xWQwxq3wiNlKit79SSJ1KUqm3iEU2h32mF/P5xUpkHMDiN1QSx1QGWqP/43pN eva6bGasdULdrksQ0DtyLHLZkFdcL4O7k8hTfqoF50C20YZAU7WIyTeKqwdWdf3wwVzs Y3wg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wYIjbh37; 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 w10si5733200eju.156.2019.10.06.10.24.07; Sun, 06 Oct 2019 10:24:31 -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=wYIjbh37; 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 S1727247AbfJFRUd (ORCPT + 99 others); Sun, 6 Oct 2019 13:20:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:45498 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727219AbfJFRU2 (ORCPT ); Sun, 6 Oct 2019 13:20:28 -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 B4D9520867; Sun, 6 Oct 2019 17:20:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570382428; bh=btIa0ZHhdskAhD1AHsqYrNAnTzJcJwLkUyEocZemCtU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wYIjbh37FXOsZuVO7GyBF4VE0tXqpHOo53hbbe227spdD3l/GKoAbt3ccq4M0ef4F 76Q2hFjKYM1aHCRM8SD5R0+Sp3K3vBoJv1zAZuaSGjVxnqimw7uTNt4MoCrk7zY1aD 98wtNr0ttEHm949ms2/02eYbL/yTeWg0tbcFj51w= 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.4 27/36] net: ipv4: avoid mixed n_redirects and rate_tokens usage Date: Sun, 6 Oct 2019 19:19:09 +0200 Message-Id: <20191006171056.823426812@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006171038.266461022@linuxfoundation.org> References: <20191006171038.266461022@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 @@ -897,16 +897,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);