Skip to contentSkip to conversation

xfrm4: fix the ports decode of sctp protocol

PATCH Applied Wei Yongjun 3 participants 6 messages Jul 3, 2009 – Jul 4, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 xfrm4: fix the ports decode of sctp protocol

The SCTP pushed the skb data above the sctp chunk header, so the check of pskb_may_pull(skb, xprth + 4 - skb->data) in _decode_session4() will never return 0 because xprth + 4 - skb->data < 0, the ports decode of sctp will always fail.

---
 net/ipv4/xfrm4_policy.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
net/ipv4/xfrm4_policy.c +2 -1
index 60d918c..0071ee6 100644
@@ -136,7 +136,8 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
 		case IPPROTO_TCP:
 		case IPPROTO_SCTP:
 		case IPPROTO_DCCP:
-			if (pskb_may_pull(skb, xprth + 4 - skb->data)) {
+			if (xprth + 4 < skb->data ||
+			    pskb_may_pull(skb, xprth + 4 - skb->data)) {
 				__be16 *ports = (__be16 *)xprth;
 
 				fl->fl_ip_sport = ports[!!reverse];
Signature · 1 line
1.6.2.2
#1 lore raw

PATCH 2/2 xfrm6: fix the proto and ports decode of sctp protocol

The SCTP pushed the skb above the sctp chunk header, so the check of pskb_may_pull(skb, nh + offset + 1 - skb->data) in _decode_session6() will never return 0 and the ports decode of sctp will always fail. (nh + offset + 1 - skb->data < 0)

---
 net/ipv6/xfrm6_policy.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
net/ipv6/xfrm6_policy.c +4 -2
index b4b16a4..3a3c677 100644
@@ -157,7 +157,8 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
 	ipv6_addr_copy(&fl->fl6_dst, reverse ? &hdr->saddr : &hdr->daddr);
 	ipv6_addr_copy(&fl->fl6_src, reverse ? &hdr->daddr : &hdr->saddr);
 
-	while (pskb_may_pull(skb, nh + offset + 1 - skb->data)) {
+	while (nh + offset + 1 < skb->data ||
+	       pskb_may_pull(skb, nh + offset + 1 - skb->data)) {
 		nh = skb_network_header(skb);
 		exthdr = (struct ipv6_opt_hdr *)(nh + offset);
 
@@ -177,7 +178,8 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
 		case IPPROTO_TCP:
 		case IPPROTO_SCTP:
 		case IPPROTO_DCCP:
-			if (!onlyproto && pskb_may_pull(skb, nh + offset + 4 - skb->data)) {
+			if (!onlyproto && (nh + offset + 4 < skb->data ||
+			     pskb_may_pull(skb, nh + offset + 4 - skb->data))) {
 				__be16 *ports = (__be16 *)exthdr;
 
 				fl->fl_ip_sport = ports[!!reverse];
Signature · 1 line
1.6.2.2
maintainer Acked-by on v1 1/2
#4 lore raw
In reply to Wei Yongjun
Quoted 6 lines · Wei Yongjun

The SCTP pushed the skb data above the sctp chunk header, so the check of pskb_may_pull(skb, xprth + 4 - skb->data) in _decode_session4() will never return 0 because xprth + 4 - skb->data < 0, the ports decode of sctp will always fail.

Longer term I wonder if we can move this stuff into the protocol code, i.e., before they call xfrm_policy_check.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
maintainer Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] xfrm6: fix the proto and ports decode of sctp protocol

In reply to Wei Yongjun
Quoted 6 lines · Wei Yongjun

The SCTP pushed the skb above the sctp chunk header, so the check of pskb_may_pull(skb, nh + offset + 1 - skb->data) in _decode_session6() will never return 0 and the ports decode of sctp will always fail. (nh + offset + 1 - skb->data < 0)

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
maintainer Applied
#5 lore raw
In reply to Herbert Xu

From: Herbert Xu <[email protected]>
Date: Fri, 3 Jul 2009 11:48:49 +0800

Quoted 9 lines · Wei Yongjun
Quoted 6 lines

The SCTP pushed the skb data above the sctp chunk header, so the check of pskb_may_pull(skb, xprth + 4 - skb->data) in _decode_session4() will never return 0 because xprth + 4 - skb->data < 0, the ports decode of sctp will always fail.

Applied.

Quoted 2 lines

Longer term I wonder if we can move this stuff into the protocol code, i.e., before they call xfrm_policy_check.

That ought to work.

maintainer Applied
#3 lore raw

Re: [PATCH 2/2] xfrm6: fix the proto and ports decode of sctp protocol

In reply to Herbert Xu

From: Herbert Xu <[email protected]>
Date: Fri, 3 Jul 2009 11:49:17 +0800

Quoted 9 lines · Wei Yongjun
Quoted 6 lines

The SCTP pushed the skb above the sctp chunk header, so the check of pskb_may_pull(skb, nh + offset + 1 - skb->data) in _decode_session6() will never return 0 and the ports decode of sctp will always fail. (nh + offset + 1 - skb->data < 0)

Applied.