Skip to contentSkip to conversation

Leak in ipv6_gso_segment()?

DISCUSSION Ben Hutchings 3 participants 5 messages May 31, 2017 – Jun 5, 2017

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

If I'm not mistaken, ipv6_gso_segment() now leaks segs if ip6_find_1stfragopt() fails. I'm not sure whether the fix would be as simple as adding a kfree_skb(segs) or whether more complex cleanup is needed.

Ben.

Signature · 3 lines
Ben Hutchings
Lowery's Law:
        If it jams, force it. If it breaks, it needed replacing anyway.
maintainer
#1 lore raw

From: Ben Hutchings <[email protected]>
Date: Wed, 31 May 2017 13:26:02 +0100

Quoted 4 lines

If I'm not mistaken, ipv6_gso_segment() now leaks segs if ip6_find_1stfragopt() fails. I'm not sure whether the fix would be as simple as adding a kfree_skb(segs) or whether more complex cleanup is needed.

I think we need to use kfree_skb_list(), like the following.

Can someone please audit and review this for me? We need to get this to -stable.

Thanks.

net/ipv6/ip6_offload.c +3 -1
index 280268f..cdb3728 100644
@@ -116,8 +116,10 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb,
 
 		if (udpfrag) {
 			int err = ip6_find_1stfragopt(skb, &prevhdr);
-			if (err < 0)
+			if (err < 0) {
+				kfree_skb_list(segs);
 				return ERR_PTR(err);
+			}
 			fptr = (struct frag_hdr *)((u8 *)ipv6h + err);
 			fptr->frag_off = htons(offset);
 			if (skb->next)
#2 lore raw
Quoted 9 lines · David Miller

From: Ben Hutchings <[email protected]>
Date: Wed, 31 May 2017 13:26:02 +0100

Quoted 4 lines

If I'm not mistaken, ipv6_gso_segment() now leaks segs if ip6_find_1stfragopt() fails. I'm not sure whether the fix would be as simple as adding a kfree_skb(segs) or whether more complex cleanup is needed.

I think we need to use kfree_skb_list(), like the following.

I think this is problematic as well. ipv6_gso_segment could previously return errors, in which case the caller uses kfree_skb (ex validate_xmit_skb() -> skb_gso_segment -> ... callbacks.gso_segment()). Having the kfree_skb_list here would cause a double free if I'm reading this correctly.

My first guess was going to be skb_gso_error_unwind(), but I'm still trying to understand that code...

Sorry again for the fallout from this bug fix. This is my first time down this code path and I clearly didn't understand it fully :/

Quoted 21 lines

Can someone please audit and review this for me? We need to get this to -stable.

Thanks.

net/ipv6/ip6_offload.c +3 -1
index 280268f..cdb3728 100644
@@ -116,8 +116,10 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb,
 
                if (udpfrag) {
                        int err = ip6_find_1stfragopt(skb, &prevhdr);
-                       if (err < 0)
+                       if (err < 0) {
+                               kfree_skb_list(segs);
                                return ERR_PTR(err);
+                       }
                        fptr = (struct frag_hdr *)((u8 *)ipv6h + err);
                        fptr->frag_off = htons(offset);
                        if (skb->next)
#3 lore raw
Quoted 16 lines · Craig Gallek
Quoted 9 lines · David Miller

From: Ben Hutchings <[email protected]>
Date: Wed, 31 May 2017 13:26:02 +0100

Quoted 4 lines

If I'm not mistaken, ipv6_gso_segment() now leaks segs if ip6_find_1stfragopt() fails. I'm not sure whether the fix would be as simple as adding a kfree_skb(segs) or whether more complex cleanup is needed.

I think we need to use kfree_skb_list(), like the following.

I think this is problematic as well. ipv6_gso_segment could previously return errors, in which case the caller uses kfree_skb (ex validate_xmit_skb() -> skb_gso_segment -> ... callbacks.gso_segment()). Having the kfree_skb_list here would cause a double free if I'm reading this correctly.

Quoted 5 lines

My first guess was going to be skb_gso_error_unwind(), but I'm still trying to understand that code...

Sorry again for the fallout from this bug fix. This is my first time down this code path and I clearly didn't understand it fully :/

Ok, I take it back. I believe your kfree_skb_list suggestion is correct.

I was assuming that skb_segment consumed the original skb upon successful segmentation. It does not. This is exactly why validate_xmit_skb calls consume_skb when segments are returned. Further, there is at least one existing example of kfree_skb_list in a similar post-semgent cleanup path (esp6_gso_segment).

maintainer
#4 lore raw

From: Craig Gallek <[email protected]>
Date: Fri, 2 Jun 2017 15:27:41 -0400

Quoted 23 lines · Craig Gallek
Quoted 16 lines · David Miller
Quoted 9 lines

From: Ben Hutchings <[email protected]>
Date: Wed, 31 May 2017 13:26:02 +0100

Quoted 4 lines

If I'm not mistaken, ipv6_gso_segment() now leaks segs if ip6_find_1stfragopt() fails. I'm not sure whether the fix would be as simple as adding a kfree_skb(segs) or whether more complex cleanup is needed.

I think we need to use kfree_skb_list(), like the following.

I think this is problematic as well. ipv6_gso_segment could previously return errors, in which case the caller uses kfree_skb (ex validate_xmit_skb() -> skb_gso_segment -> ... callbacks.gso_segment()). Having the kfree_skb_list here would cause a double free if I'm reading this correctly.

Quoted 5 lines

My first guess was going to be skb_gso_error_unwind(), but I'm still trying to understand that code...

Sorry again for the fallout from this bug fix. This is my first time down this code path and I clearly didn't understand it fully :/

Quoted 7 lines

Ok, I take it back. I believe your kfree_skb_list suggestion is correct.

I was assuming that skb_segment consumed the original skb upon successful segmentation. It does not. This is exactly why validate_xmit_skb calls consume_skb when segments are returned. Further, there is at least one existing example of kfree_skb_list in a similar post-semgent cleanup path (esp6_gso_segment).

Great, thanks for reviewing. I've pushed this into 'net' and queued it up for -stable.