All of lore.kernel.org
 help / color / mirror / Atom feed
* pull request (net): ipsec 2015-03-16
@ 2015-03-16  6:52 Steffen Klassert
  2015-03-16  6:52 ` [PATCH 1/3] xfrm6: Fix a offset value for network header in _decode_session6 Steffen Klassert
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Steffen Klassert @ 2015-03-16  6:52 UTC (permalink / raw)
  To: David Miller; +Cc: Herbert Xu, Steffen Klassert, netdev

1) Fix the network header offset in _decode_session6
   when multiple IPv6 extension headers are present.
   From Hajime Tazaki.

2) Fix an interfamily tunnel crash. We set outer mode
   protocol too early and may dispatch to the wrong
   address family. Move the setting of the outer mode
   protocol behind the last accessing of the inner mode
   to fix the crash.

3) Most callers of xfrm_lookup() expect that dst_orig
   is released on error. But xfrm_lookup_route() may
   need dst_orig to handle certain error cases. So
   introduce a flag that tells what should be done in
   case of error. From Huaibin Wang.

Please pull or let me know if there are problems.

Thanks!

The following changes since commit 59343cd7c4809cf7598789e1cd14563780ae4239:

  Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net (2015-01-27 13:55:36 -0800)

are available in the git repository at:


  git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git master

for you to fetch changes up to ac37e2515c1a89c477459a2020b6bfdedabdb91b:

  xfrm: release dst_orig in case of error in xfrm_lookup() (2015-02-12 07:10:56 +0100)

----------------------------------------------------------------
Hajime Tazaki (1):
      xfrm6: Fix a offset value for network header in _decode_session6

Steffen Klassert (1):
      xfrm: Fix local error reporting crash with interfamily tunnels

huaibin Wang (1):
      xfrm: release dst_orig in case of error in xfrm_lookup()

 include/net/dst.h       |  1 +
 net/ipv4/xfrm4_output.c |  2 +-
 net/ipv6/xfrm6_output.c |  2 +-
 net/ipv6/xfrm6_policy.c |  1 +
 net/xfrm/xfrm_policy.c  | 12 ++++++------
 5 files changed, 10 insertions(+), 8 deletions(-)

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

* [PATCH 1/3] xfrm6: Fix a offset value for network header in _decode_session6
  2015-03-16  6:52 pull request (net): ipsec 2015-03-16 Steffen Klassert
@ 2015-03-16  6:52 ` Steffen Klassert
  2015-03-16  6:52 ` [PATCH 2/3] xfrm: Fix local error reporting crash with interfamily tunnels Steffen Klassert
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Steffen Klassert @ 2015-03-16  6:52 UTC (permalink / raw)
  To: David Miller; +Cc: Herbert Xu, Steffen Klassert, netdev

From: Hajime Tazaki <tazaki@sfc.wide.ad.jp>

When a network-layer header has multiple IPv6 extension headers, then offset
for mobility header goes wrong. This regression breaks an xfrm policy lookup
for a particular receive packet. Binding update packets of Mobile IPv6
are all discarded without this fix.

Fixes: de3b7a06dfe1 ("xfrm6: Fix transport header offset in _decode_session6.")
Signed-off-by: Hajime Tazaki <tazaki@sfc.wide.ad.jp>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 net/ipv6/xfrm6_policy.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
index 48bf5a0..8d2d01b 100644
--- a/net/ipv6/xfrm6_policy.c
+++ b/net/ipv6/xfrm6_policy.c
@@ -200,6 +200,7 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
 
 #if IS_ENABLED(CONFIG_IPV6_MIP6)
 		case IPPROTO_MH:
+			offset += ipv6_optlen(exthdr);
 			if (!onlyproto && pskb_may_pull(skb, nh + offset + 3 - skb->data)) {
 				struct ip6_mh *mh;
 
-- 
1.9.1

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

* [PATCH 2/3] xfrm: Fix local error reporting crash with interfamily tunnels
  2015-03-16  6:52 pull request (net): ipsec 2015-03-16 Steffen Klassert
  2015-03-16  6:52 ` [PATCH 1/3] xfrm6: Fix a offset value for network header in _decode_session6 Steffen Klassert
@ 2015-03-16  6:52 ` Steffen Klassert
  2015-03-16  6:52 ` [PATCH 3/3] xfrm: release dst_orig in case of error in xfrm_lookup() Steffen Klassert
  2015-03-16 20:17 ` pull request (net): ipsec 2015-03-16 David Miller
  3 siblings, 0 replies; 5+ messages in thread
From: Steffen Klassert @ 2015-03-16  6:52 UTC (permalink / raw)
  To: David Miller; +Cc: Herbert Xu, Steffen Klassert, netdev

We set the outer mode protocol too early. As a result, the
local error handler might dispatch to the wrong address family
and report the error to a wrong socket type. We fix this by
setting the outer protocol to the skb after we accessed the
inner mode for the last time, right before we do the atcual
encapsulation where we switch finally to the outer mode.

Reported-by: Chris Ruehl <chris.ruehl@gtsys.com.hk>
Tested-by: Chris Ruehl <chris.ruehl@gtsys.com.hk>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 net/ipv4/xfrm4_output.c | 2 +-
 net/ipv6/xfrm6_output.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/xfrm4_output.c b/net/ipv4/xfrm4_output.c
index d5f6bd9..dab7381 100644
--- a/net/ipv4/xfrm4_output.c
+++ b/net/ipv4/xfrm4_output.c
@@ -63,6 +63,7 @@ int xfrm4_prepare_output(struct xfrm_state *x, struct sk_buff *skb)
 		return err;
 
 	IPCB(skb)->flags |= IPSKB_XFRM_TUNNEL_SIZE;
+	skb->protocol = htons(ETH_P_IP);
 
 	return x->outer_mode->output2(x, skb);
 }
@@ -71,7 +72,6 @@ EXPORT_SYMBOL(xfrm4_prepare_output);
 int xfrm4_output_finish(struct sk_buff *skb)
 {
 	memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
-	skb->protocol = htons(ETH_P_IP);
 
 #ifdef CONFIG_NETFILTER
 	IPCB(skb)->flags |= IPSKB_XFRM_TRANSFORMED;
diff --git a/net/ipv6/xfrm6_output.c b/net/ipv6/xfrm6_output.c
index ca3f29b..010f8bd 100644
--- a/net/ipv6/xfrm6_output.c
+++ b/net/ipv6/xfrm6_output.c
@@ -114,6 +114,7 @@ int xfrm6_prepare_output(struct xfrm_state *x, struct sk_buff *skb)
 		return err;
 
 	skb->ignore_df = 1;
+	skb->protocol = htons(ETH_P_IPV6);
 
 	return x->outer_mode->output2(x, skb);
 }
@@ -122,7 +123,6 @@ EXPORT_SYMBOL(xfrm6_prepare_output);
 int xfrm6_output_finish(struct sk_buff *skb)
 {
 	memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
-	skb->protocol = htons(ETH_P_IPV6);
 
 #ifdef CONFIG_NETFILTER
 	IP6CB(skb)->flags |= IP6SKB_XFRM_TRANSFORMED;
-- 
1.9.1

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

* [PATCH 3/3] xfrm: release dst_orig in case of error in xfrm_lookup()
  2015-03-16  6:52 pull request (net): ipsec 2015-03-16 Steffen Klassert
  2015-03-16  6:52 ` [PATCH 1/3] xfrm6: Fix a offset value for network header in _decode_session6 Steffen Klassert
  2015-03-16  6:52 ` [PATCH 2/3] xfrm: Fix local error reporting crash with interfamily tunnels Steffen Klassert
@ 2015-03-16  6:52 ` Steffen Klassert
  2015-03-16 20:17 ` pull request (net): ipsec 2015-03-16 David Miller
  3 siblings, 0 replies; 5+ messages in thread
From: Steffen Klassert @ 2015-03-16  6:52 UTC (permalink / raw)
  To: David Miller; +Cc: Herbert Xu, Steffen Klassert, netdev

From: huaibin Wang <huaibin.wang@6wind.com>

dst_orig should be released on error. Function like __xfrm_route_forward()
expects that behavior.
Since a recent commit, xfrm_lookup() may also be called by xfrm_lookup_route(),
which expects the opposite.
Let's introduce a new flag (XFRM_LOOKUP_KEEP_DST_REF) to tell what should be
done in case of error.

Fixes: f92ee61982d("xfrm: Generate blackhole routes only from route lookup functions")
Signed-off-by: huaibin Wang <huaibin.wang@6wind.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 include/net/dst.h      |  1 +
 net/xfrm/xfrm_policy.c | 12 ++++++------
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/include/net/dst.h b/include/net/dst.h
index a8ae4e7..0fb99a2 100644
--- a/include/net/dst.h
+++ b/include/net/dst.h
@@ -481,6 +481,7 @@ void dst_init(void);
 enum {
 	XFRM_LOOKUP_ICMP = 1 << 0,
 	XFRM_LOOKUP_QUEUE = 1 << 1,
+	XFRM_LOOKUP_KEEP_DST_REF = 1 << 2,
 };
 
 struct flowi;
diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index cee479b..638af06 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -2269,11 +2269,9 @@ struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig,
 		 * have the xfrm_state's. We need to wait for KM to
 		 * negotiate new SA's or bail out with error.*/
 		if (net->xfrm.sysctl_larval_drop) {
-			dst_release(dst);
-			xfrm_pols_put(pols, drop_pols);
 			XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTNOSTATES);
-
-			return ERR_PTR(-EREMOTE);
+			err = -EREMOTE;
+			goto error;
 		}
 
 		err = -EAGAIN;
@@ -2324,7 +2322,8 @@ nopol:
 error:
 	dst_release(dst);
 dropdst:
-	dst_release(dst_orig);
+	if (!(flags & XFRM_LOOKUP_KEEP_DST_REF))
+		dst_release(dst_orig);
 	xfrm_pols_put(pols, drop_pols);
 	return ERR_PTR(err);
 }
@@ -2338,7 +2337,8 @@ struct dst_entry *xfrm_lookup_route(struct net *net, struct dst_entry *dst_orig,
 				    struct sock *sk, int flags)
 {
 	struct dst_entry *dst = xfrm_lookup(net, dst_orig, fl, sk,
-					    flags | XFRM_LOOKUP_QUEUE);
+					    flags | XFRM_LOOKUP_QUEUE |
+					    XFRM_LOOKUP_KEEP_DST_REF);
 
 	if (IS_ERR(dst) && PTR_ERR(dst) == -EREMOTE)
 		return make_blackhole(net, dst_orig->ops->family, dst_orig);
-- 
1.9.1

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

* Re: pull request (net): ipsec 2015-03-16
  2015-03-16  6:52 pull request (net): ipsec 2015-03-16 Steffen Klassert
                   ` (2 preceding siblings ...)
  2015-03-16  6:52 ` [PATCH 3/3] xfrm: release dst_orig in case of error in xfrm_lookup() Steffen Klassert
@ 2015-03-16 20:17 ` David Miller
  3 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2015-03-16 20:17 UTC (permalink / raw)
  To: steffen.klassert; +Cc: herbert, netdev

From: Steffen Klassert <steffen.klassert@secunet.com>
Date: Mon, 16 Mar 2015 07:52:21 +0100

> 1) Fix the network header offset in _decode_session6
>    when multiple IPv6 extension headers are present.
>    From Hajime Tazaki.
> 
> 2) Fix an interfamily tunnel crash. We set outer mode
>    protocol too early and may dispatch to the wrong
>    address family. Move the setting of the outer mode
>    protocol behind the last accessing of the inner mode
>    to fix the crash.
> 
> 3) Most callers of xfrm_lookup() expect that dst_orig
>    is released on error. But xfrm_lookup_route() may
>    need dst_orig to handle certain error cases. So
>    introduce a flag that tells what should be done in
>    case of error. From Huaibin Wang.
> 
> Please pull or let me know if there are problems.

Pulled, thanks a lot.

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

end of thread, other threads:[~2015-03-16 20:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-16  6:52 pull request (net): ipsec 2015-03-16 Steffen Klassert
2015-03-16  6:52 ` [PATCH 1/3] xfrm6: Fix a offset value for network header in _decode_session6 Steffen Klassert
2015-03-16  6:52 ` [PATCH 2/3] xfrm: Fix local error reporting crash with interfamily tunnels Steffen Klassert
2015-03-16  6:52 ` [PATCH 3/3] xfrm: release dst_orig in case of error in xfrm_lookup() Steffen Klassert
2015-03-16 20:17 ` pull request (net): ipsec 2015-03-16 David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.