Skip to contentSkip to conversation

ipip: fix a regression in ioctl

PATCH Superseded Cong Wang 4 participants 7 messages Jun 29, 2013 – Jul 2, 2013

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 ipip: fix a regression in ioctl

From: Cong Wang <[email protected]>

This is a regression introduced by
commit fd58156e456d9f68fe0448 (IPIP: Use ip-tunneling code.)

Similar to GRE tunnel, previously we only check the parameters for SIOCADDTUNNEL and SIOCCHGTUNNEL, after that commit, the check is moved for all commands.

So, just check for SIOCADDTUNNEL and SIOCCHGTUNNEL.

Also, the check for i_key, o_key etc. is suspicious too, which did not exist before.

Cc Pravin B Shelar <[email protected]>
Cc "David S. Miller" <[email protected]>

---

net/ipv4/ipip.c +5 -5
index e6905fb..9d6ca81 100644
@@ -244,11 +244,11 @@ ipip_tunnel_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
 	if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
 		return -EFAULT;
 
-	if (p.iph.version != 4 || p.iph.protocol != IPPROTO_IPIP ||
-			p.iph.ihl != 5 || (p.iph.frag_off&htons(~IP_DF)))
-		return -EINVAL;
-	if (p.i_key || p.o_key || p.i_flags || p.o_flags)
-		return -EINVAL;
+	if (cmd == SIOCADDTUNNEL || cmd == SIOCCHGTUNNEL) {
+		if (p.iph.version != 4 || p.iph.protocol != IPPROTO_IPIP ||
+		    p.iph.ihl != 5 || (p.iph.frag_off&htons(~IP_DF)))
+			return -EINVAL;
+	}
 	if (p.iph.ttl)
 		p.iph.frag_off |= htons(IP_DF);
 
#1 lore raw
Quoted 25 lines · Cong Wang

From: Cong Wang <[email protected]>

This is a regression introduced by
commit fd58156e456d9f68fe0448 (IPIP: Use ip-tunneling code.)

Similar to GRE tunnel, previously we only check the parameters for SIOCADDTUNNEL and SIOCCHGTUNNEL, after that commit, the check is moved for all commands.

So, just check for SIOCADDTUNNEL and SIOCCHGTUNNEL.

Also, the check for i_key, o_key etc. is suspicious too, which did not exist before.

Cc Pravin B Shelar <[email protected]>
Cc "David S. Miller" <[email protected]>

---

net/ipv4/ipip.c +0 -0
index e6905fb..9d6ca81 100644
@@ -244,11 +244,11 @@ ipip_tunnel_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  	if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))

net/ipv4/ipip.c ipip_tunnel_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) · line 249

Quoted 10 lines
net/ipv4/ipip.c +3 -5
  		return -EFAULT;
 
-	if (p.iph.version != 4 || p.iph.protocol != IPPROTO_IPIP ||
-			p.iph.ihl != 5 || (p.iph.frag_off&htons(~IP_DF)))
-		return -EINVAL;
-	if (p.i_key || p.o_key || p.i_flags || p.o_flags)
-		return -EINVAL;
+	if (cmd == SIOCADDTUNNEL || cmd == SIOCCHGTUNNEL) {
+		if (p.iph.version != 4 || p.iph.protocol != IPPROTO_IPIP ||
+		    p.iph.ihl != 5 || (p.iph.frag_off&htons(~IP_DF)))

Maybe it's time to put spaces around & to make code formatting more
consistent here too?

WBR, Sergei

#2 lore raw
In reply to Cong Wang
Quoted 5 lines · Cong Wang

From: Cong Wang <[email protected]>

This is a regression introduced by
commit fd58156e456d9f68fe0448 (IPIP: Use ip-tunneling code.)

Quoted 9 lines

Similar to GRE tunnel, previously we only check the parameters for SIOCADDTUNNEL and SIOCCHGTUNNEL, after that commit, the check is moved for all commands.

So, just check for SIOCADDTUNNEL and SIOCCHGTUNNEL.

Also, the check for i_key, o_key etc. is suspicious too, which did not exist before.

This check is sanity check since ipip is not suppose to have these parameters set, generic layer do allow all parameters.
Earlier ipip was not using generic layer, therefore that check was not present.

Quoted 26 lines
Cc Pravin B Shelar <[email protected]>
Cc "David S. Miller" <[email protected]>

---

net/ipv4/ipip.c +5 -5
index e6905fb..9d6ca81 100644
@@ -244,11 +244,11 @@ ipip_tunnel_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
        if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
                return -EFAULT;
 
-       if (p.iph.version != 4 || p.iph.protocol != IPPROTO_IPIP ||
-                       p.iph.ihl != 5 || (p.iph.frag_off&htons(~IP_DF)))
-               return -EINVAL;
-       if (p.i_key || p.o_key || p.i_flags || p.o_flags)
-               return -EINVAL;
+       if (cmd == SIOCADDTUNNEL || cmd == SIOCCHGTUNNEL) {
+               if (p.iph.version != 4 || p.iph.protocol != IPPROTO_IPIP ||
+                   p.iph.ihl != 5 || (p.iph.frag_off&htons(~IP_DF)))
+                       return -EINVAL;
+       }
        if (p.iph.ttl)
                p.iph.frag_off |= htons(IP_DF);
 
author
#3 lore raw
Quoted 10 lines · Pravin Shelar
Quoted 9 lines · Cong Wang

From: Cong Wang <[email protected]>

This is a regression introduced by
commit fd58156e456d9f68fe0448 (IPIP: Use ip-tunneling code.)

Similar to GRE tunnel, previously we only check the parameters for SIOCADDTUNNEL and SIOCCHGTUNNEL, after that commit, the check is moved for all commands.

Quoted 8 lines
Quoted 5 lines

So, just check for SIOCADDTUNNEL and SIOCCHGTUNNEL.

Also, the check for i_key, o_key etc. is suspicious too, which did not exist before.

This check is sanity check since ipip is not suppose to have these parameters set, generic layer do allow all parameters.
Earlier ipip was not using generic layer, therefore that check was not present.

So, if old code doesn't reject this case with EINVAL, then your change _does_ break user-space applications... no matter whether ipip is supposed to have these parameters.

#4 lore raw
Quoted 16 lines · Cong Wang
Quoted 15 lines · Pravin Shelar
Quoted 14 lines · Cong Wang

From: Cong Wang <[email protected]>

This is a regression introduced by
commit fd58156e456d9f68fe0448 (IPIP: Use ip-tunneling code.)

Similar to GRE tunnel, previously we only check the parameters for SIOCADDTUNNEL and SIOCCHGTUNNEL, after that commit, the check is moved for all commands.

So, just check for SIOCADDTUNNEL and SIOCCHGTUNNEL.

Also, the check for i_key, o_key etc. is suspicious too, which did not exist before.

Quoted 8 lines
Quoted 3 lines

This check is sanity check since ipip is not suppose to have these parameters set, generic layer do allow all parameters.
Earlier ipip was not using generic layer, therefore that check was not present.

So, if old code doesn't reject this case with EINVAL, then your change _does_ break user-space applications... no matter whether ipip is supposed to have these parameters.

ok, Then we shld reset these fields before passing them to ip_tunnels layer.

Quoted 1 line
maintainer
#5 lore raw

From: Pravin Shelar <[email protected]>
Date: Mon, 1 Jul 2013 08:03:33 -0700

Quoted 21 lines · Cong Wang
Quoted 20 lines · Pravin Shelar
Quoted 18 lines · Cong Wang
Quoted 5 lines

From: Cong Wang <[email protected]>

This is a regression introduced by
commit fd58156e456d9f68fe0448 (IPIP: Use ip-tunneling code.)

Quoted 9 lines

Similar to GRE tunnel, previously we only check the parameters for SIOCADDTUNNEL and SIOCCHGTUNNEL, after that commit, the check is moved for all commands.

So, just check for SIOCADDTUNNEL and SIOCCHGTUNNEL.

Also, the check for i_key, o_key etc. is suspicious too, which did not exist before.

This check is sanity check since ipip is not suppose to have these parameters set, generic layer do allow all parameters.
Earlier ipip was not using generic layer, therefore that check was not present.

Quoted 5 lines
Quoted 4 lines

So, if old code doesn't reject this case with EINVAL, then your change _does_ break user-space applications... no matter whether ipip is supposed to have these parameters.

ok, Then we shld reset these fields before passing them to ip_tunnels layer.

Someone please respin this to clear the fields instead, thanks!

author
#6 lore raw
Quoted 5 lines · David Miller

From: Pravin Shelar <[email protected]>

Quoted 2 lines
Quoted 1 line

ok, Then we shld reset these fields before passing them to ip_tunnels layer.

Someone please respin this to clear the fields instead, thanks!

I will send v2.

Thanks!