* [PATCH] drm/imagination: Destroy the common FW object when HWRT data setup fails
@ 2026-11-21 15:29 ` Suyuan Wang via B4 Relay
0 siblings, 0 replies; 3+ messages in thread
From: Suyuan Wang @ 2026-11-21 15:29 UTC (permalink / raw)
To: luigi.santivetti, alessio.belle
Cc: linux-kernel, dri-devel, maarten.lankhorst, tzimmermann, airlied,
imagination, simona, mripard, donald.robson
From: Suyuan Wang <stevewong@hust.edu.cn>
If hwrt_data_init_fw_structure() fails in pvr_hwrt_dataset_create(),
the error path frees the per-data FW structures and then jumps straight
to err_fini_kernel_structure, skipping hwrt_fini_common_fw_structure().
The common FW object created just before is never destroyed, and its
init callback data is the hwrt that is then freed:
err = pvr_fw_object_create(pvr_dev, ...,
hwrtdata_common_init, hwrt,
&hwrt->common_fw_obj);
Besides leaking the object, this leaves it on the device's FW object
list, so a later pvr_fw_hard_reset() calls hwrtdata_common_init() with
the freed hwrt, and pvr_fw_fini() warns that the list is not empty.
Destroy the common FW object on that path, in the same order as
pvr_hwrt_dataset_release().
Found with a static analysis tool and checked by hand.
Fixes: 6eedddab733b ("drm/imagination: Implement free list and HWRT create and destroy ioctls")
Cc: stable@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
Compile tested on arm64 with clang (W=1, no new warnings). I don't have PowerVR hardware.
---
drivers/gpu/drm/imagination/pvr_hwrt.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/gpu/drm/imagination/pvr_hwrt.c b/drivers/gpu/drm/imagination/pvr_hwrt.c
index 05c68c78da22..6057f8dd1eaf 100644
--- a/drivers/gpu/drm/imagination/pvr_hwrt.c
+++ b/drivers/gpu/drm/imagination/pvr_hwrt.c
@@ -487,6 +487,8 @@ pvr_hwrt_dataset_create(struct pvr_file *pvr_file,
while (--i >= 0)
hwrt_data_fini_fw_structure(hwrt, i);
+ hwrt_fini_common_fw_structure(hwrt);
+
err_fini_kernel_structure:
hwrt_fini_kernel_structure(hwrt);
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH] drm/imagination: Destroy the common FW object when HWRT data setup fails
@ 2026-11-21 15:29 ` Suyuan Wang via B4 Relay
0 siblings, 0 replies; 3+ messages in thread
From: Suyuan Wang via B4 Relay @ 2026-11-21 15:29 UTC (permalink / raw)
To: luigi.santivetti, alessio.belle
Cc: linux-kernel, dri-devel, maarten.lankhorst, tzimmermann, airlied,
imagination, simona, mripard, donald.robson
From: Suyuan Wang <stevewong@hust.edu.cn>
If hwrt_data_init_fw_structure() fails in pvr_hwrt_dataset_create(),
the error path frees the per-data FW structures and then jumps straight
to err_fini_kernel_structure, skipping hwrt_fini_common_fw_structure().
The common FW object created just before is never destroyed, and its
init callback data is the hwrt that is then freed:
err = pvr_fw_object_create(pvr_dev, ...,
hwrtdata_common_init, hwrt,
&hwrt->common_fw_obj);
Besides leaking the object, this leaves it on the device's FW object
list, so a later pvr_fw_hard_reset() calls hwrtdata_common_init() with
the freed hwrt, and pvr_fw_fini() warns that the list is not empty.
Destroy the common FW object on that path, in the same order as
pvr_hwrt_dataset_release().
Found with a static analysis tool and checked by hand.
Fixes: 6eedddab733b ("drm/imagination: Implement free list and HWRT create and destroy ioctls")
Cc: stable@vger.kernel.org
Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
---
Compile tested on arm64 with clang (W=1, no new warnings). I don't have PowerVR hardware.
---
drivers/gpu/drm/imagination/pvr_hwrt.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/gpu/drm/imagination/pvr_hwrt.c b/drivers/gpu/drm/imagination/pvr_hwrt.c
index 05c68c78da22..6057f8dd1eaf 100644
--- a/drivers/gpu/drm/imagination/pvr_hwrt.c
+++ b/drivers/gpu/drm/imagination/pvr_hwrt.c
@@ -487,6 +487,8 @@ pvr_hwrt_dataset_create(struct pvr_file *pvr_file,
while (--i >= 0)
hwrt_data_fini_fw_structure(hwrt, i);
+ hwrt_fini_common_fw_structure(hwrt);
+
err_fini_kernel_structure:
hwrt_fini_kernel_structure(hwrt);
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] drm/imagination: Destroy the common FW object when HWRT data setup fails
2026-11-21 15:29 ` Suyuan Wang via B4 Relay
(?)
@ 2026-11-21 15:37 ` sashiko-bot
-1 siblings, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-21 15:37 UTC (permalink / raw)
To: Suyuan Wang; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] drm/imagination: Fixes tag in pvr_hwrt_dataset_create() cites
wrong commit
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] drm/imagination: max_rts truncation in
hwrt_init_kernel_structure() leaks BOs [1]
--
commit 7873fa00db9c4a0975eb336899ecacbc6e6d2863
Author: Suyuan Wang <stevewong@hust.edu.cn>
> drm/imagination: Destroy the common FW object when HWRT data setup fails
>
> If hwrt_data_init_fw_structure() fails in pvr_hwrt_dataset_create(),
> the error path frees the per-data FW structures and then jumps straight
> to err_fini_kernel_structure, skipping hwrt_fini_common_fw_structure().
> The common FW object created just before is never destroyed, and its
> init callback data is the hwrt that is then freed:
>
> err = pvr_fw_object_create(pvr_dev, ...,
> hwrtdata_common_init, hwrt,
> &hwrt->common_fw_obj);
>
> Besides leaking the object, this leaves it on the device's FW object
> list, so a later pvr_fw_hard_reset() calls hwrtdata_common_init() with
> the freed hwrt, and pvr_fw_fini() warns that the list is not empty.
>
> Destroy the common FW object on that path, in the same order as
> pvr_hwrt_dataset_release().
>
> Found with a static analysis tool and checked by hand.
>
> Fixes: 6eedddab733b ("drm/imagination: Implement free list and HWRT create and destroy ioctls")
> Cc: stable@vger.kernel.org
> Co-developed-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
> Signed-off-by: Kaixuan Li <kaixuan.li@ntu.edu.sg>
> Signed-off-by: Suyuan Wang <stevewong@hust.edu.cn>
[Severity: Low]
In 6eedddab733b ("drm/imagination: Implement free list and HWRT create and
destroy ioctls"), a failure in hwrt_data_init_fw_structure() jumped to
err_free and called pvr_hwrt_dataset_put(), which destroyed common_fw_obj
via pvr_hwrt_dataset_release(). The err_fini_data_structures unwind path
that omitted hwrt_fini_common_fw_structure() was introduced by
f1f55ed3ffe4 ("drm/imagination: Fixed oops when misusing ioctl
CREATE_HWRT_DATASET"). Should the Fixes tag be:
Fixes: f1f55ed3ffe4 ("drm/imagination: Fixed oops when misusing ioctl CREATE_HWRT_DATASET")
> diff --git a/drivers/gpu/drm/imagination/pvr_hwrt.c b/drivers/gpu/drm/imagination/pvr_hwrt.c
> index 05c68c78da229..6057f8dd1eaf4 100644
> --- a/drivers/gpu/drm/imagination/pvr_hwrt.c
> +++ b/drivers/gpu/drm/imagination/pvr_hwrt.c
> @@ -487,6 +487,8 @@ pvr_hwrt_dataset_create(struct pvr_file *pvr_file,
> while (--i >= 0)
> hwrt_data_fini_fw_structure(hwrt, i);
>
> + hwrt_fini_common_fw_structure(hwrt);
> +
> err_fini_kernel_structure:
> hwrt_fini_kernel_structure(hwrt);
[Severity: High]
This problem wasn't introduced by this patch, but can
hwrt_data_fini_fw_structure() still leak raa_obj and srtc_obj [1]
when args->layers is truncated into hwrt->max_rts?
hwrt_init_kernel_structure() stores the 32-bit args->layers into the u16
hwrt->max_rts field without bounds checking, while
hwrt_data_init_fw_structure() checks the untruncated args->layers:
drivers/gpu/drm/imagination/pvr_hwrt.c:hwrt_data_init_fw_structure() {
...
if (args->layers > 1) {
err = pvr_fw_object_create(pvr_dev, args->layers * SRTC_ENTRY_SIZE,
PVR_BO_FW_FLAGS_DEVICE_UNCACHED,
NULL, NULL, &hwrt_data->srtc_obj);
...
err = pvr_fw_object_create(pvr_dev, args->layers * RAA_ENTRY_SIZE,
PVR_BO_FW_FLAGS_DEVICE_UNCACHED,
NULL, NULL, &hwrt_data->raa_obj);
...
}
drivers/gpu/drm/imagination/pvr_hwrt.c:hwrt_data_fini_fw_structure() {
...
if (hwrt->max_rts > 1) {
pvr_fw_object_destroy(hwrt_data->raa_obj);
pvr_fw_object_destroy(hwrt_data->srtc_obj);
}
...
}
If userspace passes args->layers = 0x10000 or 0x10001, srtc_obj and
raa_obj are allocated because args->layers > 1, but hwrt->max_rts is
truncated to 0 or 1, so hwrt_data_fini_fw_structure() skips destroying
both firmware objects on error unwind or dataset release.
[1] https://sashiko.dev/#/bug/linux-39ffd81d-e0f1-4965-a087-efaa05fc6db9
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261121-pvr-hwrt-common-v1-1-784ce45b782a@gmail.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-21 15:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21 15:29 [PATCH] drm/imagination: Destroy the common FW object when HWRT data setup fails Suyuan Wang
2026-11-21 15:29 ` Suyuan Wang via B4 Relay
2026-11-21 15:37 ` 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.