public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2] iptunnel: detect protocol mismatch on tunnel change
@ 2023-04-10 23:35 Stephen Hemminger
  2023-04-11 10:09 ` Luca Boccassi
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Stephen Hemminger @ 2023-04-10 23:35 UTC (permalink / raw)
  To: netdev; +Cc: bluca, dsahern, Stephen Hemminger, Robin

If attempt is made to change an IPv6 tunnel by using IPv4
parameters, a stack overflow would happen and garbage request
would be passed to kernel.

Example:
ip tunnel add gre1 mode ip6gre local 2001:db8::1 remote 2001:db8::2 ttl 255
ip tunnel change gre1 mode gre local 192.168.0.0 remote 192.168.0.1 ttl 255

The second command should fail because it attempting set IPv4 addresses
on a GRE tunnel that is IPv6.

Do best effort detection of this mismatch by giving a bigger buffer to get
tunnel request, and checking that the IP header is IPv4. It is still possible
but unlikely that byte would match in IPv6 tunnel paramater, but good enough
to catch the obvious cases.

Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1032642
Reported-by: Robin <imer@imer.cc>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 ip/iptunnel.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/ip/iptunnel.c b/ip/iptunnel.c
index 02c3670b469d..b6da145913d6 100644
--- a/ip/iptunnel.c
+++ b/ip/iptunnel.c
@@ -17,6 +17,7 @@
 #include <net/if_arp.h>
 #include <linux/ip.h>
 #include <linux/if_tunnel.h>
+#include <linux/ip6_tunnel.h>
 
 #include "rt_names.h"
 #include "utils.h"
@@ -172,11 +173,20 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
 			if (get_ifname(p->name, *argv))
 				invarg("\"name\" not a valid ifname", *argv);
 			if (cmd == SIOCCHGTUNNEL && count == 0) {
-				struct ip_tunnel_parm old_p = {};
+				union {
+					struct ip_tunnel_parm ip_tnl;
+					struct ip6_tnl_parm2 ip6_tnl;
+				} old_p = {};
 
 				if (tnl_get_ioctl(*argv, &old_p))
 					return -1;
-				*p = old_p;
+
+				if (old_p.ip_tnl.iph.version != 4 ||
+				    old_p.ip_tnl.iph.ihl != 5)
+					invarg("\"name\" is not an ip tunnel",
+					       *argv);
+
+				*p = old_p.ip_tnl;
 			}
 		}
 		count++;
-- 
2.39.2


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

end of thread, other threads:[~2023-04-14 20:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-10 23:35 [PATCH iproute2] iptunnel: detect protocol mismatch on tunnel change Stephen Hemminger
2023-04-11 10:09 ` Luca Boccassi
2023-04-11 15:55 ` David Ahern
2023-04-11 16:49   ` Stephen Hemminger
2023-04-14 20:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox