Browse Source

Cipso: cipso_v4_optptr enter infinite loop

in for(),if((optlen > 0) && (optptr[1] == 0)), enter infinite loop.

Test: receive a packet which the ip length > 20 and the first byte of ip option is 0, produce this issue

Signed-off-by: yujuan.qi <yujuan.qi@mediatek.com>
Acked-by: Paul Moore <paul@paul-moore.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
yujuan.qi 8 years ago
parent
commit
40413955ee
1 changed files with 10 additions and 2 deletions
  1. 10 2
      net/ipv4/cipso_ipv4.c

+ 10 - 2
net/ipv4/cipso_ipv4.c

@@ -1523,9 +1523,17 @@ unsigned char *cipso_v4_optptr(const struct sk_buff *skb)
 	int taglen;
 	int taglen;
 
 
 	for (optlen = iph->ihl*4 - sizeof(struct iphdr); optlen > 0; ) {
 	for (optlen = iph->ihl*4 - sizeof(struct iphdr); optlen > 0; ) {
-		if (optptr[0] == IPOPT_CIPSO)
+		switch (optptr[0]) {
+		case IPOPT_CIPSO:
 			return optptr;
 			return optptr;
-		taglen = optptr[1];
+		case IPOPT_END:
+			return NULL;
+		case IPOPT_NOOP:
+			taglen = 1;
+			break;
+		default:
+			taglen = optptr[1];
+		}
 		optlen -= taglen;
 		optlen -= taglen;
 		optptr += taglen;
 		optptr += taglen;
 	}
 	}