Skip to content

Commit 94b0507

Browse files
anssihgregkh
authored andcommitted
can: xilinx_can: xcan_write_frame(): fix use-after-free of transmitted SKB
[ Upstream commit ef79f00 ] can_put_echo_skb() takes ownership of the SKB and it may be freed during or after the call. However, xilinx_can xcan_write_frame() keeps using SKB after the call. Fix that by only calling can_put_echo_skb() after the code is done touching the SKB. The tx_lock is held for the entire xcan_write_frame() execution and also on the can_get_echo_skb() side so the order of operations does not matter. An earlier fix commit 3d3c817 ("can: xilinx_can: Fix usage of skb memory") did not move the can_put_echo_skb() call far enough. Signed-off-by: Anssi Hannula <anssi.hannula@bitwise.fi> Fixes: 1598efe ("can: xilinx_can: refactor code in preparation for CAN FD support") Link: https://patch.msgid.link/20250822095002.168389-1-anssi.hannula@bitwise.fi [mkl: add "commit" in front of sha1 in patch description] [mkl: fix indention] Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent deedea5 commit 94b0507

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

drivers/net/can/xilinx_can.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -628,14 +628,6 @@ static void xcan_write_frame(struct net_device *ndev, struct sk_buff *skb,
628628
dlc |= XCAN_DLCR_EDL_MASK;
629629
}
630630

631-
if (!(priv->devtype.flags & XCAN_FLAG_TX_MAILBOXES) &&
632-
(priv->devtype.flags & XCAN_FLAG_TXFEMP))
633-
can_put_echo_skb(skb, ndev, priv->tx_head % priv->tx_max, 0);
634-
else
635-
can_put_echo_skb(skb, ndev, 0, 0);
636-
637-
priv->tx_head++;
638-
639631
priv->write_reg(priv, XCAN_FRAME_ID_OFFSET(frame_offset), id);
640632
/* If the CAN frame is RTR frame this write triggers transmission
641633
* (not on CAN FD)
@@ -668,6 +660,14 @@ static void xcan_write_frame(struct net_device *ndev, struct sk_buff *skb,
668660
data[1]);
669661
}
670662
}
663+
664+
if (!(priv->devtype.flags & XCAN_FLAG_TX_MAILBOXES) &&
665+
(priv->devtype.flags & XCAN_FLAG_TXFEMP))
666+
can_put_echo_skb(skb, ndev, priv->tx_head % priv->tx_max, 0);
667+
else
668+
can_put_echo_skb(skb, ndev, 0, 0);
669+
670+
priv->tx_head++;
671671
}
672672

673673
/**

0 commit comments

Comments
 (0)