All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ben Hutchings <ben.hutchings@codethink.co.uk>
To: "David S.Miller" <davem@davemloft.net>
Cc: netdev@vger.kernel.org, linux-kernel@lists.codethink.co.uk,
	Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>,
	Mitsuhiro Kimura <mitsuhiro.kimura.kc@renesas.com>,
	Hisashi Nakamura <hisashi.nakamura.ak@renesas.com>,
	Yoshihiro Kaneko <ykaneko0929@gmail.com>
Subject: [PATCH net 1/4] sh_eth: Fix padding of short frames on TX
Date: Thu, 22 Jan 2015 12:40:13 +0000	[thread overview]
Message-ID: <1421930413.1222.286.camel@xylophone.i.decadent.org.uk> (raw)
In-Reply-To: <1421930284.1222.285.camel@xylophone.i.decadent.org.uk>

If an skb to be transmitted is shorter than the minimum Ethernet frame
length, we currently set the DMA descriptor length to the minimum but
do not add zero-padding.  This could result in leaking sensitive
data.  We also pass different lengths to dma_map_single() and
dma_unmap_single().

Use skb_padto() to pad properly, before calling dma_map_single().

Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
---
 drivers/net/ethernet/renesas/sh_eth.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/renesas/sh_eth.c
index 28e3822..69f9fff 100644
--- a/drivers/net/ethernet/renesas/sh_eth.c
+++ b/drivers/net/ethernet/renesas/sh_eth.c
@@ -2117,6 +2117,9 @@ static int sh_eth_start_xmit(struct sk_buff *skb, struct net_device *ndev)
 	}
 	spin_unlock_irqrestore(&mdp->lock, flags);
 
+	if (skb_padto(skb, ETH_ZLEN))
+		return NETDEV_TX_OK;
+
 	entry = mdp->cur_tx % mdp->num_tx_ring;
 	mdp->tx_skbuff[entry] = skb;
 	txdesc = &mdp->tx_ring[entry];
@@ -2126,10 +2129,7 @@ static int sh_eth_start_xmit(struct sk_buff *skb, struct net_device *ndev)
 				 skb->len + 2);
 	txdesc->addr = dma_map_single(&ndev->dev, skb->data, skb->len,
 				      DMA_TO_DEVICE);
-	if (skb->len < ETH_ZLEN)
-		txdesc->buffer_length = ETH_ZLEN;
-	else
-		txdesc->buffer_length = skb->len;
+	txdesc->buffer_length = skb->len;
 
 	if (entry >= mdp->num_tx_ring - 1)
 		txdesc->status |= cpu_to_edmac(mdp, TD_TACT | TD_TDLE);
-- 
1.7.10.4

  reply	other threads:[~2015-01-22 12:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-22 12:38 [PATCH net 0/4] Fixes for sh_eth #2 Ben Hutchings
2015-01-22 12:40 ` Ben Hutchings [this message]
2015-01-22 12:40 ` [PATCH net 2/4] sh_eth: Detach net device when stopping queue to resize DMA rings Ben Hutchings
2015-01-22 12:41 ` [PATCH net 3/4] sh_eth: Fix crash or memory leak when resizing rings on device that is down Ben Hutchings
2015-01-22 12:44 ` [PATCH net 4/4] sh_eth: Fix serialisation of interrupt disable with interrupt & NAPI handlers Ben Hutchings
2015-01-22 13:50   ` Sergei Shtylyov
2015-01-22 15:06     ` Ben Hutchings
2015-01-22 16:35       ` Sergei Shtylyov
2015-01-22 17:59         ` Ben Hutchings
2015-01-27  0:13 ` [PATCH net 0/4] Fixes for sh_eth #2 David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1421930413.1222.286.camel@xylophone.i.decadent.org.uk \
    --to=ben.hutchings@codethink.co.uk \
    --cc=davem@davemloft.net \
    --cc=hisashi.nakamura.ak@renesas.com \
    --cc=linux-kernel@lists.codethink.co.uk \
    --cc=mitsuhiro.kimura.kc@renesas.com \
    --cc=netdev@vger.kernel.org \
    --cc=nobuhiro.iwamatsu.yj@renesas.com \
    --cc=ykaneko0929@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.