* [PATCH v2 1/2] drm/imagination: Destroy the common FW object when HWRT data setup fails
2026-11-21 15:47 [PATCH v2 0/2] drm/imagination: Fix leaks in HWRT data set handling Suyuan Wang via B4 Relay
@ 2026-11-21 15:47 ` Suyuan Wang via B4 Relay
2026-11-21 15:47 ` [PATCH v2 2/2] drm/imagination: Don't truncate the layer count in max_rts Suyuan Wang via B4 Relay
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Suyuan Wang via B4 Relay @ 2026-11-21 15:47 UTC (permalink / raw)
To: alessio.belle, luigi.santivetti
Cc: donald.robson, mripard, dri-devel, maarten.lankhorst, airlied,
simona, tzimmermann, linux-kernel, imagination
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: f1f55ed3ffe4 ("drm/imagination: Fixed oops when misusing ioctl CREATE_HWRT_DATASET")
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>
---
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 3f7c4346c52c..aa25f6adaa3b 100644
--- a/drivers/gpu/drm/imagination/pvr_hwrt.c
+++ b/drivers/gpu/drm/imagination/pvr_hwrt.c
@@ -483,6 +483,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);
--
2.34.1
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v2 2/2] drm/imagination: Don't truncate the layer count in max_rts
2026-11-21 15:47 [PATCH v2 0/2] drm/imagination: Fix leaks in HWRT data set handling Suyuan Wang via B4 Relay
2026-11-21 15:47 ` [PATCH v2 1/2] drm/imagination: Destroy the common FW object when HWRT data setup fails Suyuan Wang via B4 Relay
@ 2026-11-21 15:47 ` Suyuan Wang via B4 Relay
2026-11-26 15:51 ` [PATCH v2 0/2] drm/imagination: Fix leaks in HWRT data set handling Luigi Santivetti
2026-12-03 15:03 ` Alessio Belle
3 siblings, 0 replies; 7+ messages in thread
From: Suyuan Wang via B4 Relay @ 2026-11-21 15:47 UTC (permalink / raw)
To: alessio.belle, luigi.santivetti
Cc: donald.robson, mripard, dri-devel, maarten.lankhorst, airlied,
simona, tzimmermann, linux-kernel, imagination
From: Suyuan Wang <stevewong@hust.edu.cn>
hwrt_init_kernel_structure() stores the 32-bit args->layers from
userspace in the 16-bit hwrt->max_rts:
hwrt->max_rts = args->layers;
hwrt_data_init_fw_structure() then allocates the SRTC and RAA objects
when args->layers > 1, but hwrt_data_fini_fw_structure() only frees them
when hwrt->max_rts > 1. With layers = 0x10000 or 0x10001, max_rts ends
up as 0 or 1, so both firmware objects are leaked when the data set is
destroyed or its creation fails. Any user who can open the render node
can do this with DRM_IOCTL_PVR_CREATE_HWRT_DATASET, and the objects
grow with the layer count.
Make max_rts a u32, like args->layers and the max_rts field of the
firmware's struct rogue_fwif_rta_ctl, so that both checks see the same
value.
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>
---
drivers/gpu/drm/imagination/pvr_hwrt.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/imagination/pvr_hwrt.h b/drivers/gpu/drm/imagination/pvr_hwrt.h
index 676070b20c3b..7c215e2bd35a 100644
--- a/drivers/gpu/drm/imagination/pvr_hwrt.h
+++ b/drivers/gpu/drm/imagination/pvr_hwrt.h
@@ -74,7 +74,7 @@ struct pvr_hwrt_dataset {
struct pvr_free_list *free_lists[ROGUE_FWIF_NUM_RTDATA_FREELISTS];
/** @max_rts: Maximum render targets for this HWRT data set. */
- u16 max_rts;
+ u32 max_rts;
};
struct pvr_hwrt_dataset *
--
2.34.1
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH v2 0/2] drm/imagination: Fix leaks in HWRT data set handling
2026-11-21 15:47 [PATCH v2 0/2] drm/imagination: Fix leaks in HWRT data set handling Suyuan Wang via B4 Relay
2026-11-21 15:47 ` [PATCH v2 1/2] drm/imagination: Destroy the common FW object when HWRT data setup fails Suyuan Wang via B4 Relay
2026-11-21 15:47 ` [PATCH v2 2/2] drm/imagination: Don't truncate the layer count in max_rts Suyuan Wang via B4 Relay
@ 2026-11-26 15:51 ` Luigi Santivetti
2026-11-27 11:08 ` Wong Steve
2026-12-03 15:03 ` Alessio Belle
3 siblings, 1 reply; 7+ messages in thread
From: Luigi Santivetti @ 2026-11-26 15:51 UTC (permalink / raw)
To: shyckless, alessio.belle
Cc: alessio.belle, mripard, dri-devel, maarten.lankhorst, airlied,
simona, tzimmermann, linux-kernel, imagination
Hi Suyuan,
this series looks okay to me - thank you! I believe patch 2/2 might need to be
rebased, the line you are changing got recently refactored.
Refer to:
https://patch.msgid.link/20261104-minor-improvements-v1-1-cc976128538e@imgtec.com
This series is:
Reviewed-by: Luigi Santivetti <luigi.santivetti@imgtec.com>
On Sat, 2026-11-21 at 15:47 +0000, Suyuan Wang via B4 Relay wrote:
> Patch 1 is v1 with the Fixes tag corrected: the error path that skips
> hwrt_fini_common_fw_structure() came with f1f55ed3ffe4, not with the
> commit that added the ioctl (thanks to the Sashiko review).
>
> Patch 2 fixes the other leak that review pointed out: the 32-bit layer
> count is truncated into the 16-bit max_rts, so the SRTC and RAA objects
> allocated for layers > 1 can be skipped on destroy.
>
> Found with a static analysis tool and checked by hand. Compile tested on
> arm64 (W=1, all files that include pvr_hwrt.h); I don't have the
> hardware.
>
> Changes in v2:
> - 1/2: Fixes tag now points to f1f55ed3ffe4. No code change.
> - 2/2: new.
>
> v1: https://lore.kernel.org/all/20261121-pvr-hwrt-common-v1-1-784ce45b782a@gmail.com/
> ---
> Suyuan Wang (2):
> drm/imagination: Destroy the common FW object when HWRT data setup fails
> drm/imagination: Don't truncate the layer count in max_rts
>
> drivers/gpu/drm/imagination/pvr_hwrt.c | 2 ++
> drivers/gpu/drm/imagination/pvr_hwrt.h | 2 +-
> 2 files changed, 3 insertions(+), 1 deletion(-)
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 0/2] drm/imagination: Fix leaks in HWRT data set handling
2026-11-26 15:51 ` [PATCH v2 0/2] drm/imagination: Fix leaks in HWRT data set handling Luigi Santivetti
@ 2026-11-27 11:08 ` Wong Steve
2026-12-03 9:23 ` Alessio Belle
0 siblings, 1 reply; 7+ messages in thread
From: Wong Steve @ 2026-11-27 11:08 UTC (permalink / raw)
To: Luigi Santivetti
Cc: alessio.belle, mripard, dri-devel, maarten.lankhorst, airlied,
simona, tzimmermann, linux-kernel, imagination
Hi Luigi,
On Thu, 2026-11-26, Luigi Santivetti wrote:
> this series looks okay to me - thank you! I believe patch 2/2 might need to be
> rebased, the line you are changing got recently refactored.
Thanks for the review.
I checked this again. Both patches apply cleanly on the current
drm-misc-next, which already has your "drm/imagination: switch to
inline init of rogue_fwif_rta_ctl", and also on drm-misc-fixes (1/2
with a 4-line offset). 1/2 was already based on top of your change.
2/2 only changes the type of hwrt->max_rts in pvr_hwrt.h, from u16 to
u32. It doesn't touch the rta_ctl initialisation that your patch
reworked, so I don't think a rebase is needed. If you see a conflict
on a particular branch, tell me which one and I'll resend on top of
it with your Reviewed-by.
Thanks,
Suyuan
Luigi Santivetti <luigi.santivetti@imgtec.com> 于2026年11月26日周四 23:51写道:
>
> Hi Suyuan,
>
> this series looks okay to me - thank you! I believe patch 2/2 might need to be
> rebased, the line you are changing got recently refactored.
>
> Refer to:
>
> https://patch.msgid.link/20261104-minor-improvements-v1-1-cc976128538e@imgtec.com
>
>
> This series is:
>
> Reviewed-by: Luigi Santivetti <luigi.santivetti@imgtec.com>
>
> On Sat, 2026-11-21 at 15:47 +0000, Suyuan Wang via B4 Relay wrote:
> > Patch 1 is v1 with the Fixes tag corrected: the error path that skips
> > hwrt_fini_common_fw_structure() came with f1f55ed3ffe4, not with the
> > commit that added the ioctl (thanks to the Sashiko review).
> >
> > Patch 2 fixes the other leak that review pointed out: the 32-bit layer
> > count is truncated into the 16-bit max_rts, so the SRTC and RAA objects
> > allocated for layers > 1 can be skipped on destroy.
> >
> > Found with a static analysis tool and checked by hand. Compile tested on
> > arm64 (W=1, all files that include pvr_hwrt.h); I don't have the
> > hardware.
> >
> > Changes in v2:
> > - 1/2: Fixes tag now points to f1f55ed3ffe4. No code change.
> > - 2/2: new.
> >
> > v1: https://lore.kernel.org/all/20261121-pvr-hwrt-common-v1-1-784ce45b782a@gmail.com/
> > ---
> > Suyuan Wang (2):
> > drm/imagination: Destroy the common FW object when HWRT data setup fails
> > drm/imagination: Don't truncate the layer count in max_rts
> >
> > drivers/gpu/drm/imagination/pvr_hwrt.c | 2 ++
> > drivers/gpu/drm/imagination/pvr_hwrt.h | 2 +-
> > 2 files changed, 3 insertions(+), 1 deletion(-)
> >
> >
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 0/2] drm/imagination: Fix leaks in HWRT data set handling
2026-11-27 11:08 ` Wong Steve
@ 2026-12-03 9:23 ` Alessio Belle
0 siblings, 0 replies; 7+ messages in thread
From: Alessio Belle @ 2026-12-03 9:23 UTC (permalink / raw)
To: shyckless
Cc: Luigi Santivetti, tzimmermann, imagination, simona, dri-devel,
linux-kernel, airlied, maarten.lankhorst, mripard
Hi,
On Fri, 2026-11-27 at 19:08 +0800, Wong Steve wrote:
> Hi Luigi,
>
> On Thu, 2026-11-26, Luigi Santivetti wrote:
> > this series looks okay to me - thank you! I believe patch 2/2 might need to be
> > rebased, the line you are changing got recently refactored.
>
> Thanks for the review.
>
> I checked this again. Both patches apply cleanly on the current
> drm-misc-next, which already has your "drm/imagination: switch to
> inline init of rogue_fwif_rta_ctl", and also on drm-misc-fixes (1/2
> with a 4-line offset). 1/2 was already based on top of your change.
>
> 2/2 only changes the type of hwrt->max_rts in pvr_hwrt.h, from u16 to
> u32. It doesn't touch the rta_ctl initialisation that your patch
> reworked, so I don't think a rebase is needed. If you see a conflict
> on a particular branch, tell me which one and I'll resend on top of
> it with your Reviewed-by.
I can confirm that both patches apply cleanly to either branch, or after merging
one into the other. I'll apply them to drm-misc-fixes today.
Thanks,
Alessio
>
> Thanks,
> Suyuan
>
> Luigi Santivetti <luigi.santivetti@imgtec.com> 于2026年11月26日周四 23:51写道:
> >
> > Hi Suyuan,
> >
> > this series looks okay to me - thank you! I believe patch 2/2 might need to be
> > rebased, the line you are changing got recently refactored.
> >
> > Refer to:
> >
> > https://patch.msgid.link/20261104-minor-improvements-v1-1-cc976128538e@imgtec.com
> >
> >
> > This series is:
> >
> > Reviewed-by: Luigi Santivetti <luigi.santivetti@imgtec.com>
> >
> > On Sat, 2026-11-21 at 15:47 +0000, Suyuan Wang via B4 Relay wrote:
> > > Patch 1 is v1 with the Fixes tag corrected: the error path that skips
> > > hwrt_fini_common_fw_structure() came with f1f55ed3ffe4, not with the
> > > commit that added the ioctl (thanks to the Sashiko review).
> > >
> > > Patch 2 fixes the other leak that review pointed out: the 32-bit layer
> > > count is truncated into the 16-bit max_rts, so the SRTC and RAA objects
> > > allocated for layers > 1 can be skipped on destroy.
> > >
> > > Found with a static analysis tool and checked by hand. Compile tested on
> > > arm64 (W=1, all files that include pvr_hwrt.h); I don't have the
> > > hardware.
> > >
> > > Changes in v2:
> > > - 1/2: Fixes tag now points to f1f55ed3ffe4. No code change.
> > > - 2/2: new.
> > >
> > > v1: https://lore.kernel.org/all/20261121-pvr-hwrt-common-v1-1-784ce45b782a@gmail.com/
> > > ---
> > > Suyuan Wang (2):
> > > drm/imagination: Destroy the common FW object when HWRT data setup fails
> > > drm/imagination: Don't truncate the layer count in max_rts
> > >
> > > drivers/gpu/drm/imagination/pvr_hwrt.c | 2 ++
> > > drivers/gpu/drm/imagination/pvr_hwrt.h | 2 +-
> > > 2 files changed, 3 insertions(+), 1 deletion(-)
> > >
> > >
> >
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 0/2] drm/imagination: Fix leaks in HWRT data set handling
2026-11-21 15:47 [PATCH v2 0/2] drm/imagination: Fix leaks in HWRT data set handling Suyuan Wang via B4 Relay
` (2 preceding siblings ...)
2026-11-26 15:51 ` [PATCH v2 0/2] drm/imagination: Fix leaks in HWRT data set handling Luigi Santivetti
@ 2026-12-03 15:03 ` Alessio Belle
3 siblings, 0 replies; 7+ messages in thread
From: Alessio Belle @ 2026-12-03 15:03 UTC (permalink / raw)
To: luigi.santivetti, Suyuan Wang
Cc: donald.robson, mripard, dri-devel, maarten.lankhorst, airlied,
simona, tzimmermann, linux-kernel, imagination
On Sat, 21 Nov 2026 15:47:18 +0000, Suyuan Wang wrote:
> Patch 1 is v1 with the Fixes tag corrected: the error path that skips
> hwrt_fini_common_fw_structure() came with f1f55ed3ffe4, not with the
> commit that added the ioctl (thanks to the Sashiko review).
>
> Patch 2 fixes the other leak that review pointed out: the 32-bit layer
> count is truncated into the 16-bit max_rts, so the SRTC and RAA objects
> allocated for layers > 1 can be skipped on destroy.
>
> [...]
Applied to drm-misc-fixes, thanks!
[1/2] drm/imagination: Destroy the common FW object when HWRT data setup fails
commit: 804817b9b4fba26c12fb8eb4edad4d4b99a2d848
[2/2] drm/imagination: Don't truncate the layer count in max_rts
commit: 502ea48d0d8fa5dd0c31dc449efb3d82deef8efe
Best regards,
--
Alessio Belle <alessio.belle@imgtec.com>
^ permalink raw reply [flat|nested] 7+ messages in thread