can: m_can: fix a possible use after free in m_can_tx_handler()
Subsystems (4)
PATCH 1/1 can: m_can: fix a possible use after free in m_can_tx_handler()
can_put_echo_skb will clone skb then free the skb. It is better to avoid using skb after can_put_echo_skb.
Signed-off-by Hangyu Hua <[email protected]>
--- drivers/net/can/m_can/m_can.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/can/m_can/m_can.c +2 -1
@@ -1607,6 +1607,7 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev)u32 cccr, fdflags;int err;int putidx; +unsigned int len = skb->len; cdev->tx_skb =NULL ;
@@ -1642,7 +1643,7 @@ static netdev_tx_t m_can_tx_handler(struct m_can_classdev *cdev)if (cdev->can.ctrlmode &CAN_CTRLMODE_FD ) { cccr =m_can_read (cdev,M_CAN_CCCR ); cccr &= ~CCCR_CMR_MASK ; -if (can_is_canfd_skb (skb)) { +if (len ==CANFD_MTU ) {if (cf->flags &CANFD_BRS ) cccr |=FIELD_PREP (CCCR_CMR_MASK ,CCCR_CMR_CANFD_BRS );
Signature · 1 line
2.25.1
Marc Kleine-Budde
maintainerQuoted 2 lines · Hangyu Hua
can_put_echo_skbwill clone skb then free the skb. It is better to avoid using skb aftercan_put_echo_skb.
Why not move the can_put_echo_skb() instead? I'll send a patch.
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung West/Dortmund | Phone: +49-231-2826-924 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |