Skip to content

Commit 9a0c28e

Browse files
rrendeckuba-moo
authored andcommitted
net: rswitch: Avoid use-after-free in rswitch_poll()
The use-after-free is actually in rswitch_tx_free(), which is inlined in rswitch_poll(). Since `skb` and `gq->skbs[gq->dirty]` are in fact the same pointer, the skb is first freed using dev_kfree_skb_any(), then the value in skb->len is used to update the interface statistics. Let's move around the instructions to use skb->len before the skb is freed. This bug is trivial to reproduce using KFENCE. It will trigger a splat every few packets. A simple ARP request or ICMP echo request is enough. Fixes: 271e015 ("net: rswitch: Add unmap_addrs instead of dma address in each desc") Signed-off-by: Radu Rendec <[email protected]> Reviewed-by: Yoshihiro Shimoda <[email protected]> Reviewed-by: Niklas Söderlund <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 8eb301b commit 9a0c28e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/net/ethernet/renesas/rswitch.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -871,13 +871,13 @@ static void rswitch_tx_free(struct net_device *ndev)
871871
dma_rmb();
872872
skb = gq->skbs[gq->dirty];
873873
if (skb) {
874+
rdev->ndev->stats.tx_packets++;
875+
rdev->ndev->stats.tx_bytes += skb->len;
874876
dma_unmap_single(ndev->dev.parent,
875877
gq->unmap_addrs[gq->dirty],
876878
skb->len, DMA_TO_DEVICE);
877879
dev_kfree_skb_any(gq->skbs[gq->dirty]);
878880
gq->skbs[gq->dirty] = NULL;
879-
rdev->ndev->stats.tx_packets++;
880-
rdev->ndev->stats.tx_bytes += skb->len;
881881
}
882882
desc->desc.die_dt = DT_EEMPTY;
883883
}

0 commit comments

Comments
 (0)