can: bcm: add locking for bcm_op runtime updates
authorOliver Hartkopp <socketcan@hartkopp.net>
Mon, 19 May 2025 12:50:26 +0000 (14:50 +0200)
committerMarc Kleine-Budde <mkl@pengutronix.de>
Mon, 19 May 2025 14:58:12 +0000 (16:58 +0200)
commitc2aba69d0c36a496ab4f2e81e9c2b271f2693fd7
treee5ad5f75e90960a31fb9b585a59118ad2447aa6f
parent69c6d83d717317eab42835bc9fd54173c8de31ac
can: bcm: add locking for bcm_op runtime updates

The CAN broadcast manager (CAN BCM) can send a sequence of CAN frames via
hrtimer. The content and also the length of the sequence can be changed
resp reduced at runtime where the 'currframe' counter is then set to zero.

Although this appeared to be a safe operation the updates of 'currframe'
can be triggered from user space and hrtimer context in bcm_can_tx().
Anderson Nascimento created a proof of concept that triggered a KASAN
slab-out-of-bounds read access which can be prevented with a spin_lock_bh.

At the rework of bcm_can_tx() the 'count' variable has been moved into
the protected section as this variable can be modified from both contexts
too.

Fixes: ffd980f976e7 ("[CAN]: Add broadcast manager (bcm) protocol")
Reported-by: Anderson Nascimento <anderson@allelesecurity.com>
Tested-by: Anderson Nascimento <anderson@allelesecurity.com>
Reviewed-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://patch.msgid.link/20250519125027.11900-1-socketcan@hartkopp.net
Cc: stable@vger.kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
net/can/bcm.c