Skip to content

Commit ef79f00

Browse files
anssihmarckleinebudde
authored andcommitted
can: xilinx_can: xcan_write_frame(): fix use-after-free of transmitted SKB
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 <[email protected]> Fixes: 1598efe ("can: xilinx_can: refactor code in preparation for CAN FD support") Link: https://patch.msgid.link/[email protected] [mkl: add "commit" in front of sha1 in patch description] [mkl: fix indention] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 06e02da commit ef79f00

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
@@ -690,14 +690,6 @@ static void xcan_write_frame(struct net_device *ndev, struct sk_buff *skb,
690690
dlc |= XCAN_DLCR_EDL_MASK;
691691
}
692692

693-
if (!(priv->devtype.flags & XCAN_FLAG_TX_MAILBOXES) &&
694-
(priv->devtype.flags & XCAN_FLAG_TXFEMP))
695-
can_put_echo_skb(skb, ndev, priv->tx_head % priv->tx_max, 0);
696-
else
697-
can_put_echo_skb(skb, ndev, 0, 0);
698-
699-
priv->tx_head++;
700-
701693
priv->write_reg(priv, XCAN_FRAME_ID_OFFSET(frame_offset), id);
702694
/* If the CAN frame is RTR frame this write triggers transmission
703695
* (not on CAN FD)
@@ -730,6 +722,14 @@ static void xcan_write_frame(struct net_device *ndev, struct sk_buff *skb,
730722
data[1]);
731723
}
732724
}
725+
726+
if (!(priv->devtype.flags & XCAN_FLAG_TX_MAILBOXES) &&
727+
(priv->devtype.flags & XCAN_FLAG_TXFEMP))
728+
can_put_echo_skb(skb, ndev, priv->tx_head % priv->tx_max, 0);
729+
else
730+
can_put_echo_skb(skb, ndev, 0, 0);
731+
732+
priv->tx_head++;
733733
}
734734

735735
/**

0 commit comments

Comments
 (0)