linux/drivers/net/can
Sebastian Würl dad7f33c95 can: mcp251x: Fix race condition on receive interrupt
commit d80d60b0db upstream.

The mcp251x driver uses both receiving mailboxes of the CAN controller
chips. For retrieving the CAN frames from the controller via SPI, it checks
once per interrupt which mailboxes have been filled and will retrieve the
messages accordingly.

This introduces a race condition, as another CAN frame can enter mailbox 1
while mailbox 0 is emptied. If now another CAN frame enters mailbox 0 until
the interrupt handler is called next, mailbox 0 is emptied before
mailbox 1, leading to out-of-order CAN frames in the network device.

This is fixed by checking the interrupt flags once again after freeing
mailbox 0, to correctly also empty mailbox 1 before leaving the handler.

For reproducing the bug I created the following setup:
 - Two CAN devices, one Raspberry Pi with MCP2515, the other can be any.
 - Setup CAN to 1 MHz
 - Spam bursts of 5 CAN-messages with increasing CAN-ids
 - Continue sending the bursts while sleeping a second between the bursts
 - Check on the RPi whether the received messages have increasing CAN-ids
 - Without this patch, every burst of messages will contain a flipped pair

v3: https://lore.kernel.org/all/20220804075914.67569-1-sebastian.wuerl@ororatech.com
v2: https://lore.kernel.org/all/20220804064803.63157-1-sebastian.wuerl@ororatech.com
v1: https://lore.kernel.org/all/20220803153300.58732-1-sebastian.wuerl@ororatech.com

Fixes: bf66f3736a ("can: mcp251x: Move to threaded interrupts instead of workqueues.")
Signed-off-by: Sebastian Würl <sebastian.wuerl@ororatech.com>
Link: https://lore.kernel.org/all/20220804081411.68567-1-sebastian.wuerl@ororatech.com
[mkl: reduce scope of intf1, eflag1]
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2022-08-25 11:45:14 +02:00
..
c_can can: can-dev: remove obsolete CAN LED support 2022-05-19 22:15:51 +02:00
cc770 can: do not increase tx_bytes statistics for RTR frames 2022-01-05 12:09:05 +01:00
ctucanfd can: ctucanfd: platform: add missing dependency to HAS_IOMEM 2022-05-23 22:00:06 +02:00
dev can: netlink: allow configuring of fixed data bit rates without need for do_set_data_bittiming callback 2022-08-17 15:14:29 +02:00
flexcan can: can-dev: remove obsolete CAN LED support 2022-05-19 22:15:51 +02:00
ifi_canfd can: can-dev: remove obsolete CAN LED support 2022-05-19 22:15:51 +02:00
m_can can: m_can: m_can_{read_fifo,echo_tx_event}(): shift timestamp to full 32 bits 2022-07-04 11:43:00 +02:00
mscan can: can-dev: move to netif_napi_add_weight() 2022-05-19 22:11:28 +02:00
peak_canfd can: do not increase tx_bytes statistics for RTR frames 2022-01-05 12:09:05 +01:00
rcar can: rcar_can: do not report txerr and rxerr during bus-off 2022-08-17 15:14:52 +02:00
sja1000 can: sja1000: do not report txerr and rxerr during bus-off 2022-08-17 15:14:52 +02:00
softing can: softing: softing_netdev_open(): remove redundant ret variable 2022-02-24 08:26:04 +01:00
spi can: mcp251x: Fix race condition on receive interrupt 2022-08-25 11:45:14 +02:00
usb can: ems_usb: fix clang's -Wunaligned-access warning 2022-08-25 11:45:10 +02:00
at91_can.c can: can-dev: remove obsolete CAN LED support 2022-05-19 22:15:51 +02:00
grcan.c can: grcan: grcan_probe(): remove extra of_node_get() 2022-07-04 11:42:59 +02:00
janz-ican3.c can: can-dev: move to netif_napi_add_weight() 2022-05-19 22:11:28 +02:00
Kconfig can: can-dev: remove obsolete CAN LED support 2022-05-19 22:15:51 +02:00
kvaser_pciefd.c can: do not increase rx_bytes statistics for RTR frames 2022-01-05 12:09:05 +01:00
Makefile can: ctucanfd: add support for CTU CAN FD open-source IP core - bus independent part. 2022-04-19 17:12:14 +02:00
pch_can.c can: pch_can: pch_can_error(): initialize errc before using it 2022-08-17 15:14:53 +02:00
slcan.c can: slcan: slc_xmit(): use can_dropped_invalid_skb() instead of manual check 2022-05-16 22:06:51 +02:00
sun4i_can.c can: sun4i_can: do not report txerr and rxerr during bus-off 2022-08-17 15:14:52 +02:00
ti_hecc.c can: can-dev: remove obsolete CAN LED support 2022-05-19 22:15:51 +02:00
vcan.c can: Use netif_rx(). 2022-03-06 11:05:31 +00:00
vxcan.c can: vxcan: vxcan_xmit(): use kfree_skb() instead of kfree() to free skb 2022-03-13 09:45:35 +01:00
xilinx_can.c Revert "can: xilinx_can: Limit CANFD brp to 2" 2022-07-04 11:24:13 +02:00