netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] vti: use right inner_mode for inbound inter address family policy checks
@ 2016-09-04 10:57 Thomas Zeitlhofer
  2016-09-06 11:15 ` Steffen Klassert
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Zeitlhofer @ 2016-09-04 10:57 UTC (permalink / raw)
  To: Steffen Klassert; +Cc: Herbert Xu, David S. Miller, netdev

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;
+	}
+
+	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;
+	}
+
+	family = inner_mode->afinfo->family;
 
 	skb->mark = be32_to_cpu(t->parms.i_key);
 	ret = xfrm_policy_check(NULL, XFRM_POLICY_IN, skb, family);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] vti: use right inner_mode for inbound inter address family policy checks
  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
  2016-09-07 18:40   ` [PATCH v2] " thomas.zeitlhofer+lkml
  0 siblings, 1 reply; 5+ messages in thread
From: Steffen Klassert @ 2016-09-06 11:15 UTC (permalink / raw)
  To: Thomas Zeitlhofer; +Cc: Herbert Xu, David S. Miller, netdev

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] vti: use right inner_mode for inbound inter address family policy checks
  2016-09-06 11:15 ` Steffen Klassert
@ 2016-09-07 18:40   ` thomas.zeitlhofer+lkml
  2016-09-09  0:17     ` David Miller
  2016-09-09  8:36     ` Steffen Klassert
  0 siblings, 2 replies; 5+ messages in thread
From: thomas.zeitlhofer+lkml @ 2016-09-07 18:40 UTC (permalink / raw)
  To: Steffen Klassert; +Cc: Herbert Xu, David S. Miller, netdev

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_input() (i.e., also
increment LINUX_MIB_XFRMINSTATEMODEERROR in case of error), 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:
    v2: implement review comments from Steffen (thanks for the reply):
    
    	- return -EINVAL in case of error
    
    	- increment LINUX_MIB_XFRMINSTATEMODEERROR in case of error
    
    	  Just to point that out, in case there are arguments against it:
    	  this is done in the namespace of skb->dev and not in the
    	  t(unnel)?->net namespace.
    
    	and update the commit message accordingly.

 net/ipv4/ip_vti.c  | 15 ++++++++++++++-
 net/ipv6/ip6_vti.c | 15 ++++++++++++++-
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
index a917903..c9957ed 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,19 @@ 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) {
+			XFRM_INC_STATS(dev_net(skb->dev),
+				       LINUX_MIB_XFRMINSTATEMODEERROR);
+			return -EINVAL;
+		}
+	}
+
+	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..52a2f73 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,19 @@ 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) {
+			XFRM_INC_STATS(dev_net(skb->dev),
+				       LINUX_MIB_XFRMINSTATEMODEERROR);
+			return -EINVAL;
+		}
+	}
+
+	family = inner_mode->afinfo->family;
 
 	skb->mark = be32_to_cpu(t->parms.i_key);
 	ret = xfrm_policy_check(NULL, XFRM_POLICY_IN, skb, family);
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] vti: use right inner_mode for inbound inter address family policy checks
  2016-09-07 18:40   ` [PATCH v2] " thomas.zeitlhofer+lkml
@ 2016-09-09  0:17     ` David Miller
  2016-09-09  8:36     ` Steffen Klassert
  1 sibling, 0 replies; 5+ messages in thread
From: David Miller @ 2016-09-09  0:17 UTC (permalink / raw)
  To: thomas.zeitlhofer+lkml; +Cc: steffen.klassert, herbert, netdev

From: thomas.zeitlhofer+lkml@ze-it.at
Date: Wed, 7 Sep 2016 20:40:38 +0200

> 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_input() (i.e., also
> increment LINUX_MIB_XFRMINSTATEMODEERROR in case of error), 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>

Steffen please review this new version of the patch.

Thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] vti: use right inner_mode for inbound inter address family policy checks
  2016-09-07 18:40   ` [PATCH v2] " thomas.zeitlhofer+lkml
  2016-09-09  0:17     ` David Miller
@ 2016-09-09  8:36     ` Steffen Klassert
  1 sibling, 0 replies; 5+ messages in thread
From: Steffen Klassert @ 2016-09-09  8:36 UTC (permalink / raw)
  To: thomas.zeitlhofer+lkml; +Cc: Herbert Xu, David S. Miller, netdev

On Wed, Sep 07, 2016 at 08:40:38PM +0200, thomas.zeitlhofer+lkml@ze-it.at 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_input() (i.e., also
> increment LINUX_MIB_XFRMINSTATEMODEERROR in case of error), 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:
>     v2: implement review comments from Steffen (thanks for the reply):
>     
>     	- return -EINVAL in case of error
>     
>     	- increment LINUX_MIB_XFRMINSTATEMODEERROR in case of error
>     
>     	  Just to point that out, in case there are arguments against it:
>     	  this is done in the namespace of skb->dev and not in the
>     	  t(unnel)?->net namespace.

This is ok because the states are configured in that namespace.

I've applied this to the ipsec tree, thanks a lot!

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-09-09  8:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2016-09-07 18:40   ` [PATCH v2] " thomas.zeitlhofer+lkml
2016-09-09  0:17     ` David Miller
2016-09-09  8:36     ` Steffen Klassert

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).