Skip to content

Commit 4a41bb9

Browse files
rrendecgregkh
authored andcommitted
net: rswitch: Avoid use-after-free in rswitch_poll()
commit 9a0c28e upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 9f7a9f9 commit 4a41bb9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/net/ethernet/renesas/rswitch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,13 +799,13 @@ static void rswitch_tx_free(struct net_device *ndev)
799799

800800
skb = gq->skbs[gq->dirty];
801801
if (skb) {
802+
rdev->ndev->stats.tx_packets++;
803+
rdev->ndev->stats.tx_bytes += skb->len;
802804
dma_unmap_single(ndev->dev.parent,
803805
gq->unmap_addrs[gq->dirty],
804806
skb->len, DMA_TO_DEVICE);
805807
dev_kfree_skb_any(gq->skbs[gq->dirty]);
806808
gq->skbs[gq->dirty] = NULL;
807-
rdev->ndev->stats.tx_packets++;
808-
rdev->ndev->stats.tx_bytes += skb->len;
809809
}
810810

811811
desc->desc.die_dt = DT_EEMPTY;

0 commit comments

Comments
 (0)