From: sashiko-bot@kernel.org
To: "Gregor Herburger" <gregor.herburger@linutronix.de>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v9 05/12] nvmem: Add the Raspberry Pi OTP driver
Date: Wed, 11 Nov 2026 07:53:13 +0000 [thread overview]
Message-ID: <sashiko-outbox-208548@kernel.org> (raw)
In-Reply-To: <20261111-rpi-otp-driver-v9-5-0a7292a7a5b4@linutronix.de>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] nvmem: raspberrypi-otp: unvalidated fwbuf->count in
rpi_otp_read()
--
commit 5f43735ea021896029b9b0fd1aee1fb3cdeb2562
Author: Gregor Herburger <gregor.herburger@linutronix.de>
nvmem: Add the Raspberry Pi OTP driver
This commit adds an nvmem driver to access Raspberry Pi OTP registers
through the VideoCore firmware.
> diff --git a/drivers/nvmem/raspberrypi-otp.c b/drivers/nvmem/raspberrypi-otp.c
> new file mode 100644
> index 0000000000000..2c632781f6003
> --- /dev/null
> +++ b/drivers/nvmem/raspberrypi-otp.c
> @@ -0,0 +1,131 @@
[ ... ]
> +struct rpi_otp_header {
> + __le32 start;
> + __le32 count;
> + __le32 data[] __counted_by_le(count);
> +};
> +
> +static int rpi_otp_read(void *context, unsigned int offset, void *buf, size_t bytes)
> +{
> + struct rpi_otp_priv *priv = context;
> + struct rpi_otp_header *fwbuf;
> + u32 count;
> + int ret;
> +
> + count = bytes / 4;
> +
> + fwbuf = kzalloc(struct_size(fwbuf, data, count), GFP_KERNEL);
> + if (!fwbuf)
> + return -ENOMEM;
> +
> + fwbuf->start = cpu_to_le32(offset / 4);
> + fwbuf->count = cpu_to_le32(count);
> +
> + ret = rpi_firmware_property(priv->fw, priv->read_tag, fwbuf,
> + sizeof(struct rpi_otp_header) + bytes);
> + if (ret)
> + goto out;
> +
> + memcpy(buf, fwbuf->data, le32_to_cpu(fwbuf->count) * 4);
[Severity: High]
Can this overflow buf or leave part of it uninitialized if the firmware
modifies fwbuf->count?
rpi_firmware_property() overwrites fwbuf in-place with the response
payload, including fwbuf->count. Because fwbuf->data is marked
__counted_by_le(count), updating fwbuf->count also changes the dynamic
object size seen by fortify checks.
If the firmware returns a count larger than the requested count (such as
0xffffffff on error), memcpy() reads past fwbuf->data and overflows the
bytes-sized destination buffer buf. If it returns a smaller count,
memcpy() only partially fills buf while rpi_otp_read() still returns 0,
exposing uninitialized heap memory to callers such as bin_attr_nvmem_read().
Validating that le32_to_cpu(fwbuf->count) == count before copying (or
copying bytes after checking) would avoid both issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261111-rpi-otp-driver-v9-0-0a7292a7a5b4@linutronix.de?part=5
next prev parent reply other threads:[~2026-11-11 7:53 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 7:23 [PATCH v9 00/12] nvmem: Add Raspberry Pi OTP nvmem driver Gregor Herburger
2026-11-11 7:23 ` [PATCH v9 01/12] firmware: raspberrypi: reorder rpi_firmware_property_tag enum Gregor Herburger
2026-11-11 7:23 ` [PATCH v9 02/12] soc: bcm2835: Use IS_REACHABLE for function declaration Gregor Herburger
2026-11-11 7:23 ` [PATCH v9 03/12] nvmem: core: Enforce stride and alignment checks for nvmem_device functions Gregor Herburger
2026-11-11 7:23 ` [PATCH v9 04/12] dt-bindings: raspberrypi,bcm2835-firmware: Add bcm2712-firmware compatible Gregor Herburger
2026-11-11 7:23 ` [PATCH v9 05/12] nvmem: Add the Raspberry Pi OTP driver Gregor Herburger
2026-11-11 7:53 ` sashiko-bot [this message]
2026-11-11 7:23 ` [PATCH v9 06/12] firmware: raspberrypi: register nvmem driver Gregor Herburger
2026-11-11 7:23 ` [PATCH v9 07/12] arm64: dts: broadcom: bcm2712: add raspberrypi,bcm2712-firmware compatible Gregor Herburger
2026-11-11 7:23 ` [PATCH v9 08/12] dt-bindings: raspberrypi,bcm2835-firmware: Drop unnecessary select Gregor Herburger
2026-11-11 7:23 ` [PATCH v9 09/12] arm64: defconfig: Enable the raspberrypi otp driver as module Gregor Herburger
2026-11-11 7:23 ` [PATCH v9 10/12] ARM: bcm2835_defconfig: " Gregor Herburger
2026-11-11 7:23 ` [PATCH v9 11/12] ARM: multi_v7_defconfig: " Gregor Herburger
2026-11-11 7:23 ` [PATCH v9 12/12] firmware: raspberrypi: use drvdata to register rtc driver Gregor Herburger
2026-11-11 8:02 ` [PATCH v9 00/12] nvmem: Add Raspberry Pi OTP nvmem driver Krzysztof Kozlowski
2026-11-11 8:14 ` Gregor Herburger
2026-11-11 15:30 ` Rob Herring
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-208548@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