Commit 2e36c9fb authored by Paul Barker's avatar Paul Barker Committed by Paolo Abeni

net: ravb: Fix RX byte accounting for jumbo packets

The RX byte accounting for jumbo packets was changed to fix a potential
use-after-free bug. However, that fix used the wrong variable and so
only accounted for the number of bytes in the final descriptor, not the
number of bytes in the whole packet.

To fix this, we can simply update our stats with the correct number of
bytes before calling napi_gro_receive().

Also rename pkt_len to desc_len in ravb_rx_gbeth() to avoid any future
confusion. The variable name pkt_len is correct in ravb_rx_rcar() as
that function does not handle packets spanning multiple descriptors.

Fixes: 5a5a3e56 ("ravb: Fix potential use-after-free in ravb_rx_gbeth()")
Signed-off-by: default avatarPaul Barker <paul.barker.ct@bp.renesas.com>
Reviewed-by: default avatarSergey Shtylyov <s.shtylyov@omp.ru>
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
parent c7c44950
...@@ -769,7 +769,7 @@ static bool ravb_rx_gbeth(struct net_device *ndev, int *quota, int q) ...@@ -769,7 +769,7 @@ static bool ravb_rx_gbeth(struct net_device *ndev, int *quota, int q)
dma_addr_t dma_addr; dma_addr_t dma_addr;
int rx_packets = 0; int rx_packets = 0;
u8 desc_status; u8 desc_status;
u16 pkt_len; u16 desc_len;
u8 die_dt; u8 die_dt;
int entry; int entry;
int limit; int limit;
...@@ -787,10 +787,10 @@ static bool ravb_rx_gbeth(struct net_device *ndev, int *quota, int q) ...@@ -787,10 +787,10 @@ static bool ravb_rx_gbeth(struct net_device *ndev, int *quota, int q)
/* Descriptor type must be checked before all other reads */ /* Descriptor type must be checked before all other reads */
dma_rmb(); dma_rmb();
desc_status = desc->msc; desc_status = desc->msc;
pkt_len = le16_to_cpu(desc->ds_cc) & RX_DS; desc_len = le16_to_cpu(desc->ds_cc) & RX_DS;
/* We use 0-byte descriptors to mark the DMA mapping errors */ /* We use 0-byte descriptors to mark the DMA mapping errors */
if (!pkt_len) if (!desc_len)
continue; continue;
if (desc_status & MSC_MC) if (desc_status & MSC_MC)
...@@ -811,25 +811,25 @@ static bool ravb_rx_gbeth(struct net_device *ndev, int *quota, int q) ...@@ -811,25 +811,25 @@ static bool ravb_rx_gbeth(struct net_device *ndev, int *quota, int q)
switch (die_dt) { switch (die_dt) {
case DT_FSINGLE: case DT_FSINGLE:
skb = ravb_get_skb_gbeth(ndev, entry, desc); skb = ravb_get_skb_gbeth(ndev, entry, desc);
skb_put(skb, pkt_len); skb_put(skb, desc_len);
skb->protocol = eth_type_trans(skb, ndev); skb->protocol = eth_type_trans(skb, ndev);
if (ndev->features & NETIF_F_RXCSUM) if (ndev->features & NETIF_F_RXCSUM)
ravb_rx_csum_gbeth(skb); ravb_rx_csum_gbeth(skb);
napi_gro_receive(&priv->napi[q], skb); napi_gro_receive(&priv->napi[q], skb);
rx_packets++; rx_packets++;
stats->rx_bytes += pkt_len; stats->rx_bytes += desc_len;
break; break;
case DT_FSTART: case DT_FSTART:
priv->rx_1st_skb = ravb_get_skb_gbeth(ndev, entry, desc); priv->rx_1st_skb = ravb_get_skb_gbeth(ndev, entry, desc);
skb_put(priv->rx_1st_skb, pkt_len); skb_put(priv->rx_1st_skb, desc_len);
break; break;
case DT_FMID: case DT_FMID:
skb = ravb_get_skb_gbeth(ndev, entry, desc); skb = ravb_get_skb_gbeth(ndev, entry, desc);
skb_copy_to_linear_data_offset(priv->rx_1st_skb, skb_copy_to_linear_data_offset(priv->rx_1st_skb,
priv->rx_1st_skb->len, priv->rx_1st_skb->len,
skb->data, skb->data,
pkt_len); desc_len);
skb_put(priv->rx_1st_skb, pkt_len); skb_put(priv->rx_1st_skb, desc_len);
dev_kfree_skb(skb); dev_kfree_skb(skb);
break; break;
case DT_FEND: case DT_FEND:
...@@ -837,17 +837,17 @@ static bool ravb_rx_gbeth(struct net_device *ndev, int *quota, int q) ...@@ -837,17 +837,17 @@ static bool ravb_rx_gbeth(struct net_device *ndev, int *quota, int q)
skb_copy_to_linear_data_offset(priv->rx_1st_skb, skb_copy_to_linear_data_offset(priv->rx_1st_skb,
priv->rx_1st_skb->len, priv->rx_1st_skb->len,
skb->data, skb->data,
pkt_len); desc_len);
skb_put(priv->rx_1st_skb, pkt_len); skb_put(priv->rx_1st_skb, desc_len);
dev_kfree_skb(skb); dev_kfree_skb(skb);
priv->rx_1st_skb->protocol = priv->rx_1st_skb->protocol =
eth_type_trans(priv->rx_1st_skb, ndev); eth_type_trans(priv->rx_1st_skb, ndev);
if (ndev->features & NETIF_F_RXCSUM) if (ndev->features & NETIF_F_RXCSUM)
ravb_rx_csum_gbeth(priv->rx_1st_skb); ravb_rx_csum_gbeth(priv->rx_1st_skb);
stats->rx_bytes += priv->rx_1st_skb->len;
napi_gro_receive(&priv->napi[q], napi_gro_receive(&priv->napi[q],
priv->rx_1st_skb); priv->rx_1st_skb);
rx_packets++; rx_packets++;
stats->rx_bytes += pkt_len;
break; break;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment