From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED6A91A9FA0; Mon, 17 Aug 2026 15:00:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786978828; cv=none; b=Z830trMRx6km7gQRRJQWKaR61Akxh+kQxHqrPdL5/+z+185hnui73vuASqS6soYKqCzKbvMCriWENs4j8oBqLgIChvWlDgJV9Szinz8ErqLHBi+bHmLfn0vh76Psu2auJrFRqbcfFMKiXk0CEfGHXh85eByJlcRgn7UKwD3l0SQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786978828; c=relaxed/simple; bh=87b4u/nQSHlMUCKazT/T86WQC1ZTmEd6/IjGdgvGnT0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t18q5SrZTPpVpTr/lCPrIuA+wnY1xDAvwZBGg+/uzeXWm3WyqKcuwcxeXOd2NVJRVZUjuHVomlca/40jFMSaH94Q7wVCbqeWY/GJM7mkRJnSKmU2EJJLzbm/iQhcFAFtcnXzzy/SO+zMtaADasr579gzszgk/DITKJe3xRTf8oA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=s7EJ2dFF; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="s7EJ2dFF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E6FB1F000E9; Mon, 17 Aug 2026 15:00:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786978826; bh=/yhVHvaEF9RimuEX6uh1R13qkbvH+0eQ50vRSGA5Z94=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=s7EJ2dFFFF/zjujjAODj4R60dy1OlWb5V4qnw3ms+J10HobpAAhcfGyE6O9FLnOki MrLD/1iaJ1bjNASeQs3ZihJ+5CRaeqZse5dtE3Auww42UUFpxhzvXSF5sZesNAuIE4 Z9xJF0tFLGP90BbAXdqlhGoJdUl4ooxlZijdg/8I= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, sashiko-bot@kernel.org, Oliver Hartkopp , stable@kernel.org, Marc Kleine-Budde , Sasha Levin Subject: [PATCH 6.1 015/609] can: bcm: fix data race on rx_stamp/rx_ifindex in bcm_rx_handler() Date: Mon, 17 Aug 2026 15:25:11 +0200 Message-ID: <20260817132543.700340019@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260817132543.039278408@linuxfoundation.org> References: <20260817132543.039278408@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Oliver Hartkopp commit 58fd6cbc8541216af1d7ed272ea7ac2b66d50fd8 upstream. 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: ffd980f976e7 ("[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 Link: https://patch.msgid.link/20260714-bcm_fixes-v15-10-562f7e3e42da@hartkopp.net Cc: stable@kernel.org Signed-off-by: Marc Kleine-Budde Signed-off-by: Oliver Hartkopp Signed-off-by: Sasha Levin --- net/can/bcm.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/net/can/bcm.c b/net/can/bcm.c index c304279d667b4f..e6eaf7dfcb2ac5 100644 --- a/net/can/bcm.c +++ b/net/can/bcm.c @@ -761,11 +761,6 @@ static void bcm_rx_handler(struct sk_buff *skb, void *data) /* disable timeout */ hrtimer_cancel(&op->timer); - /* save rx timestamp */ - op->rx_stamp = skb->tstamp; - /* save originator for recvfrom() */ - op->rx_ifindex = skb->dev->ifindex; - /* op->flags/op->frames may be updated concurrently by bcm_rx_setup() */ spin_lock_bh(&op->bcm_rx_update_lock); @@ -789,6 +784,14 @@ static void bcm_rx_handler(struct sk_buff *skb, void *data) */ bcm_update_rx_stats(op); + /* save rx timestamp and originator for recvfrom() under lock. + * For an op subscribed on all interfaces (ifindex == 0) + * bcm_rx_handler() can run concurrently on different CPUs so + * the CAN content and the meta data must be bundled correctly. + */ + op->rx_stamp = skb->tstamp; + op->rx_ifindex = skb->dev->ifindex; + if (op->flags & RX_FILTER_ID) { /* the easiest case */ bcm_rx_update_and_send(op, op->last_frames, rxframe); -- 2.53.0