Skip to contentSkip to conversation

xfrm6: Fix ICMPv6 and MH header checks in _decode_session6

PATCH In review Mathias Krause 2 participants 2 messages Sep 11, 2015 – Sep 14, 2015

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

PATCH 1/1 xfrm6: Fix ICMPv6 and MH header checks in _decode_session6

From: Mathias Krause <[email protected]>

Ensure there's enough data left prior calling pskb_may_pull(). If skb->data was already advanced, we'll call pskb_may_pull() with a negative value converted to unsigned int -- leading to a huge positive value. That won't matter in practice as pskb_may_pull() will likely fail in this case, but it leads to underflow reports on kernels handling such kind of over-/underflows, e.g. a PaX enabled kernel instrumented with the size_overflow plugin.

---
 net/ipv6/xfrm6_policy.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
net/ipv6/xfrm6_policy.c +4 -2
index ed0583c1b9fc..c988c3f033cf 100644
@@ -174,7 +174,8 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
 			return;
 
 		case IPPROTO_ICMPV6:
-			if (!onlyproto && pskb_may_pull(skb, nh + offset + 2 - skb->data)) {
+			if (!onlyproto && (nh + offset + 2 < skb->data ||
+			    pskb_may_pull(skb, nh + offset + 2 - skb->data))) {
 				u8 *icmp;
 
 				nh = skb_network_header(skb);
@@ -188,7 +189,8 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
 #if IS_ENABLED(CONFIG_IPV6_MIP6)
 		case IPPROTO_MH:
 			offset += ipv6_optlen(exthdr);
-			if (!onlyproto && pskb_may_pull(skb, nh + offset + 3 - skb->data)) {
+			if (!onlyproto && (nh + offset + 3 < skb->data ||
+			    pskb_may_pull(skb, nh + offset + 3 - skb->data))) {
 				struct ip6_mh *mh;
 
 				nh = skb_network_header(skb);
Signature · 1 line
2.1.4
maintainer
#1 lore raw
Quoted 10 lines · Mathias Krause

From: Mathias Krause <[email protected]>

Ensure there's enough data left prior calling pskb_may_pull(). If skb->data was already advanced, we'll call pskb_may_pull() with a negative value converted to unsigned int -- leading to a huge positive value. That won't matter in practice as pskb_may_pull() will likely fail in this case, but it leads to underflow reports on kernels handling such kind of over-/underflows, e.g. a PaX enabled kernel instrumented with the size_overflow plugin.

Quoted 4 lines

Skipping upper layer informations due to a wrong length calculation, may also leed to incorrect policy lookups. Patch applied to the ipsec tree, thanks!