From nobody Fri Apr 17 12:01:07 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 ECCFF334373; Thu, 19 Feb 2026 12:47:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771505256; cv=none; b=IN0lTNDuENqExq0lHBqzmsFcfPskaMMgnbsTqiYOGHcvS+PIBoQFv4xrN+rcj5AD0PFi4wlfIJrq9kvShUZk3ZGTaJ1jXmGjGB3/o24VZ6mRWe2FH1AkH1laQDd08JfuSuXAavGqsNJx6DDOF6MiIhS8J8YYgenzvWibAMh0H4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771505256; c=relaxed/simple; bh=Ndj7MZu1RYgFXaRQMR5Ww5AM02i+hNiCGZqxPAQvqAw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XGUlbfJzZRzq+ijjXUfFQq5qVa/2kEbwDaJ1C/lkNihC7eOjFL7PoCV+bafatj82DDBFZPPGyqO87q6z/oPk/iZnMdWIFkneO8ykUz8A/xx03N3IGvvtV5PI/LWLO49ewtRtKMhru9OYCNLPgQZzGAeviH3p64VlapDvUY7kxAY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WqDERcrc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="WqDERcrc" Received: by smtp.kernel.org (Postfix) with ESMTPS id A9D8BC19423; Thu, 19 Feb 2026 12:47:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771505255; bh=Ndj7MZu1RYgFXaRQMR5Ww5AM02i+hNiCGZqxPAQvqAw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=WqDERcrc0FYzd/D55jUSdQUW05D/UmahoEmFzJPjNltZU4czHcowLQyRBRStcDzfR +HsYN4zfF6Y62vsGKwmigBhvVHWIWSx79mVT/P9CeFBvbD4N4yKGJbW7+iNk493uBf rxVk8W5f1lpgH6160hnH49SEi/tizBz372p67w/ALZ8OV1qsKoSzR+yXobpGM2xqqr DtqOH3roZdtVXPhnb2toHxEn0LIb4tKVhTF0ekZCkM8oL39uGexX5G5waNLXK4thEH imrPrpxulv1kBH+wAY5SnKwVDOno2/3T3zR+Rd8k5QjN7GMbBNWBelINnC06b+nlul qWZJ4B34lf7Mg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96F29E9A048; Thu, 19 Feb 2026 12:47:35 +0000 (UTC) From: Oliver Hartkopp via B4 Relay Date: Thu, 19 Feb 2026 13:47:31 +0100 Subject: [PATCH v2 1/2] can: bcm: fix locking for bcm_op runtime updates Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260219-bcm_spin_lock_init-v2-1-694352bfca62@hartkopp.net> References: <20260219-bcm_spin_lock_init-v2-0-694352bfca62@hartkopp.net> In-Reply-To: <20260219-bcm_spin_lock_init-v2-0-694352bfca62@hartkopp.net> To: Marc Kleine-Budde , "David S. Miller" , Urs Thuermann Cc: linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, Oliver Hartkopp , syzbot+5b11eccc403dd1cea9f8@syzkaller.appspotmail.com X-Mailer: b4 0.15-dev-47773 X-Developer-Signature: v=1; a=ed25519-sha256; t=1771505254; l=1553; i=socketcan@hartkopp.net; s=20260128; h=from:subject:message-id; bh=XQu0DK6j8SlJ077Pj9O4qw1EtV49i3xT6l7+T5PUHaM=; b=E5k7ahkcLuD04La9QHnSdaDaGBBREOmrl/6BUT125ocgAwYdag/7dEbI9bPskUma7PIdZk0sl dx80MgCRF6zAqLA2vIzal4nSs1Qq8MbSjF79uYElQiiHkdAMo22i/0c X-Developer-Key: i=socketcan@hartkopp.net; a=ed25519; pk=/gU/7/wBqak3kTsTeFbCCqUi9dnh+1i6ITEkfPj/BvU= X-Endpoint-Received: by B4 Relay for socketcan@hartkopp.net/20260128 with auth_id=620 X-Original-From: Oliver Hartkopp Reply-To: socketcan@hartkopp.net From: Oliver Hartkopp Commit c2aba69d0c36 ("can: bcm: add locking for bcm_op runtime updates") added a locking for some variables that can be modified at runtime when updating the sending bcm_op with a new TX_SETUP command in bcm_tx_setup(). Usually the RX_SETUP only handles and filters incoming traffic with one exception: When the RX_RTR_FRAME flag is set a predefined CAN frame is sent when a specific RTR frame is received. Therefore the rx bcm_op uses bcm_can_tx() which uses the bcm_tx_lock that was only initialized in bcm_tx_setup(). Add the missing spin_lock_init() when allocating the bcm_op in bcm_rx_setup() to handle the RTR case properly. Fixes: c2aba69d0c36 ("can: bcm: add locking for bcm_op runtime updates") Reported-by: syzbot+5b11eccc403dd1cea9f8@syzkaller.appspotmail.com Closes: https://lore.kernel.org/linux-can/699466e4.a70a0220.2c38d7.00ff.GAE= @google.com/ Signed-off-by: Oliver Hartkopp --- net/can/bcm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/can/bcm.c b/net/can/bcm.c index b7324e9c955b..fd9fa072881e 100644 --- a/net/can/bcm.c +++ b/net/can/bcm.c @@ -1174,10 +1174,11 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_he= ad, struct msghdr *msg, /* insert new BCM operation for the given can_id */ op =3D kzalloc(OPSIZ, GFP_KERNEL); if (!op) return -ENOMEM; =20 + spin_lock_init(&op->bcm_tx_lock); op->can_id =3D msg_head->can_id; op->nframes =3D msg_head->nframes; op->cfsiz =3D CFSIZ(msg_head->flags); op->flags =3D msg_head->flags; =20 --=20 2.51.0 From nobody Fri Apr 17 12:01:07 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 ECC7C33123A; Thu, 19 Feb 2026 12:47:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771505256; cv=none; b=GUaC2+YJ3U+/TwsNZh1npKJ9LG//YHVo4BuUatAtwM7qBaKTuioAlk11iRdiiJv6+FnC9nAPBOnur//xhwKs129W9W4zDHW8eWWVC6Jnss0k8TjQaFNUfsAppZ8Zj3IszyvqQcyxm+wepnE9SZqnqbofGWNGrabCrsMUqM7rjZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771505256; c=relaxed/simple; bh=mZYbmW+dvJay6yLP96rk2aVfcPCWb/vWObzqfGu6ioA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uKKmiszT4XWpN1orV3FpzbuBXPgG96Zc0ltbahlGk05PGB06W4SoQI0SVN3UXCaCRqe1DytCLiM0OZ98q9tG3kpOO6uC2+6h0GbbTfMKieYPPGFtoYiR9I/y4t8BBZziwuoHSQ/hgvRJf0NnqEuKswT56/kIm1k3SAp3D9Jecq4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ga7PjZMQ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ga7PjZMQ" Received: by smtp.kernel.org (Postfix) with ESMTPS id B9B42C116D0; Thu, 19 Feb 2026 12:47:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771505255; bh=mZYbmW+dvJay6yLP96rk2aVfcPCWb/vWObzqfGu6ioA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=ga7PjZMQCLMiRzM/Y0/DJ64DL5zdVlf7uKTOxptvZ9fLvg36XNS2OMNFRYDY6HLcL tVQ3TirnoYsuiU1ZAxomZBJbG3VcFhFPrFwt9vc+lZYaqBdGBglIHYfz1G6qcM1MPE 770CaZ21v1LQLQJctmvdW4QsKFE1k8Hmw2j4yKHSR7iOYyFDQ+9hJyTtSAkI4dYt9c jBclZJbKSfH0Wk0nXhEnHlPkLfKG2j5Dyu4rV70aiEezdo5AI4X7R/N5K+3oMLEany 3a2ozUEbS/g/2GIXAN8GesHW79oJtiR8Db+WP/qPYoqVSaJtlJhRQorztGTaXSvVNs VgEYyM9cTqFeA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC019E9A049; Thu, 19 Feb 2026 12:47:35 +0000 (UTC) From: Oliver Hartkopp via B4 Relay Date: Thu, 19 Feb 2026 13:47:32 +0100 Subject: [PATCH v2 2/2] can: bcm: add locking when updating filter and timer values Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260219-bcm_spin_lock_init-v2-2-694352bfca62@hartkopp.net> References: <20260219-bcm_spin_lock_init-v2-0-694352bfca62@hartkopp.net> In-Reply-To: <20260219-bcm_spin_lock_init-v2-0-694352bfca62@hartkopp.net> To: Marc Kleine-Budde , "David S. Miller" , Urs Thuermann Cc: linux-can@vger.kernel.org, linux-kernel@vger.kernel.org, Oliver Hartkopp , syzbot+75e5e4ae00c3b4bb544e@syzkaller.appspotmail.com X-Mailer: b4 0.15-dev-47773 X-Developer-Signature: v=1; a=ed25519-sha256; t=1771505254; l=4358; i=socketcan@hartkopp.net; s=20260128; h=from:subject:message-id; bh=LZlNTIGHLDqDPxLmvSsyaQormiMZ6P6MsnwA3/m9nxY=; b=aYlRDF3AAVYKMqetg4BauKI9oNRyiM7CKQ4FeqEUUVdSELBZI4dLlwRVfDm5dHM9B9TnEIw58 QOf/3x95UigANm09SDQlqgSaIWkdk2lyMQhJXJk3wWAJekdMS/qOJiR X-Developer-Key: i=socketcan@hartkopp.net; a=ed25519; pk=/gU/7/wBqak3kTsTeFbCCqUi9dnh+1i6ITEkfPj/BvU= X-Endpoint-Received: by B4 Relay for socketcan@hartkopp.net/20260128 with auth_id=620 X-Original-From: Oliver Hartkopp Reply-To: socketcan@hartkopp.net From: Oliver Hartkopp KCSAN detected a simultaneous access to timer values that can be overwritten in bcm_rx_setup when updating timer and filter content. This caused no functional issues in the past as the new values might show up at any time without losing its intended functionality. Btw. the KCSAN report can be resolved by protecting the 'lockless' data updates with a spin_lock_bh(). Fixes: ffd980f976e7 ("[CAN]: Add broadcast manager (bcm) protocol") Reported-by: syzbot+75e5e4ae00c3b4bb544e@syzkaller.appspotmail.com Closes: https://lore.kernel.org/linux-can/6975d5cf.a00a0220.33ccc7.0022.GAE= @google.com/ Signed-off-by: Oliver Hartkopp Tested-by: Oliver Hartkopp --- net/can/bcm.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/net/can/bcm.c b/net/can/bcm.c index fd9fa072881e..0a3dc5500e14 100644 --- a/net/can/bcm.c +++ b/net/can/bcm.c @@ -123,10 +123,11 @@ struct bcm_op { struct canfd_frame sframe; struct canfd_frame last_sframe; struct sock *sk; struct net_device *rx_reg_dev; spinlock_t bcm_tx_lock; /* protect currframe/count in runtime updates */ + spinlock_t bcm_rx_update_lock; /* protect update of filter data */ }; =20 struct bcm_sock { struct sock sk; int bound; @@ -1141,10 +1142,12 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_he= ad, struct msghdr *msg, return -EINVAL; =20 /* check the given can_id */ op =3D bcm_find_op(&bo->rx_ops, msg_head, ifindex); if (op) { + void *new_frames =3D NULL; + /* update existing BCM operation */ =20 /* * Do we need more space for the CAN frames than currently * allocated? -> This is a _really_ unusual use-case and @@ -1152,33 +1155,53 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_he= ad, struct msghdr *msg, */ if (msg_head->nframes > op->nframes) return -E2BIG; =20 if (msg_head->nframes) { - /* update CAN frames content */ - err =3D memcpy_from_msg(op->frames, msg, + /* get new CAN frames content before locking */ + new_frames =3D kmalloc(msg_head->nframes * op->cfsiz, + GFP_KERNEL); + if (!new_frames) + return -ENOMEM; + + err =3D memcpy_from_msg(new_frames, msg, msg_head->nframes * op->cfsiz); - if (err < 0) + if (err < 0) { + kfree(new_frames); return err; - - /* clear last_frames to indicate 'nothing received' */ - memset(op->last_frames, 0, msg_head->nframes * op->cfsiz); + } } =20 + spin_lock_bh(&op->bcm_rx_update_lock); op->nframes =3D msg_head->nframes; op->flags =3D msg_head->flags; =20 + if (msg_head->nframes) { + /* update CAN frames content */ + memcpy(op->frames, new_frames, + msg_head->nframes * op->cfsiz); + + /* clear last_frames to indicate 'nothing received' */ + memset(op->last_frames, 0, + msg_head->nframes * op->cfsiz); + } + spin_unlock_bh(&op->bcm_rx_update_lock); + + /* free temporary frames / kfree(NULL) is safe */ + kfree(new_frames); + /* Only an update -> do not call can_rx_register() */ do_rx_register =3D 0; =20 } else { /* insert new BCM operation for the given can_id */ op =3D kzalloc(OPSIZ, GFP_KERNEL); if (!op) return -ENOMEM; =20 spin_lock_init(&op->bcm_tx_lock); + spin_lock_init(&op->bcm_rx_update_lock); op->can_id =3D msg_head->can_id; op->nframes =3D msg_head->nframes; op->cfsiz =3D CFSIZ(msg_head->flags); op->flags =3D msg_head->flags; =20 @@ -1261,24 +1284,26 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_he= ad, struct msghdr *msg, =20 } else { if (op->flags & SETTIMER) { =20 /* set timer value */ + spin_lock_bh(&op->bcm_rx_update_lock); op->ival1 =3D msg_head->ival1; op->ival2 =3D msg_head->ival2; op->kt_ival1 =3D bcm_timeval_to_ktime(msg_head->ival1); op->kt_ival2 =3D bcm_timeval_to_ktime(msg_head->ival2); + op->kt_lastmsg =3D 0; + spin_unlock_bh(&op->bcm_rx_update_lock); =20 /* disable an active timer due to zero value? */ if (!op->kt_ival1) hrtimer_cancel(&op->timer); =20 /* * In any case cancel the throttle timer, flush * potentially blocked msgs and reset throttle handling */ - op->kt_lastmsg =3D 0; hrtimer_cancel(&op->thrtimer); bcm_rx_thr_flush(op); } =20 if ((op->flags & STARTTIMER) && op->kt_ival1) --=20 2.51.0