Skip to content

Commit 75854ca

Browse files
vincent-mailholmarckleinebudde
authored andcommitted
can: vxcan: vxcan_xmit: fix use after free bug
After calling netif_rx_ni(skb), dereferencing skb is unsafe. Especially, the canfd_frame cfd which aliases skb memory is accessed after the netif_rx_ni(). Fixes: a8f820a ("can: add Virtual CAN Tunnel driver (vxcan)") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vincent Mailhol <[email protected]> Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 03f16c5 commit 75854ca

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/net/can/vxcan.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ static netdev_tx_t vxcan_xmit(struct sk_buff *skb, struct net_device *dev)
3939
struct net_device *peer;
4040
struct canfd_frame *cfd = (struct canfd_frame *)skb->data;
4141
struct net_device_stats *peerstats, *srcstats = &dev->stats;
42+
u8 len;
4243

4344
if (can_dropped_invalid_skb(dev, skb))
4445
return NETDEV_TX_OK;
@@ -61,12 +62,13 @@ static netdev_tx_t vxcan_xmit(struct sk_buff *skb, struct net_device *dev)
6162
skb->dev = peer;
6263
skb->ip_summed = CHECKSUM_UNNECESSARY;
6364

65+
len = cfd->len;
6466
if (netif_rx_ni(skb) == NET_RX_SUCCESS) {
6567
srcstats->tx_packets++;
66-
srcstats->tx_bytes += cfd->len;
68+
srcstats->tx_bytes += len;
6769
peerstats = &peer->stats;
6870
peerstats->rx_packets++;
69-
peerstats->rx_bytes += cfd->len;
71+
peerstats->rx_bytes += len;
7072
}
7173

7274
out_unlock:

0 commit comments

Comments
 (0)