From: sashiko-bot@kernel.org
To: "Ketil Johnsen" <ketil.johnsen@arm.com>
Cc: dri-devel@lists.freedesktop.org, ojeda@kernel.org, gary@garyguo.net
Subject: Re: [PATCH v5 11/13] drm/panthor: Support FW init of protm
Date: Mon, 16 Nov 2026 11:51:00 +0000 [thread overview]
Message-ID: <sashiko-outbox-216960@kernel.org> (raw)
In-Reply-To: <20261116112601.3483649-12-ketil.johnsen@arm.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] drm/panthor: NULL pointer dereference in
panthor_fw_query_protm_info()
- [Medium] drm/panthor: UAF or NULL dereference of fw->vm outside
drm_dev_enter()
- [Low] drm/panthor: missing kernel-doc for protm member in struct
panthor_fw
- [Low] drm/panthor: NULL shared_section->mem in
panthor_fw_load_section_entry()
--
commit 5ac4027cd6058f1c3359662cdf5433f1c22a832b
Author: Boris Brezillon <boris.brezillon@collabora.com>
drm/panthor: Support FW init of protm
This commit adds UAPI and firmware support to query protected mode
information and initialize the protected firmware section from a
userspace-supplied GEM buffer object.
> diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c
> index b565b362f401f..af86b1844ead8 100644
> --- a/drivers/gpu/drm/panthor/panthor_fw.c
> +++ b/drivers/gpu/drm/panthor/panthor_fw.c
[ ... ]
> @@ -267,6 +269,18 @@ struct panthor_fw {
> struct delayed_work ping_work;
> } watchdog;
>
> + struct {
> + /** @protm.init_lock: Used to serialize protm initialization. */
> + struct mutex init_lock;
> +
> + /** @protm.inited: set to true when protm.section is initialized */
> + bool inited;
> +
> + /** @protm.section: The protected mode section. */
> + struct panthor_fw_section *section;
> +
> + } protm;
[Severity: Low]
This isn't a bug, but struct panthor_fw has a kernel-doc comment block and
protm is missing its top-level @protm description, which triggers a
kernel-doc warning with W=1 builds.
[ ... ]
> @@ -637,12 +659,6 @@ static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
> return -EINVAL;
> }
>
> - if (hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_PROT) {
> - drm_warn(&ptdev->base,
> - "Firmware protected mode entry is not supported, ignoring");
> - return 0;
> - }
> -
> if (hdr.va.start == CSF_MCU_SHARED_REGION_START &&
> !(hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_SHARED)) {
> drm_err(&ptdev->base,
> @@ -694,7 +710,22 @@ static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
> section->size = section_size;
> section->va = hdr.va.start;
>
> - if (section_size) {
> + if (hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_PROT) {
> + guard(mutex)(&ptdev->fw->protm.init_lock);
> +
> + if (ptdev->fw->protm.section) {
> + drm_err(&ptdev->base,
> + "Only one protected section supported\n");
> + return -EINVAL;
> + }
> +
> + ptdev->fw->protm.section = section;
> + }
> +
> + /* Defer the section->mem creation if this is a protected entry.
> + * This will be populated when DRM_IOCTL_PANTHOR_PROTM_INIT is called.
> + */
> + if (section->size && !(hdr.flags & CSF_FW_BINARY_IFACE_ENTRY_PROT)) {
> u32 vm_map_flags = section_vm_map_flags(section);
>
> section->mem = panthor_kernel_bo_create(
[Severity: Low]
Can a malformed firmware binary cause a NULL pointer dereference of
ptdev->fw->shared_section->mem in panthor_fw_init_ifaces()?
If an entry at CSF_MCU_SHARED_REGION_START has both
CSF_FW_BINARY_IFACE_ENTRY_SHARED and CSF_FW_BINARY_IFACE_ENTRY_PROT set,
panthor_fw_load_section_entry() skips allocating section->mem and still
assigns ptdev->fw->shared_section = section, which
panthor_fw_init_ifaces() then dereferences via panthor_kernel_bo_size().
Rejecting CSF_FW_BINARY_IFACE_ENTRY_PROT when
CSF_FW_BINARY_IFACE_ENTRY_SHARED is set would prevent this.
[ ... ]
> @@ -1610,6 +1641,101 @@ int panthor_fw_protm_exit(struct panthor_device *ptdev, u32 timeout_ms)
> return panthor_fw_protm_exit_wait(ptdev, timeout_ms);
> }
>
> +int panthor_fw_protm_init(struct drm_file *file,
> + struct drm_panthor_protm_init *args)
> +{
> + struct panthor_file *pfile = file->driver_priv;
> + struct panthor_device *ptdev = pfile->ptdev;
> + ssize_t vm_pgsz = panthor_vm_page_size(ptdev->fw->vm);
> + struct panthor_fw_section *protm_section;
> + struct panthor_kernel_bo *mem;
> + struct drm_gem_object *obj;
> + u32 vm_map_flags;
> + int cookie, ret = 0;
> +
> + if (!capable(CAP_SYS_MODULE))
> + return -EPERM;
> +
> + if (args->pad)
> + return -EINVAL;
> +
> + mutex_lock(&ptdev->fw->protm.init_lock);
> +
> + protm_section = ptdev->fw->protm.section;
> +
> + if (!protm_section || !protm_section->size) {
> + ret = -EINVAL;
> + goto out_unlock;
> + }
> +
> + if (ptdev->fw->protm.inited)
> + goto out_unlock;
> +
> + if (!drm_dev_enter(&ptdev->base, &cookie)) {
> + ret = -ENODEV;
> + goto out_unlock;
> + }
[Severity: Medium]
Can calling panthor_vm_page_size(ptdev->fw->vm) before drm_dev_enter() here
(and without drm_dev_enter() in panthor_fw_query_protm_info() below) cause
a use-after-free or NULL pointer dereference if the device is unplugged
concurrently?
CPU0 CPU1
drm_ioctl_kernel()
panthor_ioctl_protm_init()
panthor_fw_protm_init()
panthor_device_unplug()
drm_dev_unplug(&ptdev->base)
panthor_fw_unplug(ptdev)
panthor_vm_put(ptdev->fw->vm)
ptdev->fw->vm = NULL
panthor_vm_page_size(ptdev->fw->vm)
<-- NULL / UAF dereference
...
drm_dev_enter(&ptdev->base, &cookie)
Evaluating panthor_vm_page_size(ptdev->fw->vm) only inside a
drm_dev_enter() section in both functions would avoid racing with
panthor_fw_unplug().
> +
> + obj = drm_gem_object_lookup(file,
> + args->fw_protected_sections_bo_handle);
> + if (!obj) {
> + ret = -ENOENT;
> + goto out_dev_exit;
> + }
> +
> + if (obj->size < ALIGN(ptdev->fw->protm.section->size, vm_pgsz)) {
> + ret = -EINVAL;
> + goto out_gem_put;
> + }
> +
> + vm_map_flags = section_vm_map_flags(protm_section);
> +
> + mem = panthor_kernel_bo_create_from_gem(
> + ptdev, panthor_fw_vm(ptdev), to_panthor_bo(obj), vm_map_flags,
> + protm_section->va, protm_section->size);
> + if (IS_ERR(mem)) {
> + ret = PTR_ERR(mem);
> + goto out_gem_put;
> + }
> +
> + protm_section->mem = mem;
> +
> + ptdev->fw->protm.inited = true;
> +
> +out_gem_put:
> + drm_gem_object_put(obj);
> +
> +out_dev_exit:
> + drm_dev_exit(cookie);
> +
> +out_unlock:
> + mutex_unlock(&ptdev->fw->protm.init_lock);
> +
> + return ret;
> +}
> +
> +bool panthor_fw_protm_is_inited(struct panthor_device *ptdev)
> +{
> + guard(mutex)(&ptdev->fw->protm.init_lock);
> + return ptdev->fw->protm.inited;
> +}
> +
> +void panthor_fw_query_protm_info(struct drm_file *file,
> + struct drm_panthor_protm_info *arg)
> +{
> + struct panthor_file *pfile = file->driver_priv;
> + struct panthor_device *ptdev = pfile->ptdev;
> + ssize_t vm_pgsz = panthor_vm_page_size(ptdev->fw->vm);
> +
> + guard(mutex)(&ptdev->fw->protm.init_lock);
> +
> + memset(arg, 0, sizeof(*arg));
> + arg->state = ptdev->fw->protm.inited ? DRM_PANTHOR_PROTM_INITIALIZED : 0;
> + arg->group_protected_suspend_buf_size = ptdev->fw->protm_suspend_size;
> + arg->fw_protected_sections_size = ALIGN(ptdev->fw->protm.section->size,
> + vm_pgsz);
> +}
[Severity: High]
Does panthor_fw_query_protm_info() dereference a NULL
ptdev->fw->protm.section when the loaded firmware has no protected section?
Unlike panthor_fw_protm_init(), which checks whether protm_section is NULL,
querying DRM_PANTHOR_DEV_QUERY_PROTM_INFO unconditionally reads
ptdev->fw->protm.section->size, allowing any user with render node access
to trigger a kernel NULL pointer dereference if the firmware binary lacks a
non-empty CSF_FW_BINARY_IFACE_ENTRY_PROT entry.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116112601.3483649-1-ketil.johnsen@arm.com?part=11
next prev parent reply other threads:[~2026-11-16 11:51 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 11:25 [PATCH v5 00/13] drm/panthor: Protected mode support for Mali CSF GPUs Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 01/13] drm/panthor: De-duplicate FW memory section sync Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 02/13] drm/panthor: Minor scheduler refactoring Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 03/13] drm/panthor: Pass drm_file instead of panthor_file Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 04/13] drm/panthor: Don't allocate protm_suspend_buf Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 05/13] drm/panthor: Add support for entering and exiting protected mode Ketil Johnsen
2026-11-16 12:12 ` sashiko-bot
2026-11-16 11:25 ` [PATCH v5 06/13] drm/panthor: New function for FW section map flags Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 07/13] drm/panthor: Keep size and VA in FW section obj Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 08/13] drm/panthor: Refactor GEM usage flags assignment Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 09/13] drm/panthor: Create kernel BO from existing GEM Ketil Johnsen
2026-11-16 11:25 ` [PATCH v5 10/13] drm/panthor: Use a copy of suspend buffer sizes Ketil Johnsen
2026-11-16 11:37 ` sashiko-bot
2026-11-16 11:25 ` [PATCH v5 11/13] drm/panthor: Support FW init of protm Ketil Johnsen
2026-11-16 11:51 ` sashiko-bot [this message]
2026-11-16 18:00 ` kernel test robot
2026-11-16 11:26 ` [PATCH v5 12/13] drm/panthor: Protm support for groups Ketil Johnsen
2026-11-16 12:05 ` sashiko-bot
2026-11-16 11:26 ` [PATCH v5 13/13] drm/panthor: Bump version to expose protm feature Ketil Johnsen
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-216960@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=ketil.johnsen@arm.com \
--cc=ojeda@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 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.