From: sashiko-bot@kernel.org
To: "Alexandru Dadu" <alexandru.dadu@imgtec.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 3/6] drm/imagination: Save metadata from firmware
Date: Wed, 02 Dec 2026 06:49:59 +0000 [thread overview]
Message-ID: <sashiko-outbox-244999@kernel.org> (raw)
In-Reply-To: <20261202-b4-commonize-fw-segment-loading-v2-3-45fd5153c040@imgtec.com>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] drm/imagination: undefined pvr_exp_fw_support in
pvr_fw_load_version()
- [Medium] drm/imagination: UAF and NULL deref of metadata in
pvr_fw_info_get()
- [Low] drm/imagination: misplaced parenthesis in
pvr_fw_info_header_validate()
--
commit b39417857398d201ed66dd9476480df29442e140
Author: Matt Coster <opensource@mtcoster.net>
drm/imagination: Save metadata from firmware
This commit extracts firmware version and section layout metadata from the
firmware header into an allocated struct pvr_fw_metadata during device
initialization.
> diff --git a/drivers/gpu/drm/imagination/pvr_fw.c b/drivers/gpu/drm/imagination/pvr_fw.c
> index cbde54c7291c7..2a5dcd9aeed71 100644
> --- a/drivers/gpu/drm/imagination/pvr_fw.c
> +++ b/drivers/gpu/drm/imagination/pvr_fw.c
[ ... ]
> @@ -1549,8 +1387,8 @@ pvr_fw_info_get(const struct pvr_device *pvr_dev,
> if (fw_info._padding_4)
> return -EINVAL;
>
> - fw_info.major_version = pvr_dev->fw_version.major;
> - fw_info.minor_version = pvr_dev->fw_version.minor;
> + fw_info.major_version = pvr_dev->fw_dev.metadata->version.major;
> + fw_info.minor_version = pvr_dev->fw_dev.metadata->version.minor;
>
> err = PVR_UOBJ_SET(args->pointer, args->size, fw_info);
> if (err < 0)
[Severity: Medium]
Can pvr_fw_info_get() trigger a use-after-free or NULL pointer dereference
on pvr_dev->fw_dev.metadata during device removal?
Previously, pvr_fw_info_get() read pvr_dev->fw_version, which lived inside
struct pvr_device for the lifetime of the DRM device. With this change,
pvr_fw_free_metadata_and_device_info() frees and clears
pvr_dev->fw_dev.metadata during pvr_device_fini(), which pvr_remove() runs
before drm_dev_unplug():
CPU0 CPU1
pvr_remove() pvr_ioctl_dev_query()
drm_dev_enter()
pvr_device_fini()
...
pvr_fw_free_metadata_and_device_info()
kfree(pvr_dev->fw_dev.metadata)
pvr_dev->fw_dev.metadata = NULL
pvr_fw_info_get()
pvr_dev->fw_dev.metadata->version
<-- use-after-free / NULL deref
drm_dev_unplug()
> diff --git a/drivers/gpu/drm/imagination/pvr_fw.h b/drivers/gpu/drm/imagination/pvr_fw.h
> index dab8292a84791..51acefde73ee2 100644
> --- a/drivers/gpu/drm/imagination/pvr_fw.h
> +++ b/drivers/gpu/drm/imagination/pvr_fw.h
> @@ -23,6 +22,30 @@ struct pvr_vm_context;
>
> #define ROGUE_FWIF_KCCB_NUMCMDS_LOG2_DEFAULT 7
>
> +extern bool pvr_exp_fw_support;
[ ... ]
> diff --git a/drivers/gpu/drm/imagination/pvr_fw_info.c b/drivers/gpu/drm/imagination/pvr_fw_info.c
> new file mode 100644
> index 0000000000000..b0f2dad91fc32
> --- /dev/null
> +++ b/drivers/gpu/drm/imagination/pvr_fw_info.c
> @@ -0,0 +1,345 @@
[ ... ]
> +static bool
> +pvr_fw_load_version(struct pvr_device *pvr_dev,
> + const struct pvr_fw_info_header *header,
> + struct pvr_fw_version *version_out)
> +{
> + struct drm_device *drm_dev = from_pvr_device(pvr_dev);
> + bool invalid = false;
> +
> + struct pvr_fw_version version = {
> + .major = header->fw_version_major,
> + .minor = header->fw_version_minor,
> + .build = header->fw_version_build,
> + .open_source = header->flags & PVR_FW_FLAGS_OPEN_SOURCE,
> + };
> +
> + if (!version.open_source) {
> + drm_err(drm_dev, "Firmware is not open-source compatible (found version " PVR_FW_VERSION_FMT ")\n",
> + PVR_FW_VERSION_FMT_ARGS(&version));
> + invalid = true;
> + }
> +
> + if (version.major == 0 ||
> + (version.major > PVR_FW_MAX_SUPPORTED_MAJOR_VERSION && !pvr_exp_fw_support) ||
> + (version.major != PVR_FW_MAX_SUPPORTED_MAJOR_VERSION && pvr_exp_fw_support)) {
> + drm_err(drm_dev, "Firmware version is unsupported (known range is 1..%u inclusive, found "
> + PVR_FW_VERSION_FMT ")\n",
> + PVR_FW_MAX_SUPPORTED_MAJOR_VERSION,
> + PVR_FW_VERSION_FMT_ARGS(&version));
> + invalid = true;
> + }
[Severity: High]
As reported by kernel test robot on v1 [1], is the definition of
pvr_exp_fw_support missing? Nothing in the tree defines it, so linking
vmlinux or modpost for powervr.ko fails with an undefined symbol error.
Also, when pvr_exp_fw_support is true, the check rejects any
version.major != PVR_FW_MAX_SUPPORTED_MAJOR_VERSION, which blocks
experimental firmware major versions above PVR_FW_MAX_SUPPORTED_MAJOR_VERSION
instead of allowing them.
> +
> + if (invalid)
> + return false;
> +
> + *version_out = version;
> + return true;
> +}
> +
> +static int
> +pvr_fw_info_header_validate(struct pvr_device *pvr_dev,
> + const struct pvr_fw_info_header *header,
> + struct pvr_fw_version *fw_version_out)
> +{
> + struct drm_device *drm_dev = from_pvr_device(pvr_dev);
> + bool invalid = false;
> +
> + if (header->info_version != PVR_FW_INFO_VERSION) {
> + drm_err(drm_dev,
> + "Firmware version is unsupported (known version is %u, found %u)\n",
> + PVR_FW_INFO_VERSION, header->info_version);
> + return -EINVAL;
> + }
> +
> + if (header->header_len != sizeof(struct pvr_fw_info_header)) {
> + drm_err(drm_dev, "Firmware header size mismatch (found=%u, expected=%zu)\n)",
> + header->header_len, sizeof(struct pvr_fw_info_header));
> + return -EINVAL;
> + }
> +
> + if (!header->layout_entry_num || !header->layout_entry_size) {
> + drm_err(drm_dev, "Firmware layout table missing\n");
> + invalid = true;
> + } else if (header->layout_entry_size != sizeof(struct pvr_fw_layout_entry)) {
> + drm_err(drm_dev,
> + "Firmware layout table entry size mismatch (found=%u, expected=%zu)\n)",
> + header->layout_entry_size, sizeof(struct pvr_fw_layout_entry));
> + invalid = true;
> + } else if (header->layout_entry_num > PVR_FW_INFO_MAX_NUM_ENTRIES) {
> + drm_err(drm_dev, "Firmware layout table is too large (found=%u, max=%u)\n)",
> + header->layout_entry_num, PVR_FW_INFO_MAX_NUM_ENTRIES);
> + invalid = true;
[Severity: Low]
These three drm_err() format strings end with "\n)" instead of ")\n", which
prints the closing parenthesis on the next log line.
[1] https://lore.kernel.org/r/20261126130340.K8Rznt4t-lkp@intel.com
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-b4-commonize-fw-segment-loading-v2-0-45fd5153c040@imgtec.com?part=3
next prev parent reply other threads:[~2026-12-02 6:50 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 6:34 [PATCH v2 0/6] drm/imagination: Commonize firmware segment loading Alexandru Dadu
2026-12-02 6:34 ` Alexandru Dadu
2026-12-02 6:34 ` [PATCH v2 1/6] drm/imagination: Remove get_fw_obj_gpu_addr() Alexandru Dadu
2026-12-02 6:34 ` Alexandru Dadu
2026-12-02 6:34 ` [PATCH v2 2/6] drm/imagination: Fix size of FW header members Alexandru Dadu
2026-12-02 6:34 ` Alexandru Dadu
2026-12-02 6:34 ` [PATCH v2 3/6] drm/imagination: Save metadata from firmware Alexandru Dadu
2026-12-02 6:34 ` Alexandru Dadu
2026-12-02 6:49 ` sashiko-bot [this message]
2026-12-02 6:34 ` [PATCH v2 4/6] drm/imagination: Release firmware after init Alexandru Dadu
2026-12-02 6:34 ` Alexandru Dadu
2026-12-02 6:34 ` [PATCH v2 5/6] drm/imagination: Generalize FW segment loading Alexandru Dadu
2026-12-02 6:34 ` Alexandru Dadu
2026-12-02 6:34 ` [PATCH v2 6/6] drm/imagination: Avoid loop in configure_seg_mmu() Alexandru Dadu
2026-12-02 6:34 ` Alexandru Dadu
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-244999@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=alexandru.dadu@imgtec.com \
--cc=dri-devel@lists.freedesktop.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.