From: netdev-bot+sashiko@kernel.org
To: mkl@pengutronix.de
Cc: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org,
linux-can@vger.kernel.org, kernel@pengutronix.de,
socketcan@hartkopp.net, kurt.van.dijck@eia.be
Subject: Re: [PATCH net-next 17/37] can: rcar_canfd: Add support for Renesas RZ/G3S
Date: Fri, 16 Oct 2026 02:37:08 +0000 [thread overview]
Message-ID: <179211822831.434549.16106222466489918568@kernel.org> (raw)
In-Reply-To: <20261015015336.816543-18-mkl@pengutronix.de>
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] On renesas,r9a08g045-canfd (RZ/G3S), rcar_canfd_probe() reads the
"renesas,no-can-fd" and "renesas,fd-only" DT properties without…
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is a use-
after-free and double free in the probe error path, now also reachable…
- [High] This problem wasn't introduced by this patch, but it is a use-
after-free in IRQ context during driver removal, also reachable on the…
--
can: rcar_canfd: Add support for Renesas RZ/G3S
This adds r9a08g045_hw_info for the RZ/G3S CAN-FD controller: two
channels, 16 AFL pages, a CAN FD clock derived from pclk and a fixed
CAN-FD mode. It also adds the "renesas,r9a08g045-canfd" compatible to the
OF match table.
Link: https://patch.msgid.link/20260902141544.565763-6-claudiu.beznea+renesas@tuxon.dev
> diff --git a/drivers/net/can/rcar/rcar_canfd.c b/drivers/net/can/rcar/rcar_canfd.c
> index ac5d5959d8e4..74c3c3f20991 100644
> --- a/drivers/net/can/rcar/rcar_canfd.c
> +++ b/drivers/net/can/rcar/rcar_canfd.c
> @@ -661,6 +661,26 @@ static const struct rcar_canfd_hw_info rzg2l_hw_info = {
> .fixed_canfd = 0,
> };
>
> +static const struct rcar_canfd_hw_info r9a08g045_hw_info = {
[ ... ]
> + .external_clk = 1,
> + .fcan_pclk = 1,
> + .fixed_canfd = 1,
> +};
[Severity: Low]
This is the first hw_info with fixed_canfd set. That makes the early
continue in rcar_canfd_reset_controller() reachable:
/* Set the controller into appropriate mode */
if (gpriv->info->fixed_canfd)
continue;
As a result CLOE/FDOE are never programmed, and the hardware stays in
CAN-FD mode.
rcar_canfd_probe() still reads the mode properties for every compatible
and does not check info->fixed_canfd:
if (of_property_read_bool(dev->of_node, "renesas,no-can-fd"))
fdmode = false; /* Classical CAN only mode */
...
if (of_property_read_bool(dev->of_node, "renesas,fd-only"))
gpriv->fd_only_mode = true; /* FD-Only mode for CAN-FD */
Suppose renesas,no-can-fd were present on an RZ/G3S node. Then
gpriv->fdmode is false, and rcar_canfd_channel_probe() sets the channel
up as classical CAN: no CAN_CTRLMODE_FD, no data bittiming, and RFFDF
ignored on rx. The controller would still be in CAN-FD mode. Would the
software mode and the hardware mode then disagree?
With renesas,fd-only, the only effect would be that the "global
operational state" message prints "fd-only". That doesn't match the
hardware either.
The binding added earlier in this series sets renesas,no-can-fd and
renesas,fd-only to false for renesas,r9a08g045-canfd. A DT that passes
schema validation therefore can't reach this path; only a DT that breaks
the binding can.
Would it still make sense to ignore these properties, or warn about
them, when info->fixed_canfd is set? The RZ/G3L compatible added later
in the series reuses r9a08g045_hw_info and has the same behaviour.
[ ... ]
> @@ -2383,6 +2403,7 @@ static DEFINE_SIMPLE_DEV_PM_OPS(rcar_canfd_pm_ops, rcar_canfd_suspend,
>
> static const __maybe_unused struct of_device_id rcar_canfd_of_table[] = {
> { .compatible = "renesas,r8a779a0-canfd", .data = &rcar_gen4_hw_info },
> + { .compatible = "renesas,r9a08g045-canfd", .data = &r9a08g045_hw_info },
[Severity: High]
This isn't a bug introduced by this patch, but RZ/G3S can now hit a
use-after-free and double free in the probe error path.
rcar_canfd_channel_probe() publishes the channel before registering it,
and does not clear the slot if registration fails:
gpriv->ch[priv->channel] = priv;
err = register_candev(ndev);
if (err) {
...
goto fail_candev;
}
...
fail_candev:
netif_napi_del(&priv->napi);
fail:
free_candev(ndev);
priv lives in netdev_priv(ndev), so after this gpriv->ch[ch] points to
freed memory. rcar_canfd_probe() then unwinds every channel in
channels_mask, including the one that just failed:
fail_channel:
for_each_set_bit(ch, &gpriv->channels_mask, info->max_channels)
rcar_canfd_channel_remove(gpriv, ch);
The stale pointer passes the NULL check in rcar_canfd_channel_remove():
struct rcar_canfd_channel *priv = gpriv->ch[ch];
if (priv) {
unregister_candev(priv->ndev);
netif_napi_del(&priv->napi);
free_candev(priv->ndev);
}
Suppose register_candev() fails, for example with -ENOMEM from
register_netdevice() or a NETDEV_REGISTER notifier veto. Doesn't this
path read priv->ndev from freed memory, call unregister_candev() on a
netdev that was never registered, and then call free_candev() on it a
second time?
The assignment comes from commit c5048a7b2c23 ("can: rcar_canfd:
rcar_canfd_channel_probe(): register the CAN device when fully ready").
The error path dates back to commit dd3bd23eb438 ("can: rcar_canfd: Add
Renesas R-Car CAN FD driver"). Nothing later in the series changes it.
Two possible fixes: clear gpriv->ch[priv->channel] on the fail_candev
path, or assign it only after register_candev() succeeds (after checking
that no IRQ handler needs it earlier).
[Severity: High]
This is also a pre-existing issue and not introduced by this patch. Is
there a use-after-free in IRQ context during rcar_canfd_remove() that
RZ/G3S now inherits?
for_each_set_bit(ch, &gpriv->channels_mask, gpriv->info->max_channels) {
rcar_canfd_disable_channel_interrupts(gpriv->ch[ch]);
rcar_canfd_channel_remove(gpriv, ch);
}
rcar_canfd_global_deinit(gpriv, true);
rcar_canfd_disable_channel_interrupts() only clears the CCTR error
interrupt enables. It does not touch the RX FIFO RFIE bit.
rcar_canfd_channel_remove() then frees the channel but leaves
gpriv->ch[ch] and gpriv->channels_mask unchanged.
Global interrupts are only disabled afterwards, in
rcar_canfd_global_deinit(). The global IRQ handlers were requested with
devm_request_irq() and dev_id = gpriv, so they stay installed until after
remove() returns.
Consider the case where channel 0 has been freed but channel 1 is still
open and receiving. An RX FIFO interrupt for channel 1 runs
rcar_canfd_global_receive_fifo_interrupt() (g_recc on RZ/G3S and RZ/G2L)
or rcar_canfd_global_interrupt() (Gen3/Gen4). Both walk all of
channels_mask, starting with channel 0:
rcar_canfd_global_receive_fifo_interrupt()
rcar_canfd_handle_global_receive(gpriv, 0)
priv = gpriv->ch[0]; /* already freed */
sts = rcar_canfd_read(priv->base, RCANFD_RFSTS(gpriv, ridx));
Could this dereference the freed priv and perform MMIO through a base
address loaded from freed memory? The global error path also uses
priv->ndev of the freed channel and can call rcar_canfd_global_error()
on it.
Nothing later in the series addresses this. Either of these would close
the window: disable all global and per-channel interrupt sources and
synchronize the IRQs before freeing any channel, or clear gpriv->ch[ch]
and its channels_mask bit before the free.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261015015336.816543-2-mkl%40pengutronix.de
next prev parent reply other threads:[~2026-10-16 2:37 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 1:39 [PATCH net-next 0/37] pull-request: can-next 2026-10-15 Marc Kleine-Budde
2026-10-15 1:39 ` [PATCH net-next 01/37] can: dev: can_dropped_invalid_skb: drop CAN XL frames on non-CAN XL devices Marc Kleine-Budde
2026-10-15 1:57 ` netdev-bot+sinfo
2026-10-15 1:40 ` [PATCH net-next 02/37] can: raw: remove redundant NULL check before netdev_hold() Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 03/37] can: replace ARPHRD_CAN type checks with can_get_ml_priv() Marc Kleine-Budde
2026-10-16 2:37 ` netdev-bot+sashiko
2026-10-15 1:40 ` [PATCH net-next 04/37] can: proc: reset pkg_stats atomics individually Marc Kleine-Budde
2026-10-16 2:37 ` netdev-bot+sashiko
2026-10-15 1:40 ` [PATCH net-next 05/37] can: proc: remove pointers from CAN specific proc output Marc Kleine-Budde
2026-10-16 2:37 ` netdev-bot+sashiko
2026-10-15 1:40 ` [PATCH net-next 06/37] can: isotp: check the frame type, not just the length Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 07/37] can: isotp: fix filter removal race between release and netns change Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 08/37] can: bcm: " Marc Kleine-Budde
2026-10-16 2:37 ` netdev-bot+sashiko
2026-10-15 1:40 ` [PATCH net-next 09/37] can: raw: take rtnl_lock() before leaving the notifier list Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 10/37] can: skb: make echo skb freeing safe in any IRQ context Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 11/37] dt-bindings: can: renesas,rcar-canfd: Document RZ/G3S SoC Marc Kleine-Budde
2026-10-16 2:37 ` netdev-bot+sashiko
2026-10-15 1:40 ` [PATCH net-next 12/37] can: skb: make CAN skb allocation failure paths IRQ-safe Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 13/37] can: rcar_canfd: Fix typos in macro names Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 14/37] can: dev: can_put_echo_skb(): free skb on invalid echo index Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 15/37] can: rcar_canfd: Allow the CAN FD clock to be sourced from fck Marc Kleine-Budde
2026-10-16 2:37 ` netdev-bot+sashiko
2026-10-15 1:40 ` [PATCH net-next 16/37] can: rcar_canfd: Do not set registers selecting the CAN mode Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 17/37] can: rcar_canfd: Add support for Renesas RZ/G3S Marc Kleine-Budde
2026-10-16 2:37 ` netdev-bot+sashiko [this message]
2026-10-15 1:40 ` [PATCH net-next 18/37] dt-bindings: can: renesas,rcar-canfd: Restrict resets in top-level Marc Kleine-Budde
2026-10-16 2:37 ` netdev-bot+sashiko
2026-10-15 1:40 ` [PATCH net-next 19/37] dt-bindings: can: renesas,rcar-canfd: Document RZ/G3L SoC Marc Kleine-Budde
2026-10-16 2:37 ` netdev-bot+sashiko
2026-10-15 1:40 ` [PATCH net-next 20/37] can: rcar_canfd: Derive max_channels from the device tree Marc Kleine-Budde
2026-10-16 2:37 ` netdev-bot+sashiko
2026-10-15 1:40 ` [PATCH net-next 21/37] dt-bindings: net: can: convert grcan to DT schema Marc Kleine-Budde
2026-10-16 2:37 ` netdev-bot+sashiko
2026-10-15 1:40 ` [PATCH net-next 22/37] can: rcar_canfd: Add support for Renesas RZ/G3L Marc Kleine-Budde
2026-10-16 2:37 ` netdev-bot+sashiko
2026-10-15 1:40 ` [PATCH net-next 23/37] can: grcan: update the binding file reference in the driver comment Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 24/37] can: remove Softing CANcard driver Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 25/37] can: Convert to DEFINE_SIMPLE_DEV_PM_OPS() Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 26/37] can: cc770: don't discard the IRQ lookup error in probe Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 27/37] can: cc770: fix the clock divider check on the platform bus Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 28/37] can: ems_usb: use usb_kill_urb() to stop the intr URB Marc Kleine-Budde
2026-10-16 2:37 ` netdev-bot+sashiko
2026-10-15 1:40 ` [PATCH net-next 29/37] can: esd: acc_start_xmit(): avoid use-after-free of skb after can_put_echo_skb() Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 30/37] can: flexcan: flexcan_setup_stop_mode_gpr: fix OF node reference leak Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 31/37] can: kvaser_usb: refactor endpoint lookup Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 32/37] can: kvaser_usb: validate command format before parsing in hydra receive path Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 33/37] can: kvaser_pciefd: fix use-after-free in bec poll timer Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 34/37] can: mcp251xfd: mcp251xfd_probe(): reject devices without match data Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 35/37] can: sun4i_can: sun4ican_probe(): fix clk leak Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 36/37] can: ucan: fix repeated word 'is' in comment Marc Kleine-Budde
2026-10-15 1:40 ` [PATCH net-next 37/37] can: xilinx_can: set CAN FD flags on received frames Marc Kleine-Budde
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=179211822831.434549.16106222466489918568@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=davem@davemloft.net \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=kurt.van.dijck@eia.be \
--cc=linux-can@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=socketcan@hartkopp.net \
/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