Skip to content

Commit 58fd6cb

Browse files
hartkoppmarckleinebudde
authored andcommitted
can: bcm: fix data race on rx_stamp/rx_ifindex in bcm_rx_handler()
For an rx op subscribed on all interfaces (ifindex == 0), the same op is registered once in the shared per-netns wildcard filter list, so bcm_rx_handler() can run concurrently on different CPUs for frames arriving on different net devices. op->rx_stamp and op->rx_ifindex were written before bcm_rx_update_lock was taken, allowing concurrent writers to race each other - including a torn store of the 64-bit rx_stamp on 32-bit platforms. Beyond a torn store bcm_send_to_user() must report the timestamp/ifindex of the very same frame whose content it is delivering. So the assignment is placed in the same unbroken bcm_rx_update_lock section as the content comparison. As a side effect, the RTR-request frame feature (which never reach bcm_send_to_user()) no longer updates rx_stamp/rx_ifindex, since only the notification path needs them. Fixes: ffd980f ("[CAN]: Add broadcast manager (bcm) protocol") Reported-by: sashiko-bot@kernel.org Closes: https://lore.kernel.org/linux-can/20260707145135.5BC831F00A3A@smtp.kernel.org/ Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net> Link: https://patch.msgid.link/20260714-bcm_fixes-v15-10-562f7e3e42da@hartkopp.net Cc: stable@kernel.org Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
1 parent 3b762c0 commit 58fd6cb

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

net/can/bcm.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -800,11 +800,6 @@ static void bcm_rx_handler(struct sk_buff *skb, void *data)
800800
/* disable timeout */
801801
hrtimer_cancel(&op->timer);
802802

803-
/* save rx timestamp */
804-
op->rx_stamp = skb->tstamp;
805-
/* save originator for recvfrom() */
806-
op->rx_ifindex = skb->dev->ifindex;
807-
808803
/* op->flags/op->frames may be updated concurrently by bcm_rx_setup() */
809804
spin_lock_bh(&op->bcm_rx_update_lock);
810805

@@ -836,6 +831,14 @@ static void bcm_rx_handler(struct sk_buff *skb, void *data)
836831
traffic_flags |= RX_OWN;
837832
}
838833

834+
/* save rx timestamp and originator for recvfrom() under lock.
835+
* For an op subscribed on all interfaces (ifindex == 0)
836+
* bcm_rx_handler() can run concurrently on different CPUs so
837+
* the CAN content and the meta data must be bundled correctly.
838+
*/
839+
op->rx_stamp = skb->tstamp;
840+
op->rx_ifindex = skb->dev->ifindex;
841+
839842
if (op->flags & RX_FILTER_ID) {
840843
/* the easiest case */
841844
bcm_rx_update_and_send(op, op->last_frames, rxframe,

0 commit comments

Comments
 (0)