Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1637429 > unrolled thread

[PATCH V2 0/1] net: cdc_ncm: Fix TX zero padding

Started byJim Baxter <jim_baxter@mentor.com>
First post2017-05-08 15:00 +0200
Last post2017-05-08 22:10 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH V2 0/1] net: cdc_ncm: Fix TX zero padding Jim Baxter <jim_baxter@mentor.com> - 2017-05-08 15:00 +0200
    [PATCH V2 1/1] net: cdc_ncm: Fix TX zero padding Jim Baxter <jim_baxter@mentor.com> - 2017-05-08 15:00 +0200
      Re: [PATCH V2 1/1] net: cdc_ncm: Fix TX zero padding David Miller <davem@davemloft.net> - 2017-05-08 22:10 +0200

#1637429 — [PATCH V2 0/1] net: cdc_ncm: Fix TX zero padding

FromJim Baxter <jim_baxter@mentor.com>
Date2017-05-08 15:00 +0200
Subject[PATCH V2 0/1] net: cdc_ncm: Fix TX zero padding
Message-ID<tEQqB-434-1@gated-at.bofh.it>
Analysis
--------

The zero padding that is added to NTB's does not zero
the memory correctly.
This happens because the skb_put called within the memset in
the line:
memset(skb_put(skb_out, ctx->tx_max - skb_out->len),
       0, ctx->tx_max - skb_out->len);
causes the value of skb_out->len to be modified during
the two uses of it within the above line.
This causes non-zeroed data at the end of skb_out.

This issue was found when connecting between an ARM
Sabre SD Host platform and a test box that was
dropping the NDP's due to the non zeroed memory being
identified as an error.

Solution
--------

To resolve this I have cached the value of
ctx->tx_max - skb_out->len before the memset operation.

----

V1: Sent to linux-use for review.
V2: Added netdev mailing list as it was missed for V1.

Jim Baxter (1):
  net: cdc_ncm: Fix TX zero padding

 drivers/net/usb/cdc_ncm.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

-- 
1.9.1

[toc] | [next] | [standalone]


#1637431 — [PATCH V2 1/1] net: cdc_ncm: Fix TX zero padding

FromJim Baxter <jim_baxter@mentor.com>
Date2017-05-08 15:00 +0200
Subject[PATCH V2 1/1] net: cdc_ncm: Fix TX zero padding
Message-ID<tEQqB-434-13@gated-at.bofh.it>
In reply to#1637429
The zero padding that is added to NTB's does
not zero the memory correctly.
This is because the skb_put modifies the value
of skb_out->len which results in the memset
command not setting any memory to zero as
(ctx->tx_max - skb_out->len) == 0.

I have resolved this by storing the size of
the memory to be zeroed before the skb_put
and using this in the memset call.

Signed-off-by: Jim Baxter <jim_baxter@mentor.com>
Reviewed-by: Bjørn Mork <bjorn@mork.no>
---

V1: Sent to linux-use for review.
V2: Added netdev mailing list as it was missed for V1.

 drivers/net/usb/cdc_ncm.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index f317984..e2a48d7 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -1087,6 +1087,7 @@ struct sk_buff *
 	u16 n = 0, index, ndplen;
 	u8 ready2send = 0;
 	u32 delayed_ndp_size;
+	size_t padding_count;
 
 	/* When our NDP gets written in cdc_ncm_ndp(), then skb_out->len gets updated
 	 * accordingly. Otherwise, we should check here.
@@ -1243,11 +1244,13 @@ struct sk_buff *
 	 * a ZLP after full sized NTBs.
 	 */
 	if (!(dev->driver_info->flags & FLAG_SEND_ZLP) &&
-	    skb_out->len > ctx->min_tx_pkt)
-		memset(skb_put(skb_out, ctx->tx_max - skb_out->len), 0,
-		       ctx->tx_max - skb_out->len);
-	else if (skb_out->len < ctx->tx_max && (skb_out->len % dev->maxpacket) == 0)
+	    skb_out->len > ctx->min_tx_pkt) {
+		padding_count = ctx->tx_max - skb_out->len;
+		memset(skb_put(skb_out, padding_count), 0, padding_count);
+	} else if (skb_out->len < ctx->tx_max &&
+		   (skb_out->len % dev->maxpacket) == 0) {
 		*skb_put(skb_out, 1) = 0;	/* force short packet */
+	}
 
 	/* set final frame length */
 	nth16 = (struct usb_cdc_ncm_nth16 *)skb_out->data;
-- 
1.9.1

[toc] | [prev] | [next] | [standalone]


#1637688 — Re: [PATCH V2 1/1] net: cdc_ncm: Fix TX zero padding

FromDavid Miller <davem@davemloft.net>
Date2017-05-08 22:10 +0200
SubjectRe: [PATCH V2 1/1] net: cdc_ncm: Fix TX zero padding
Message-ID<tEX8J-5q-5@gated-at.bofh.it>
In reply to#1637431
From: Jim Baxter <jim_baxter@mentor.com>
Date: Mon, 8 May 2017 13:49:57 +0100

> The zero padding that is added to NTB's does
> not zero the memory correctly.
> This is because the skb_put modifies the value
> of skb_out->len which results in the memset
> command not setting any memory to zero as
> (ctx->tx_max - skb_out->len) == 0.
> 
> I have resolved this by storing the size of
> the memory to be zeroed before the skb_put
> and using this in the memset call.
> 
> Signed-off-by: Jim Baxter <jim_baxter@mentor.com>
> Reviewed-by: Bjørn Mork <bjorn@mork.no>

Applied, thank you.

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web