Skip to contentSkip to conversation

xfrm6: call kfree_skb when skb is toobig

PATCH Superseded Thadeu Lima de Souza Cascardo 3 participants 7 messages Aug 30, 2018 – Sep 3, 2018

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

PATCH 1/2 xfrm6: call kfree_skb when skb is toobig

After commit d6990976af7c5d8f55903bfb4289b6fb030bf754 ("vti6: fix PMTU caching and reporting on xmit"), some too big skbs might be potentially passed down to __xfrm6_output, causing it to fail to transmit but not free the skb, causing a leak of skb, and consequentially a leak of dst references.

After running pmtu.sh, that shows as failure to unregister devices in a namespace:

[  311.397671] unregister_netdevice: waiting for veth_b to become free. Usage count = 1

The fix is to call kfree_skb in case of transmit failures.

---
 net/ipv6/xfrm6_output.c | 2 ++
 1 file changed, 2 insertions(+)
net/ipv6/xfrm6_output.c +2 -0
index 5959ce9620eb..6a74080005cf 100644
@@ -170,9 +170,11 @@ static int __xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
 
 	if (toobig && xfrm6_local_dontfrag(skb)) {
 		xfrm6_local_rxpmtu(skb, mtu);
+		kfree_skb(skb);
 		return -EMSGSIZE;
 	} else if (!skb->ignore_df && toobig && skb->sk) {
 		xfrm_local_error(skb, mtu);
+		kfree_skb(skb);
 		return -EMSGSIZE;
 	}
 
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/2 vti6: do not check for ignore_df in order to update pmtu

Before commit d6990976af7c5d8f55903bfb4289b6fb030bf754 ("vti6: fix PMTU caching and reporting on xmit"), skb was scrubbed before checking for ignore_df. The scrubbing meant ignore_df was false, making the check irrelevant. Now that the scrubbing happens after that, some packets might fail the checking and dst will not have its pmtu updated.

Not only that, but too big skb will be potentially passed down to __xfrm6_output, causing it to fail to transmit but not free the skb, causing a leak of skb, and consequentially a leak of dst references.

After running pmtu.sh, that shows as failure to unregister devices in a namespace:

[  311.397671] unregister_netdevice: waiting for veth_b to become free. Usage count = 1
---
 net/ipv6/ip6_vti.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/ip6_vti.c +1 -1
index c72ae3a4fe09..fbd3752ea587 100644
@@ -481,7 +481,7 @@ vti6_xmit(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)
 	}
 
 	mtu = dst_mtu(dst);
-	if (!skb->ignore_df && skb->len > mtu) {
+	if (skb->len > mtu) {
 		skb_dst_update_pmtu(skb, mtu);
 
 		if (skb->protocol == htons(ETH_P_IPV6)) {
Signature · 1 line
2.17.1
maintainer
#2 lore raw

Re: [PATCH 2/2] vti6: do not check for ignore_df in order to update pmtu

Quoted 24 lines · Thadeu Lima de Souza Cascardo

Before commit d6990976af7c5d8f55903bfb4289b6fb030bf754 ("vti6: fix PMTU caching and reporting on xmit"), skb was scrubbed before checking for ignore_df. The scrubbing meant ignore_df was false, making the check irrelevant. Now that the scrubbing happens after that, some packets might fail the checking and dst will not have its pmtu updated.

Not only that, but too big skb will be potentially passed down to __xfrm6_output, causing it to fail to transmit but not free the skb, causing a leak of skb, and consequentially a leak of dst references.

After running pmtu.sh, that shows as failure to unregister devices in a namespace:

[  311.397671] unregister_netdevice: waiting for veth_b to become free. Usage count = 1
---
 net/ipv6/ip6_vti.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/ip6_vti.c +0 -0
index c72ae3a4fe09..fbd3752ea587 100644

net/ipv6/ip6_vti.c vti6_xmit(struct sk_buff *skb, struct net_device *dev, struct flowi *fl) · line 485

Quoted 6 lines
net/ipv6/ip6_vti.c +1 -1
@@ -481,7 +481,7 @@ vti6_xmit(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)
 	}
 
 	mtu = dst_mtu(dst);
-	if (!skb->ignore_df && skb->len > mtu) {
+	if (skb->len > mtu) {
 		skb_dst_update_pmtu(skb, mtu);

The very same patch went already to the net tree two day ago:

commit 9f2895461439fda2801a7906fb4c5fb3dbb37a0a
vti6: remove !skb->ignore_df check from vti6_xmit()

Reviewed-by on v1 1/2
#3 lore raw
In reply to Thadeu Lima de Souza Cascardo
Quoted 5 lines · Thadeu Lima de Souza Cascardo

After commit d6990976af7c5d8f55903bfb4289b6fb030bf754 ("vti6: fix PMTU caching and reporting on xmit"), some too big skbs might be potentially passed down to __xfrm6_output, causing it to fail to transmit but not free the skb, causing a leak of skb, and consequentially a leak of dst references.

Quoted 7 lines

After running pmtu.sh, that shows as failure to unregister devices in a namespace:

[  311.397671] unregister_netdevice: waiting for veth_b to become free. Usage count = 1

The fix is to call kfree_skb in case of transmit failures.

I was about to post the same patch. Arguably, the commit introducing this bug is the one that added those "return -EMSGSIZE" to __xfrm6_output without freeing.

Either way, it's missing a Fixes: tag, which should be one of those, or both:

Fixes d6990976af7c ("vti6: fix PMTU caching and reporting on xmit")
Fixes dd767856a36e ("xfrm6: Don't call icmpv6_send on local error")
Signature · 1 line
Sabrina
maintainer
#4 lore raw
Quoted 6 lines · Sabrina Dubroca
Quoted 5 lines · Thadeu Lima de Souza Cascardo

After commit d6990976af7c5d8f55903bfb4289b6fb030bf754 ("vti6: fix PMTU caching and reporting on xmit"), some too big skbs might be potentially passed down to __xfrm6_output, causing it to fail to transmit but not free the skb, causing a leak of skb, and consequentially a leak of dst references.

Quoted 7 lines
Quoted 7 lines

After running pmtu.sh, that shows as failure to unregister devices in a namespace:

[  311.397671] unregister_netdevice: waiting for veth_b to become free. Usage count = 1

The fix is to call kfree_skb in case of transmit failures.

Good catch!

Quoted 11 lines

I was about to post the same patch. Arguably, the commit introducing this bug is the one that added those "return -EMSGSIZE" to __xfrm6_output without freeing.

Either way, it's missing a Fixes: tag, which should be one of those, or both:

Fixes d6990976af7c ("vti6: fix PMTU caching and reporting on xmit")
Fixes dd767856a36e ("xfrm6: Don't call icmpv6_send on local error")

This bug can be triggered even without vti6, so the correct Fixes tag would be the latter.

Thadeu, please resend this one with the Fixes tag.

Thanks!

#5 lore raw

PATCH v2 1/1 xfrm6: call kfree_skb when skb is toobig

In reply to Thadeu Lima de Souza Cascardo

After commit d6990976af7c5d8f55903bfb4289b6fb030bf754 ("vti6: fix PMTU caching and reporting on xmit"), some too big skbs might be potentially passed down to __xfrm6_output, causing it to fail to transmit but not free the skb, causing a leak of skb, and consequentially a leak of dst references.

After running pmtu.sh, that shows as failure to unregister devices in a namespace:

[  311.397671] unregister_netdevice: waiting for veth_b to become free. Usage count = 1

The fix is to call kfree_skb in case of transmit failures.

Fixes dd767856a36e ("xfrm6: Don't call icmpv6_send on local error")
---
 net/ipv6/xfrm6_output.c | 2 ++
 1 file changed, 2 insertions(+)
net/ipv6/xfrm6_output.c +2 -0
index 5959ce9620eb..6a74080005cf 100644
@@ -170,9 +170,11 @@ static int __xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
 
 	if (toobig && xfrm6_local_dontfrag(skb)) {
 		xfrm6_local_rxpmtu(skb, mtu);
+		kfree_skb(skb);
 		return -EMSGSIZE;
 	} else if (!skb->ignore_df && toobig && skb->sk) {
 		xfrm_local_error(skb, mtu);
+		kfree_skb(skb);
 		return -EMSGSIZE;
 	}
 
Signature · 1 line
2.17.1
maintainer Applied
#6 lore raw
Quoted 7 lines · Thadeu Lima de Souza Cascardo

After commit d6990976af7c5d8f55903bfb4289b6fb030bf754 ("vti6: fix PMTU caching and reporting on xmit"), some too big skbs might be potentially passed down to __xfrm6_output, causing it to fail to transmit but not free the skb, causing a leak of skb, and consequentially a leak of dst references.

After running pmtu.sh, that shows as failure to unregister devices in a namespace:

Quoted 7 lines
[  311.397671] unregister_netdevice: waiting for veth_b to become free. Usage count = 1

The fix is to call kfree_skb in case of transmit failures.

Fixes dd767856a36e ("xfrm6: Don't call icmpv6_send on local error")

Applied, thanks a lot!