Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Gregor Herburger" <gregor.herburger@linutronix.de>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v3 3/4] firmware: raspberrypi: Add reboot mode support
Date: Tue, 07 Jul 2026 14:40:02 +0000	[thread overview]
Message-ID: <20260707144002.C1F7F1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260707-rpi-tryboot-v3-3-fda82fe7ed76@linutronix.de>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] TOCTOU race in `rpi_firmware_get` allows `kref_get_unless_zero` to execute on freed memory during concurrent driver unbinding.
--

--- Patch [3]: [PATCH v3 3/4] firmware: raspberrypi: Add reboot mode support ---
commit 0477b96e458c7ecca585d15b527bfef8d16f88fc
Author: Gregor Herburger <gregor.herburger@linutronix.de>
Subject: firmware: raspberrypi: Add reboot mode support

This commit adds tryboot mode support to the Raspberry Pi firmware driver to
enable an A/B update scheme. It registers a reboot mode driver to send the
RPI_FIRMWARE_SET_REBOOT_FLAGS message. Additionally, it transitions the
firmware context teardown to be devres-managed to safely register the reboot
mode.

> diff --git a/drivers/firmware/raspberrypi.c b/drivers/firmware/raspberrypi.c
> index 0aa322e9a2e73..2a0c40b8052e5 100644
> --- a/drivers/firmware/raspberrypi.c
> +++ b/drivers/firmware/raspberrypi.c
[ ... ]
> @@ -302,9 +331,14 @@ static int rpi_firmware_probe(struct platform_device *pdev)
>  
>  	platform_set_drvdata(pdev, fw);
>  
> +	ret = devm_add_action_or_reset(dev, devm_rpi_firmware_put, fw);
> +	if (ret)
> +		return ret;
> +

[Severity: High]
This is a pre-existing issue, but modifying the teardown sequence brings up a
question about rpi_firmware_get().

Can a concurrent driver unbind and probe trigger a use-after-free in
rpi_firmware_get()?

If a privileged user triggers unbinding, the driver core executes
device_unbind_cleanup(). This calls devres_release_all(), which now triggers
devm_rpi_firmware_put(), dropping the kref to 0 and freeing the fw object.
Crucially, the driver core clears the drvdata after devres_release_all().

If another thread concurrently probes a dependent driver, rpi_firmware_get()
could locklessly read the drvdata pointer before it is cleared:

drivers/firmware/raspberrypi.c:rpi_firmware_get() {
    ...
    fw = platform_get_drvdata(pdev);
    if (!fw)
        goto err_put_device;

    if (!kref_get_unless_zero(&fw->consumers))
        goto err_put_device;
    ...
}

Since fw could already be freed by devm_rpi_firmware_put(), passing it to
kref_get_unless_zero() would access freed memory. Does the retrieval of
drvdata need synchronization to protect against concurrent unbinding?

>  	rpi_firmware_print_firmware_revision(fw);
>  	rpi_register_hwmon_driver(dev, fw);
>  	rpi_register_clk_driver(dev);
> +	rpi_register_reboot_mode(dev, fw);
>  
>  	return 0;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260707-rpi-tryboot-v3-0-fda82fe7ed76@linutronix.de?part=3

  reply	other threads:[~2026-07-07 14:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07 14:20 [PATCH v3 0/4] firmware: raspberrypi: Add support for the tryboot mode Gregor Herburger
2026-07-07 14:20 ` [PATCH v3 1/4] firmware: raspberrypi: reorder rpi_firmware_property_tag enum Gregor Herburger
2026-07-07 14:20 ` [PATCH v3 2/4] dt-bindings: raspberrypi,bcm2835-firmware: Include 'reboot-mode.yaml' Gregor Herburger
2026-07-07 14:20 ` [PATCH v3 3/4] firmware: raspberrypi: Add reboot mode support Gregor Herburger
2026-07-07 14:40   ` sashiko-bot [this message]
2026-07-07 14:20 ` [PATCH v3 4/4] arm64: dts: broadcom: bcm2712: Add reboot modes to firmware node Gregor Herburger

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=20260707144002.C1F7F1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gregor.herburger@linutronix.de \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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