* [PATCH v3] drm/imagination: Fix parameter validation in pvr_fw_object_destroy()
@ 2026-09-22 5:39 Alexandru Dadu
2026-09-22 5:49 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Alexandru Dadu @ 2026-09-22 5:39 UTC (permalink / raw)
To: Alessio Belle, Luigi Santivetti, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter
Cc: imagination, dri-devel, linux-kernel, Sashiko, Alexandru Dadu,
Donald Robson, Sarah Walker
Fix parameter validation to avoid possible NULL pointer dereference from
pvr_fw_object_destroy() when handling allocation failures.
Sashiko report:
If pvr_gem_object_create() fails in
pvr_fw_object_create_and_map_common(), fw_obj->gem is explicitly set to
NULL before jumping to the error cleanup path.
The cleanup path then calls pvr_fw_object_destroy().
Reported-by: Sashiko <sashiko-bot@kernel.org>
Link: https://lore.kernel.org/dri-devel/20260810132202.3C16D1F000E9@smtp.kernel.org/
Fixes: cc1aeedb98ad ("drm/imagination: Implement firmware infrastructure and META FW support")
Signed-off-by: Alexandru Dadu <alexandru.dadu@imgtec.com>
---
Changes in v3:
- Skimed the commit message removing redundant information.
- Refactored the parameter validation to return early.
- Link to v2: https://patch.msgid.link/20260903-fix-null-pointer-dereference-v2-1-138ff9b6f805@imgtec.com
Changes in v2:
- Commit message and cover letter updates.
- Link to v1: https://patch.msgid.link/20260812-fix-null-pointer-dereference-v1-1-f69b2ffe9520@imgtec.com
To: Alessio Belle <alessio.belle@imgtec.com>
To: Luigi Santivetti <luigi.santivetti@imgtec.com>
To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
To: Maxime Ripard <mripard@kernel.org>
To: Thomas Zimmermann <tzimmermann@suse.de>
To: David Airlie <airlied@gmail.com>
To: Simona Vetter <simona@ffwll.ch>
To: Donald Robson <donald.robson@imgtec.com>
To: Sarah Walker <sarah.walker@imgtec.com>
Cc: imagination@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
---
drivers/gpu/drm/imagination/pvr_fw.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/imagination/pvr_fw.c b/drivers/gpu/drm/imagination/pvr_fw.c
index 850a3ec8e775..9977f4da3d8d 100644
--- a/drivers/gpu/drm/imagination/pvr_fw.c
+++ b/drivers/gpu/drm/imagination/pvr_fw.c
@@ -1429,6 +1429,12 @@ void pvr_fw_object_destroy(struct pvr_fw_object *fw_obj)
struct drm_gem_object *gem_obj = gem_from_pvr_gem(pvr_obj);
struct pvr_device *pvr_dev = to_pvr_device(gem_obj->dev);
+ if (!fw_obj)
+ return;
+
+ if (!fw_obj->gem)
+ return;
+
mutex_lock(&pvr_dev->fw_dev.fw_objs.lock);
list_del(&fw_obj->node);
mutex_unlock(&pvr_dev->fw_dev.fw_objs.lock);
@@ -1439,8 +1445,7 @@ void pvr_fw_object_destroy(struct pvr_fw_object *fw_obj)
return;
}
- if (fw_obj->gem)
- pvr_gem_object_put(fw_obj->gem);
+ pvr_gem_object_put(fw_obj->gem);
kfree(fw_obj);
}
---
base-commit: bd4f284df04d76fd65e57141cb1e6e7a49e4c3cb
change-id: 20260812-fix-null-pointer-dereference-2c891142d988
Best regards,
--
Alexandru Dadu <alexandru.dadu@imgtec.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] drm/imagination: Fix parameter validation in pvr_fw_object_destroy()
2026-09-22 5:39 [PATCH v3] drm/imagination: Fix parameter validation in pvr_fw_object_destroy() Alexandru Dadu
@ 2026-09-22 5:49 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-09-22 5:49 UTC (permalink / raw)
To: Alexandru Dadu; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] drm/imagination: memory leak of fw_obj on allocation error path
--
commit f0dd8a6ab034ccbc4cdc49ac4cbb537593b10a6d
Author: Alexandru Dadu <alexandru.dadu@imgtec.com>
Subject: drm/imagination: Fix parameter validation in pvr_fw_object_destroy()
This patch attempts to fix a possible NULL pointer dereference in
pvr_fw_object_destroy() when handling allocation failures in
pvr_fw_object_create_and_map_common() by returning early.
Link: https://lore.kernel.org/dri-devel/20260810132202.3C16D1F000E9@smtp.kernel.org/
> diff --git a/drivers/gpu/drm/imagination/pvr_fw.c b/drivers/gpu/drm/imagination/pvr_fw.c
> index 850a3ec8e7750..9977f4da3d8d7 100644
> --- a/drivers/gpu/drm/imagination/pvr_fw.c
> +++ b/drivers/gpu/drm/imagination/pvr_fw.c
> @@ -1429,6 +1429,12 @@ void pvr_fw_object_destroy(struct pvr_fw_object *fw_obj)
> struct drm_gem_object *gem_obj = gem_from_pvr_gem(pvr_obj);
> struct pvr_device *pvr_dev = to_pvr_device(gem_obj->dev);
>
> + if (!fw_obj)
> + return;
> +
> + if (!fw_obj->gem)
> + return;
[Severity: High]
Does this code leave the original NULL pointer dereference unfixed?
Since the local variables gem_obj and pvr_dev are declared and initialized
before these new early returns, fw_obj and fw_obj->gem are implicitly
dereferenced by accessing gem_obj->dev before the check is ever reached.
If either is NULL, an oops will still occur at the start of the function.
[ ... ]
> @@ -1439,8 +1445,7 @@ void pvr_fw_object_destroy(struct pvr_fw_object *fw_obj)
> return;
> }
>
> - if (fw_obj->gem)
> - pvr_gem_object_put(fw_obj->gem);
> + pvr_gem_object_put(fw_obj->gem);
>
> kfree(fw_obj);
[Severity: High]
Could the early return added above cause a memory leak regression?
In pvr_fw_object_create_and_map_common(), if pvr_gem_object_create() fails,
fw_obj->gem is set to NULL and the error cleanup path calls
pvr_fw_object_destroy().
The new early return for !fw_obj->gem skips this kfree(fw_obj) at the end of
the function, permanently leaking the firmware object structure.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260922-fix-null-pointer-dereference-v3-1-f099763ed676@imgtec.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-22 5:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-22 5:39 [PATCH v3] drm/imagination: Fix parameter validation in pvr_fw_object_destroy() Alexandru Dadu
2026-09-22 5:49 ` sashiko-bot
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.