Skip to content

Commit eebfb64

Browse files
bwh-ctdavem330
authored andcommitted
sh_eth: Fix padding of short frames on TX
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 02a5416 commit eebfb64

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/net/ethernet/renesas/sh_eth.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,6 +2117,9 @@ static int sh_eth_start_xmit(struct sk_buff *skb, struct net_device *ndev)
21172117
}
21182118
spin_unlock_irqrestore(&mdp->lock, flags);
21192119

2120+
if (skb_padto(skb, ETH_ZLEN))
2121+
return NETDEV_TX_OK;
2122+
21202123
entry = mdp->cur_tx % mdp->num_tx_ring;
21212124
mdp->tx_skbuff[entry] = skb;
21222125
txdesc = &mdp->tx_ring[entry];
@@ -2126,10 +2129,7 @@ static int sh_eth_start_xmit(struct sk_buff *skb, struct net_device *ndev)
21262129
skb->len + 2);
21272130
txdesc->addr = dma_map_single(&ndev->dev, skb->data, skb->len,
21282131
DMA_TO_DEVICE);
2129-
if (skb->len < ETH_ZLEN)
2130-
txdesc->buffer_length = ETH_ZLEN;
2131-
else
2132-
txdesc->buffer_length = skb->len;
2132+
txdesc->buffer_length = skb->len;
21332133

21342134
if (entry >= mdp->num_tx_ring - 1)
21352135
txdesc->status |= cpu_to_edmac(mdp, TD_TACT | TD_TDLE);

0 commit comments

Comments
 (0)