From: sashiko-bot@kernel.org
To: "Zhu Jun" <zhujun2@cmss.chinamobile.com>
Cc: linux-can@vger.kernel.org,
"Marc Kleine-Budde" <mkl@pengutronix.de>,
"Oliver Hartkopp" <socketcan@hartkopp.net>,
"Vincent Mailhol" <mailhol@kernel.org>,
"Oleksij Rempel" <o.rempel@pengutronix.de>
Subject: Re: [PATCH] can: gw: avoid losing statistics updates on concurrent receive
Date: Wed, 11 Nov 2026 06:33:03 +0000 [thread overview]
Message-ID: <sashiko-outbox-208446@kernel.org> (raw)
In-Reply-To: <20261111062907.16857-1-zhujun2@cmss.chinamobile.com>
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] can: data race modifying shared SKB in can_send() [1]
--
commit 10078742ee4a6687a5a77083fa056c99b8f26a52
Author: Zhu Jun <zhujun2@cmss.chinamobile.com>
can: gw: avoid losing statistics updates on concurrent receive
This commit converts the frame statistics counters in struct cgw_job to
atomic_t so concurrent receive paths and netlink dumps do not race on
counter updates.
> diff --git a/net/can/gw.c b/net/can/gw.c
> index 8a5327d8a00e8..a5233b4606dad 100644
> --- a/net/can/gw.c
> +++ b/net/can/gw.c
[ ... ]
> @@ -510,7 +511,7 @@ static void can_can_gw_rcv(struct sk_buff *skb, void *data)
> nskb = skb_clone(skb, GFP_ATOMIC);
>
> if (!nskb) {
> - gwj->dropped_frames++;
> + atomic_inc(&gwj->dropped_frames);
> return;
> }
[ ... ]
> @@ -571,9 +572,9 @@ static void can_can_gw_rcv(struct sk_buff *skb, void *data)
>
> /* send to netdevice */
> if (can_send(nskb, gwj->flags & CGW_FLAGS_CAN_ECHO))
> - gwj->dropped_frames++;
> + atomic_inc(&gwj->dropped_frames);
> else
> - gwj->handled_frames++;
> + atomic_inc(&gwj->handled_frames);
> }
[Severity: High]
This problem wasn't introduced by this patch, but can routing an unmodified
CAN FD frame cause a data race [1] on the shared skb payload in
can_send()?
When no modification functions are configured (!mod->modfunc[0]),
can_can_gw_rcv() duplicates the incoming skb with skb_clone(), which shares
skb->data with the original skb, and passes nskb to can_send():
net/can/af_can.c:can_send() {
...
} else if (can_is_canfd_skb(skb)) {
struct canfd_frame *cfd = (struct canfd_frame *)skb->data;
skb->protocol = htons(ETH_P_CANFD);
/* set CAN FD flag for CAN FD frames by default */
cfd->flags |= CANFD_FDF;
...
}
can_send() modifies cfd->flags in place on the shared buffer while other
receivers (such as raw sockets or packet sniffers) may be reading the
original skb concurrently, causing a data race and corrupting the flags for
concurrent readers.
[1] https://sashiko.dev/#/bug/linux-89b38ada-4acb-4bf7-afe0-3d8d244ba058
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261111062907.16857-1-zhujun2@cmss.chinamobile.com?part=1
next prev parent reply other threads:[~2026-11-11 6:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 6:29 [PATCH] can: gw: avoid losing statistics updates on concurrent receive Zhu Jun
2026-11-11 6:33 ` sashiko-bot [this message]
2026-11-11 7:54 ` Oliver Hartkopp
2026-11-11 8:00 ` Oliver Hartkopp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-208446@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=mailhol@kernel.org \
--cc=mkl@pengutronix.de \
--cc=o.rempel@pengutronix.de \
--cc=sashiko-reviews@lists.linux.dev \
--cc=socketcan@hartkopp.net \
--cc=zhujun2@cmss.chinamobile.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox