From patchwork Wed Oct 19 18:05:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Flavio Leitner X-Patchwork-Id: 120678 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 454A3B71BB for ; Thu, 20 Oct 2011 05:05:47 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751292Ab1JSSFm (ORCPT ); Wed, 19 Oct 2011 14:05:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41576 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750855Ab1JSSFl (ORCPT ); Wed, 19 Oct 2011 14:05:41 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p9JI5e4G007066 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 19 Oct 2011 14:05:40 -0400 Received: from asterix.rh (ovpn-113-50.phx2.redhat.com [10.3.113.50]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p9JI5cHc025887; Wed, 19 Oct 2011 14:05:39 -0400 Date: Wed, 19 Oct 2011 16:05:37 -0200 From: Flavio Leitner To: David Miller Cc: netdev@vger.kernel.org Subject: Re: [PATCH] route: fix ICMP redirect validation Message-ID: <20111019160537.4aeedef8@asterix.rh> In-Reply-To: <20111017.194344.510280595317217573.davem@davemloft.net> References: <1317824404-9513-1-git-send-email-fbl@redhat.com> <20111017.194344.510280595317217573.davem@davemloft.net> Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Mon, 17 Oct 2011 19:43:44 -0400 (EDT) David Miller wrote: > From: Flavio Leitner > Date: Wed, 5 Oct 2011 11:20:04 -0300 > > > The commit f39925dbde7788cfb96419c0f092b086aa325c0f > > (ipv4: Cache learned redirect information in inetpeer.) > > removed some ICMP packet validations which are required by > > RFC 1122, section 3.2.2.2: > > ... > > A Redirect message SHOULD be silently discarded if the new > > gateway address it specifies is not on the same connected > > (sub-) net through which the Redirect arrived [INTRO:2, > > Appendix A], or if the source of the Redirect is not the > > current first-hop gateway for the specified destination (see > > Section 3.3.1). > > > > Signed-off-by: Flavio Leitner > > The reason for putting this into the inetpeer cache was so that we > didn't need to consult the routing cache at all. We're working to > remove it at some point, so every dependency matters. > > Can you implement this such that only an inetpeer cache probe is > necessary? > Sure, I have reviewed your patch series to remove the routing cache and I believe this version works with and without it, though I have tested only with current net-next code. Thanks for your time reviewing, I appreciate it. fbl Signed-off-by: Flavio Leitner --- net/ipv4/route.c | 43 ++++++++++++++++++++++++++++++++++++++----- 1 files changed, 38 insertions(+), 5 deletions(-) diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 26c77e1..1a639b9 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -1308,8 +1308,14 @@ static void rt_del(unsigned hash, struct rtable *rt) void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw, __be32 saddr, struct net_device *dev) { + int s, i; struct in_device *in_dev = __in_dev_get_rcu(dev); + struct rtable *rt; + __be32 skeys[2] = { saddr, 0 }; + int ikeys[2] = { dev->ifindex, 0 }; + struct flowi4 fl4; struct inet_peer *peer; + bool putpeer = false; struct net *net; if (!in_dev) @@ -1331,13 +1337,40 @@ void ip_rt_redirect(__be32 old_gw, __be32 daddr, __be32 new_gw, goto reject_redirect; } - peer = inet_getpeer_v4(daddr, 1); - if (peer) { - peer->redirect_learned.a4 = new_gw; + memset(&fl4, 0, sizeof(fl4)); + fl4.daddr = daddr; + for (s = 0; s < 2; s++) { + for (i = 0; i < 2; i++) { + fl4.flowi4_oif = ikeys[i]; + fl4.saddr = skeys[s]; + rt = __ip_route_output_key(net, &fl4); + if (IS_ERR(rt)) + continue; - inet_putpeer(peer); + if (rt->dst.error || rt->dst.dev != dev || + rt->rt_gateway != old_gw) { + ip_rt_put(rt); + continue; + } - atomic_inc(&__rt_peer_genid); + peer = rt->peer; + if (!peer) { + peer = inet_getpeer_v4(daddr, 1); + putpeer = true; + } + + if (peer) { + peer->redirect_learned.a4 = new_gw; + + if (putpeer) + inet_putpeer(peer); + + atomic_inc(&__rt_peer_genid); + } + + ip_rt_put(rt); + return; + } } return;