]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
can: xilinx_can: xcan_write_frame(): fix use-after-free of transmitted SKB
authorAnssi Hannula <anssi.hannula@bitwise.fi>
Fri, 22 Aug 2025 09:50:02 +0000 (12:50 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 19 Sep 2025 14:37:37 +0000 (16:37 +0200)
commit668cc1e3bb21101d074e430de1b7ba8fd10189e7
treef1556a2d4d8a2b678b831f8108cc3d96a4ea2fb1
parentc85c52f0ca8e6c0800c4ad0d71ff72002d8944f0
can: xilinx_can: xcan_write_frame(): fix use-after-free of transmitted SKB

[ Upstream commit ef79f00be72bd81d2e1e6f060d83cf7e425deee4 ]

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 3d3c817c3a40 ("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: 1598efe57b3e ("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>
drivers/net/can/xilinx_can.c