Skip to content

Commit 869016a

Browse files
marckleinebuddegregkh
authored andcommitted
can: m_can: m_can_tx_handler(): fix use after free of skb
commit 2e8e79c upstream. can_put_echo_skb() will clone skb then free the skb. Move the can_put_echo_skb() for the m_can version 3.0.x directly before the start of the xmit in hardware, similar to the 3.1.x branch. Fixes: 8064673 ("can: m_can: update to support CAN FD features") Link: https://lore.kernel.org/all/20220317081305.739554-1-mkl@pengutronix.de Cc: stable@vger.kernel.org Reported-by: Hangyu Hua <hbh25y@gmail.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e90518d commit 869016a

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

drivers/net/can/m_can/m_can.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,8 +1491,6 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev)
14911491
M_CAN_FIFO_DATA(i / 4),
14921492
*(u32 *)(cf->data + i));
14931493

1494-
can_put_echo_skb(skb, dev, 0);
1495-
14961494
if (cdev->can.ctrlmode & CAN_CTRLMODE_FD) {
14971495
cccr = m_can_read(cdev, M_CAN_CCCR);
14981496
cccr &= ~(CCCR_CMR_MASK << CCCR_CMR_SHIFT);
@@ -1509,6 +1507,9 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev)
15091507
m_can_write(cdev, M_CAN_CCCR, cccr);
15101508
}
15111509
m_can_write(cdev, M_CAN_TXBTIE, 0x1);
1510+
1511+
can_put_echo_skb(skb, dev, 0);
1512+
15121513
m_can_write(cdev, M_CAN_TXBAR, 0x1);
15131514
/* End of xmit function for version 3.0.x */
15141515
} else {

0 commit comments

Comments
 (0)