All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH wpan 1/2] net: 6lowpan: fix reserved space for single frames
@ 2018-07-02 20:32 Alexander Aring
  2018-07-02 20:32 ` [PATCH wpan 2/2] net: mac802154: tx: expand tailroom if necessary Alexander Aring
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Alexander Aring @ 2018-07-02 20:32 UTC (permalink / raw)
  To: stefan; +Cc: linux-wpan, netdev, kernel, 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
Reported-by: David Palma <david.palma@ntnu.no>
Reported-by: Rabi Narayan Sahoo <rabinarayans0828@gmail.com>
Signed-off-by: Alexander Aring <aring@mojatatu.com>
---
 net/ieee802154/6lowpan/tx.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/net/ieee802154/6lowpan/tx.c b/net/ieee802154/6lowpan/tx.c
index e6ff5128e61a..d0c4d220de08 100644
--- a/net/ieee802154/6lowpan/tx.c
+++ b/net/ieee802154/6lowpan/tx.c
@@ -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) {
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH wpan 2/2] net: mac802154: tx: expand tailroom if necessary
  2018-07-02 20:32 [PATCH wpan 1/2] net: 6lowpan: fix reserved space for single frames Alexander Aring
@ 2018-07-02 20:32 ` Alexander Aring
  2018-08-06  9:26   ` Stefan Schmidt
  2018-07-05 11:16 ` [PATCH wpan 1/2] net: 6lowpan: fix reserved space for single frames Stefan Schmidt
  2018-07-06 10:06 ` Stefan Schmidt
  2 siblings, 1 reply; 7+ messages in thread
From: Alexander Aring @ 2018-07-02 20:32 UTC (permalink / raw)
  To: stefan; +Cc: linux-wpan, netdev, kernel, 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.

Reported-by: David Palma <david.palma@ntnu.no>
Reported-by: Rabi Narayan Sahoo <rabinarayans0828@gmail.com>
Signed-off-by: Alexander Aring <aring@mojatatu.com>
---
 net/mac802154/tx.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/net/mac802154/tx.c b/net/mac802154/tx.c
index 7e253455f9dd..bcd1a5e6ebf4 100644
--- a/net/mac802154/tx.c
+++ b/net/mac802154/tx.c
@@ -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));
 	}
 
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH wpan 1/2] net: 6lowpan: fix reserved space for single frames
  2018-07-02 20:32 [PATCH wpan 1/2] net: 6lowpan: fix reserved space for single frames Alexander Aring
  2018-07-02 20:32 ` [PATCH wpan 2/2] net: mac802154: tx: expand tailroom if necessary Alexander Aring
@ 2018-07-05 11:16 ` Stefan Schmidt
  2018-07-06  7:54   ` David Palma
  2018-07-06 10:06 ` Stefan Schmidt
  2 siblings, 1 reply; 7+ messages in thread
From: Stefan Schmidt @ 2018-07-05 11:16 UTC (permalink / raw)
  To: Alexander Aring, stefan
  Cc: linux-wpan, netdev, kernel, David Palma, Rabi Narayan Sahoo

Hello.

[CC David Palma and Rabi Narayan Sahoo]

On 02.07.2018 22:32, Alexander Aring wrote:
> 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
> Reported-by: David Palma <david.palma@ntnu.no>
> Reported-by: Rabi Narayan Sahoo <rabinarayans0828@gmail.com>
> Signed-off-by: Alexander Aring <aring@mojatatu.com>

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

regards
Stefan Schmidt

> ---
>  net/ieee802154/6lowpan/tx.c | 21 ++++++++++++++++++---
>  1 file changed, 18 insertions(+), 3 deletions(-)
> 
> diff --git a/net/ieee802154/6lowpan/tx.c b/net/ieee802154/6lowpan/tx.c
> index e6ff5128e61a..d0c4d220de08 100644
> --- a/net/ieee802154/6lowpan/tx.c
> +++ b/net/ieee802154/6lowpan/tx.c
> @@ -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) {
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH wpan 1/2] net: 6lowpan: fix reserved space for single frames
  2018-07-05 11:16 ` [PATCH wpan 1/2] net: 6lowpan: fix reserved space for single frames Stefan Schmidt
@ 2018-07-06  7:54   ` David Palma
  2018-07-06  8:07     ` Stefan Schmidt
  0 siblings, 1 reply; 7+ messages in thread
From: David Palma @ 2018-07-06  7:54 UTC (permalink / raw)
  To: Stefan Schmidt, Alexander Aring, stefan
  Cc: linux-wpan, netdev, kernel, Rabi Narayan Sahoo


[-- Attachment #1.1: Type: text/plain, Size: 2426 bytes --]

Hi Stefan,

On 05/07/18 13:16, Stefan Schmidt wrote:
> Hello.
> 
> [CC David Palma and Rabi Narayan Sahoo]
> 
> On 02.07.2018 22:32, Alexander Aring wrote:
>> 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
>> Reported-by: David Palma <david.palma@ntnu.no>
>> Reported-by: Rabi Narayan Sahoo <rabinarayans0828@gmail.com>
>> Signed-off-by: Alexander Aring <aring@mojatatu.com>
> 
> 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,
-- 
David

>> ---
>>  net/ieee802154/6lowpan/tx.c | 21 ++++++++++++++++++---
>>  1 file changed, 18 insertions(+), 3 deletions(-)
>>
>> diff --git a/net/ieee802154/6lowpan/tx.c b/net/ieee802154/6lowpan/tx.c
>> index e6ff5128e61a..d0c4d220de08 100644
>> --- a/net/ieee802154/6lowpan/tx.c
>> +++ b/net/ieee802154/6lowpan/tx.c
>> @@ -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) {
>>



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH wpan 1/2] net: 6lowpan: fix reserved space for single frames
  2018-07-06  7:54   ` David Palma
@ 2018-07-06  8:07     ` Stefan Schmidt
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Schmidt @ 2018-07-06  8:07 UTC (permalink / raw)
  To: David Palma, Alexander Aring, stefan
  Cc: linux-wpan, netdev, kernel, Rabi Narayan Sahoo

Hello David.

On 06.07.2018 09:54, David Palma wrote:
> Hi Stefan,
> 
> On 05/07/18 13:16, Stefan Schmidt wrote:
>> Hello.
>>
>> [CC David Palma and Rabi Narayan Sahoo]
>>
>> On 02.07.2018 22:32, Alexander Aring wrote:
>>> 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
>>> Reported-by: David Palma <david.palma@ntnu.no>
>>> Reported-by: Rabi Narayan Sahoo <rabinarayans0828@gmail.com>
>>> Signed-off-by: Alexander Aring <aring@mojatatu.com>
>>
>> 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.

Thanks for confirming.

> 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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH wpan 1/2] net: 6lowpan: fix reserved space for single frames
  2018-07-02 20:32 [PATCH wpan 1/2] net: 6lowpan: fix reserved space for single frames Alexander Aring
  2018-07-02 20:32 ` [PATCH wpan 2/2] net: mac802154: tx: expand tailroom if necessary Alexander Aring
  2018-07-05 11:16 ` [PATCH wpan 1/2] net: 6lowpan: fix reserved space for single frames Stefan Schmidt
@ 2018-07-06 10:06 ` Stefan Schmidt
  2 siblings, 0 replies; 7+ messages in thread
From: Stefan Schmidt @ 2018-07-06 10:06 UTC (permalink / raw)
  To: Alexander Aring, stefan; +Cc: linux-wpan, netdev, kernel

Hello.

On 02.07.2018 22:32, Alexander Aring wrote:
> 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.

> 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
> Reported-by: David Palma <david.palma@ntnu.no>
> Reported-by: Rabi Narayan Sahoo <rabinarayans0828@gmail.com>
> Signed-off-by: Alexander Aring <aring@mojatatu.com>
> ---
>  net/ieee802154/6lowpan/tx.c | 21 ++++++++++++++++++---
>  1 file changed, 18 insertions(+), 3 deletions(-)
> 
> diff --git a/net/ieee802154/6lowpan/tx.c b/net/ieee802154/6lowpan/tx.c
> index e6ff5128e61a..d0c4d220de08 100644
> --- a/net/ieee802154/6lowpan/tx.c
> +++ b/net/ieee802154/6lowpan/tx.c
> @@ -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)) {

I think you wanted to check for nskb here.

> +			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) {
> 

The rest looks fine to me.

regards
Stefan Schmidt

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH wpan 2/2] net: mac802154: tx: expand tailroom if necessary
  2018-07-02 20:32 ` [PATCH wpan 2/2] net: mac802154: tx: expand tailroom if necessary Alexander Aring
@ 2018-08-06  9:26   ` Stefan Schmidt
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Schmidt @ 2018-08-06  9:26 UTC (permalink / raw)
  To: Alexander Aring, stefan; +Cc: linux-wpan, netdev, kernel

Hello.

On 07/02/2018 10:32 PM, Alexander Aring wrote:
> 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.
> 
> Reported-by: David Palma <david.palma@ntnu.no>
> Reported-by: Rabi Narayan Sahoo <rabinarayans0828@gmail.com>
> Signed-off-by: Alexander Aring <aring@mojatatu.com>
> ---
>  net/mac802154/tx.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/net/mac802154/tx.c b/net/mac802154/tx.c
> index 7e253455f9dd..bcd1a5e6ebf4 100644
> --- a/net/mac802154/tx.c
> +++ b/net/mac802154/tx.c
> @@ -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));
>  	}
>  
> 

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-08-06 11:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-02 20:32 [PATCH wpan 1/2] net: 6lowpan: fix reserved space for single frames Alexander Aring
2018-07-02 20:32 ` [PATCH wpan 2/2] net: mac802154: tx: expand tailroom if necessary Alexander Aring
2018-08-06  9:26   ` Stefan Schmidt
2018-07-05 11:16 ` [PATCH wpan 1/2] net: 6lowpan: fix reserved space for single frames Stefan Schmidt
2018-07-06  7:54   ` David Palma
2018-07-06  8:07     ` Stefan Schmidt
2018-07-06 10:06 ` Stefan Schmidt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.