From: Steffen Klassert <steffen.klassert@secunet.com>
To: Thomas Zeitlhofer <thomas.zeitlhofer+lkml@ze-it.at>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>, <netdev@vger.kernel.org>
Subject: Re: [PATCH] vti: use right inner_mode for inbound inter address family policy checks
Date: Tue, 6 Sep 2016 13:15:23 +0200 [thread overview]
Message-ID: <20160906111522.GG31137@gauss.secunet.com> (raw)
In-Reply-To: <20160904105713.3mqgszgqi7waxk5l@toau>
On Sun, Sep 04, 2016 at 12:57:13PM +0200, Thomas Zeitlhofer wrote:
> In case of inter address family tunneling (IPv6 over vti4 or IPv4 over
> vti6), the inbound policy checks in vti_rcv_cb and vti6_rcv_cb are using
> the wrong address family. As a result, all inbound inter address family
> traffic is dropped.
>
> Use the xfrm_ip2inner_mode helper (as done in xfrm_prepare_input and
> xfrm_input) to select the inner_mode that contains the right address family
> for the inbound policy checks.
>
> Signed-off-by: Thomas Zeitlhofer <thomas.zeitlhofer+lkml@ze-it.at>
> ---
>
> Notes:
> The patch was developed by looking at the code, but without knowledge of
> the XFRM code in the kernel. It has been successfully tested, but it is
> more a guess that might be helpful for the maintainers to find a proper
> solution.
>
> net/ipv4/ip_vti.c | 12 +++++++++++-
> net/ipv6/ip6_vti.c | 12 +++++++++++-
> 2 files changed, 22 insertions(+), 2 deletions(-)
>
> diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
> index a917903..44d5449 100644
> --- a/net/ipv4/ip_vti.c
> +++ b/net/ipv4/ip_vti.c
> @@ -88,6 +88,7 @@ static int vti_rcv_cb(struct sk_buff *skb, int err)
> struct net_device *dev;
> struct pcpu_sw_netstats *tstats;
> struct xfrm_state *x;
> + struct xfrm_mode *inner_mode;
> struct ip_tunnel *tunnel = XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip4;
> u32 orig_mark = skb->mark;
> int ret;
> @@ -105,7 +106,16 @@ static int vti_rcv_cb(struct sk_buff *skb, int err)
> }
>
> x = xfrm_input_state(skb);
> - family = x->inner_mode->afinfo->family;
> +
> + inner_mode = x->inner_mode;
> +
> + if (x->sel.family == AF_UNSPEC) {
> + inner_mode = xfrm_ip2inner_mode(x, XFRM_MODE_SKB_CB(skb)->protocol);
> + if (inner_mode == NULL)
> + return -EPERM;
You better return -EINVAL instead of -EPERM here.
Also you should bump the LINUX_MIB_XFRMINSTATEMODEERROR
counter as we do in xfrm_input.
> + }
> +
> + family = inner_mode->afinfo->family;
>
> skb->mark = be32_to_cpu(tunnel->parms.i_key);
> ret = xfrm_policy_check(NULL, XFRM_POLICY_IN, skb, family);
> diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
> index d90a11f..3149757 100644
> --- a/net/ipv6/ip6_vti.c
> +++ b/net/ipv6/ip6_vti.c
> @@ -340,6 +340,7 @@ static int vti6_rcv_cb(struct sk_buff *skb, int err)
> struct net_device *dev;
> struct pcpu_sw_netstats *tstats;
> struct xfrm_state *x;
> + struct xfrm_mode *inner_mode;
> struct ip6_tnl *t = XFRM_TUNNEL_SKB_CB(skb)->tunnel.ip6;
> u32 orig_mark = skb->mark;
> int ret;
> @@ -357,7 +358,16 @@ static int vti6_rcv_cb(struct sk_buff *skb, int err)
> }
>
> x = xfrm_input_state(skb);
> - family = x->inner_mode->afinfo->family;
> +
> + inner_mode = x->inner_mode;
> +
> + if (x->sel.family == AF_UNSPEC) {
> + inner_mode = xfrm_ip2inner_mode(x, XFRM_MODE_SKB_CB(skb)->protocol);
> + if (inner_mode == NULL)
> + return -EPERM;
Same here.
Other that that it looks ok to me.
next prev parent reply other threads:[~2016-09-06 11:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-04 10:57 [PATCH] vti: use right inner_mode for inbound inter address family policy checks Thomas Zeitlhofer
2016-09-06 11:15 ` Steffen Klassert [this message]
2016-09-07 18:40 ` [PATCH v2] " thomas.zeitlhofer+lkml
2016-09-09 0:17 ` David Miller
2016-09-09 8:36 ` Steffen Klassert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160906111522.GG31137@gauss.secunet.com \
--to=steffen.klassert@secunet.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=netdev@vger.kernel.org \
--cc=thomas.zeitlhofer+lkml@ze-it.at \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).