Skip to contentSkip to conversation

net: 6lowpan: fix reserved space for single frames

PATCH Superseded Alexander Aring 3 participants 7 messages Jul 2, 2018 – Aug 6, 2018

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 net: 6lowpan: fix reserved space for single frames

This patch fixes patch add handling to take care tail and headroom for single 6lowpan frames. We need to be sure we have a skb with the right head and tailroom for single frames. This patch do it by using skb_copy_expand() if head and tailroom is not enough allocated by upper layer.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=195059

---
 net/ieee802154/6lowpan/tx.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
net/ieee802154/6lowpan/tx.c +18 -3
index e6ff5128e61a..d0c4d220de08 100644
@@ -265,9 +265,24 @@ netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *ldev)
 	/* We must take a copy of the skb before we modify/replace the ipv6
 	 * header as the header could be used elsewhere
 	 */
-	skb = skb_unshare(skb, GFP_ATOMIC);
-	if (!skb)
-		return NET_XMIT_DROP;
+	if (unlikely(skb_headroom(skb) < ldev->needed_headroom ||
+		     skb_tailroom(skb) < ldev->needed_tailroom)) {
+		struct sk_buff *nskb;
+
+		nskb = skb_copy_expand(skb, ldev->needed_headroom,
+				       ldev->needed_tailroom, GFP_ATOMIC);
+		if (likely(skb)) {
+			consume_skb(skb);
+			skb = nskb;
+		} else {
+			kfree_skb(skb);
+			return NET_XMIT_DROP;
+		}
+	} else {
+		skb = skb_unshare(skb, GFP_ATOMIC);
+		if (!skb)
+			return NET_XMIT_DROP;
+	}
 
 	ret = lowpan_header(skb, ldev, &dgram_size, &dgram_offset);
 	if (ret < 0) {
Signature · 1 line
2.11.0
#1 lore raw

PATCH 2/2 net: mac802154: tx: expand tailroom if necessary

This patch is necessary if case of AF_PACKET or other socket interface which I am aware of it and didn't allocated the necessary room.

---
 net/mac802154/tx.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
net/mac802154/tx.c +14 -1
index 7e253455f9dd..bcd1a5e6ebf4 100644
@@ -63,8 +63,21 @@ ieee802154_tx(struct ieee802154_local *local, struct sk_buff *skb)
 	int ret;
 
 	if (!(local->hw.flags & IEEE802154_HW_TX_OMIT_CKSUM)) {
-		u16 crc = crc_ccitt(0, skb->data, skb->len);
+		struct sk_buff *nskb;
+		u16 crc;
+
+		if (unlikely(skb_tailroom(skb) < IEEE802154_FCS_LEN)) {
+			nskb = skb_copy_expand(skb, 0, IEEE802154_FCS_LEN,
+					       GFP_ATOMIC);
+			if (likely(nskb)) {
+				consume_skb(skb);
+				skb = nskb;
+			} else {
+				goto err_tx;
+			}
+		}
 
+		crc = crc_ccitt(0, skb->data, skb->len);
 		put_unaligned_le16(crc, skb_put(skb, 2));
 	}
 
Signature · 1 line
2.11.0
maintainer
#2 lore raw

Re: [PATCH wpan 2/2] net: mac802154: tx: expand tailroom if necessary

Hello.

Quoted 28 lines · Alexander Aring

This patch is necessary if case of AF_PACKET or other socket interface which I am aware of it and didn't allocated the necessary room.

---
 net/mac802154/tx.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
net/mac802154/tx.c +8 -1
index 7e253455f9dd..bcd1a5e6ebf4 100644
@@ -63,8 +63,21 @@ ieee802154_tx(struct ieee802154_local *local, struct sk_buff *skb)
 	int ret;
 
 	if (!(local->hw.flags & IEEE802154_HW_TX_OMIT_CKSUM)) {
-		u16 crc = crc_ccitt(0, skb->data, skb->len);
+		struct sk_buff *nskb;
+		u16 crc;
+
+		if (unlikely(skb_tailroom(skb) < IEEE802154_FCS_LEN)) {
+			nskb = skb_copy_expand(skb, 0, IEEE802154_FCS_LEN,
+					       GFP_ATOMIC);
+			if (likely(nskb)) {
+				consume_skb(skb);

net/mac802154/tx.c ieee802154_tx(struct ieee802154_local *local, struct sk_buff *skb) · line 83

Quoted 10 lines
net/mac802154/tx.c +6 -0
+				skb = nskb;
+			} else {
+				goto err_tx;
+			}
+		}
 
+		crc = crc_ccitt(0, skb->data, skb->len);
 		put_unaligned_le16(crc, skb_put(skb, 2));
 	}
 

This patch has been applied to the wpan-next tree and will be part of the next pull request to net-next. Thanks!

I know you submitted this for wpan instead of wpan-next, but with rc8 being out I will not submit another pull request for 4.18. Instead I added cc stable to the patch to make sure it gets picked into the stable tree once 4.18 is out.

regards
Stefan Schmidt

maintainer
#3 lore raw
In reply to Alexander Aring

Hello.

[CC David Palma and Rabi Narayan Sahoo]

Quoted 10 lines · Alexander Aring

This patch fixes patch add handling to take care tail and headroom for single 6lowpan frames. We need to be sure we have a skb with the right head and tailroom for single frames. This patch do it by using skb_copy_expand() if head and tailroom is not enough allocated by upper layer.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=195059

David, Rabi and you please test these two patches and verify that it fixes the problems you have?

regards
Stefan Schmidt

Quoted 37 lines
---
 net/ieee802154/6lowpan/tx.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
net/ieee802154/6lowpan/tx.c +18 -3
index e6ff5128e61a..d0c4d220de08 100644
@@ -265,9 +265,24 @@ netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *ldev)
 	/* We must take a copy of the skb before we modify/replace the ipv6
 	 * header as the header could be used elsewhere
 	 */
-	skb = skb_unshare(skb, GFP_ATOMIC);
-	if (!skb)
-		return NET_XMIT_DROP;
+	if (unlikely(skb_headroom(skb) < ldev->needed_headroom ||
+		     skb_tailroom(skb) < ldev->needed_tailroom)) {
+		struct sk_buff *nskb;
+
+		nskb = skb_copy_expand(skb, ldev->needed_headroom,
+				       ldev->needed_tailroom, GFP_ATOMIC);
+		if (likely(skb)) {
+			consume_skb(skb);
+			skb = nskb;
+		} else {
+			kfree_skb(skb);
+			return NET_XMIT_DROP;
+		}
+	} else {
+		skb = skb_unshare(skb, GFP_ATOMIC);
+		if (!skb)
+			return NET_XMIT_DROP;
+	}
 
 	ret = lowpan_header(skb, ldev, &dgram_size, &dgram_offset);
 	if (ret < 0) {
#4 lore raw

Hi Stefan,

Quoted 16 lines · Stefan Schmidt

Hello.

[CC David Palma and Rabi Narayan Sahoo]

Quoted 10 lines · Alexander Aring

This patch fixes patch add handling to take care tail and headroom for single 6lowpan frames. We need to be sure we have a skb with the right head and tailroom for single frames. This patch do it by using skb_copy_expand() if head and tailroom is not enough allocated by upper layer.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=195059

Quoted 6 lines

David, Rabi and you please test these two patches and verify that it fixes the problems you have?

regards
Stefan Schmidt

The patches fix the problems!

I've tested them against different packet sizes and no kernel panic.

The patches were applied in Debian's 4.9.88-1+deb9u1 x86_64 kernel, which before the patches showed the reported issue.

Thanks again to Alex for looking into it.

Cheers,

Signature · 1 line
David
Quoted 37 lines
Quoted 37 lines
---
 net/ieee802154/6lowpan/tx.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
net/ieee802154/6lowpan/tx.c +18 -3
index e6ff5128e61a..d0c4d220de08 100644
@@ -265,9 +265,24 @@ netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *ldev)
 	/* We must take a copy of the skb before we modify/replace the ipv6
 	 * header as the header could be used elsewhere
 	 */
-	skb = skb_unshare(skb, GFP_ATOMIC);
-	if (!skb)
-		return NET_XMIT_DROP;
+	if (unlikely(skb_headroom(skb) < ldev->needed_headroom ||
+		     skb_tailroom(skb) < ldev->needed_tailroom)) {
+		struct sk_buff *nskb;
+
+		nskb = skb_copy_expand(skb, ldev->needed_headroom,
+				       ldev->needed_tailroom, GFP_ATOMIC);
+		if (likely(skb)) {
+			consume_skb(skb);
+			skb = nskb;
+		} else {
+			kfree_skb(skb);
+			return NET_XMIT_DROP;
+		}
+	} else {
+		skb = skb_unshare(skb, GFP_ATOMIC);
+		if (!skb)
+			return NET_XMIT_DROP;
+	}
 
 	ret = lowpan_header(skb, ldev, &dgram_size, &dgram_offset);
 	if (ret < 0) {
maintainer
#5 lore raw

Hello David.

Quoted 22 lines · David Palma

Hi Stefan,

Quoted 19 lines · Stefan Schmidt

Hello.

[CC David Palma and Rabi Narayan Sahoo]

Quoted 10 lines · Alexander Aring

This patch fixes patch add handling to take care tail and headroom for single 6lowpan frames. We need to be sure we have a skb with the right head and tailroom for single frames. This patch do it by using skb_copy_expand() if head and tailroom is not enough allocated by upper layer.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=195059

David, Rabi and you please test these two patches and verify that it fixes the problems you have?

Quoted 7 lines
Quoted 3 lines

regards
Stefan Schmidt

The patches fix the problems!

I've tested them against different packet sizes and no kernel panic.

Thanks for confirming.

Quoted 2 lines

The patches were applied in Debian's 4.9.88-1+deb9u1 x86_64 kernel, which before the patches showed the reported issue.

I will see that I get them into the stable kernel as well. For LTS or Debian kernels you might want to poke the maintainers of them directly once this patch had hit Linux mainline.

regards
Stefan Schmidt

maintainer
#6 lore raw
In reply to Alexander Aring

Hello.

Quoted 1 line · Alexander Aring

This patch fixes patch add handling to take care tail and headroom for

The "patch add" text here is form some patch managing? Please fix this when doing the re-spin for the problem below.

Quoted 21 lines

single 6lowpan frames. We need to be sure we have a skb with the right head and tailroom for single frames. This patch do it by using skb_copy_expand() if head and tailroom is not enough allocated by upper layer.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=195059

---
 net/ieee802154/6lowpan/tx.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
net/ieee802154/6lowpan/tx.c +0 -0
index e6ff5128e61a..d0c4d220de08 100644
@@ -265,9 +265,24 @@ netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *ldev)
 	/* We must take a copy of the skb before we modify/replace the ipv6
 	 * header as the header could be used elsewhere
 	 */

net/ieee802154/6lowpan/tx.c netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *ldev) · line 274

Quoted 10 lines
net/ieee802154/6lowpan/tx.c +7 -3
-	skb = skb_unshare(skb, GFP_ATOMIC);
-	if (!skb)
-		return NET_XMIT_DROP;
+	if (unlikely(skb_headroom(skb) < ldev->needed_headroom ||
+		     skb_tailroom(skb) < ldev->needed_tailroom)) {
+		struct sk_buff *nskb;
+
+		nskb = skb_copy_expand(skb, ldev->needed_headroom,
+				       ldev->needed_tailroom, GFP_ATOMIC);
+		if (likely(skb)) {

I think you wanted to check for nskb here.

Quoted 5 lines
net/ieee802154/6lowpan/tx.c +4 -0
+			consume_skb(skb);
+			skb = nskb;
+		} else {
+			kfree_skb(skb);

net/ieee802154/6lowpan/tx.c netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *ldev) · line 288

Quoted 10 lines
net/ieee802154/6lowpan/tx.c +7 -0
+			return NET_XMIT_DROP;
+		}
+	} else {
+		skb = skb_unshare(skb, GFP_ATOMIC);
+		if (!skb)
+			return NET_XMIT_DROP;
+	}
 
 	ret = lowpan_header(skb, ldev, &dgram_size, &dgram_offset);
 	if (ret < 0) {

The rest looks fine to me.

regards
Stefan Schmidt