Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3400443ybp; Sun, 6 Oct 2019 11:05:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqwf0jBGg6uDnBc8BPAW3J/plQQc+raK7oVV3myN4S2UcvVmnnMWBLwBOaD9Tkw8rR7TFiRe X-Received: by 2002:a05:6402:1a52:: with SMTP id bf18mr25674178edb.67.1570385148472; Sun, 06 Oct 2019 11:05:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570385148; cv=none; d=google.com; s=arc-20160816; b=JPcunuoW3C3MsfTWdn1XuxHk4xkqHd+na2NlkgDra3bme1m+GH5U3fLsEyEe6bRVVO X3rXuyVTWAxXCiim04VkADEfyDlEKDfzffe6WDyQQSdoHD5r26NSMMX1qhse7B8SWs0B wKYYW93C/2IkeI23Bi2isDctfsmjod2d8K4MW8PN+2YnLgm9TN+blI4vB0Dr2pTeOz58 W7GUh1X0EANov64c7mI5gkqpcRX/1giQHxs17pHJbNw0jgQUKwO6EVhpGVJTZboDmQKt TcYpz5XvdadradGIgkytr7JtE4t+g6VWhIEHBXOkJr/mf6KFWZjAmaFkjST4JnQ6/QfE CJ8A== 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=OFzvEk+w0NN4H8qzRkMFaRPWg+iKWyhCNVexOVoTv40=; b=TOBD15eAzn+ma+rihHWSsSUfvJ6OzjD/eva12TB+bxu5kQYfR1N5eW1LmF4UZMmZ3t 22jId9o1UFvZVhzRuuvptolpTPLqEDfeNWhQnvUJ3/eV1VQskWvVgNeHW8TsE+1s3/Dk 0T/B9Ld4ee8+WLmJwLr/VI1PagOESEcUvcZKBpvVK6L2ofEVdRg0lOioJ2Hix3K3sSt9 DENqGNRzZH+RTcbMx/qq86Swl81g9fenJpFxGSz/a1SEYRMRvnhFQCxEykUFaz94ChSu zVv9cxTZKu59sk62icTO4tFortR1O3pTNoAjU0OFZpwjtHgvEZoGAgg8B8gU4mFwYqDX IGKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iCOe0Zlm; 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 k6si7550919edb.235.2019.10.06.11.05.24; Sun, 06 Oct 2019 11:05:48 -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=iCOe0Zlm; 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 S1727822AbfJFRYK (ORCPT + 99 others); Sun, 6 Oct 2019 13:24:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:49026 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727798AbfJFRYJ (ORCPT ); Sun, 6 Oct 2019 13:24:09 -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 2EB5921479; Sun, 6 Oct 2019 17:24:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570382648; bh=F0AV2r5DMBlc+V5iWCahKWm3KkH3txRZ3r87QnIBRpA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iCOe0ZlmCuwltWSyfBr5jGfFHhB7UrwgPftk7XO5Gk/3QXQun6Gb6UHNYTVuztpPM JXWq3nMBtH2bUVbYn9tHBJv5mGLjNVWqeDdkgzuJEGoWMLCepJ5xqiZbomEFDtuG3D bwwihTVOOpSUV1XnuYf5aXpEt7NZ1hnvcbtquFxI= 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.9 35/47] net: ipv4: avoid mixed n_redirects and rate_tokens usage Date: Sun, 6 Oct 2019 19:21:22 +0200 Message-Id: <20191006172018.743249193@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191006172016.873463083@linuxfoundation.org> References: <20191006172016.873463083@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 @@ -903,16 +903,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);