All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH ipsec] ip_vti: receive ipip packet by calling ip_tunnel_rcv
@ 2020-04-21 12:46 Xin Long
  2020-04-23  6:07 ` Steffen Klassert
  0 siblings, 1 reply; 2+ messages in thread
From: Xin Long @ 2020-04-21 12:46 UTC (permalink / raw)
  To: netdev
  Cc: Su Yanjun, Steffen Klassert, Herbert Xu, David S. Miller,
	Sabrina Dubroca

In Commit dd9ee3444014 ("vti4: Fix a ipip packet processing bug in
'IPCOMP' virtual tunnel"), it tries to receive IPIP packets in vti
by calling xfrm_input(). This case happens when a small packet or
frag sent by peer is too small to get compressed.

However, xfrm_input() will still get to the IPCOMP path where skb
sec_path is set, but never dropped while it should have been done
in vti_ipcomp4_protocol.cb_handler(vti_rcv_cb), as it's not an
ipcomp4 packet. This will cause that the packet can never pass
xfrm4_policy_check() in the upper protocol rcv functions.

So this patch is to call ip_tunnel_rcv() to process IPIP packets
instead.

Fixes: dd9ee3444014 ("vti4: Fix a ipip packet processing bug in 'IPCOMP' virtual tunnel")
Reported-by: Xiumei Mu <xmu@redhat.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/ipv4/ip_vti.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
index 1b4e6f2..1dda7c1 100644
--- a/net/ipv4/ip_vti.c
+++ b/net/ipv4/ip_vti.c
@@ -93,7 +93,28 @@ static int vti_rcv_proto(struct sk_buff *skb)
 
 static int vti_rcv_tunnel(struct sk_buff *skb)
 {
-	return vti_rcv(skb, ip_hdr(skb)->saddr, true);
+	struct ip_tunnel_net *itn = net_generic(dev_net(skb->dev), vti_net_id);
+	const struct iphdr *iph = ip_hdr(skb);
+	struct ip_tunnel *tunnel;
+
+	tunnel = ip_tunnel_lookup(itn, skb->dev->ifindex, TUNNEL_NO_KEY,
+				  iph->saddr, iph->daddr, 0);
+	if (tunnel) {
+		struct tnl_ptk_info tpi = {
+			.proto = htons(ETH_P_IP),
+		};
+
+		if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb))
+			goto drop;
+		if (iptunnel_pull_header(skb, 0, tpi.proto, false))
+			goto drop;
+		return ip_tunnel_rcv(tunnel, skb, &tpi, NULL, false);
+	}
+
+	return -EINVAL;
+drop:
+	kfree_skb(skb);
+	return 0;
 }
 
 static int vti_rcv_cb(struct sk_buff *skb, int err)
-- 
2.1.0


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

* Re: [PATCH ipsec] ip_vti: receive ipip packet by calling ip_tunnel_rcv
  2020-04-21 12:46 [PATCH ipsec] ip_vti: receive ipip packet by calling ip_tunnel_rcv Xin Long
@ 2020-04-23  6:07 ` Steffen Klassert
  0 siblings, 0 replies; 2+ messages in thread
From: Steffen Klassert @ 2020-04-23  6:07 UTC (permalink / raw)
  To: Xin Long; +Cc: netdev, Su Yanjun, Herbert Xu, David S. Miller, Sabrina Dubroca

On Tue, Apr 21, 2020 at 08:46:11PM +0800, Xin Long wrote:
> In Commit dd9ee3444014 ("vti4: Fix a ipip packet processing bug in
> 'IPCOMP' virtual tunnel"), it tries to receive IPIP packets in vti
> by calling xfrm_input(). This case happens when a small packet or
> frag sent by peer is too small to get compressed.
> 
> However, xfrm_input() will still get to the IPCOMP path where skb
> sec_path is set, but never dropped while it should have been done
> in vti_ipcomp4_protocol.cb_handler(vti_rcv_cb), as it's not an
> ipcomp4 packet. This will cause that the packet can never pass
> xfrm4_policy_check() in the upper protocol rcv functions.
> 
> So this patch is to call ip_tunnel_rcv() to process IPIP packets
> instead.
> 
> Fixes: dd9ee3444014 ("vti4: Fix a ipip packet processing bug in 'IPCOMP' virtual tunnel")
> Reported-by: Xiumei Mu <xmu@redhat.com>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>

Applied, thanks!

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

end of thread, other threads:[~2020-04-23  6:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-21 12:46 [PATCH ipsec] ip_vti: receive ipip packet by calling ip_tunnel_rcv Xin Long
2020-04-23  6:07 ` Steffen Klassert

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.