The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] drm/panthor: reject zero-sized firmware sections
@ 2026-07-20 11:30 Osama Abdelkader
  2026-07-24 16:03 ` Steven Price
  0 siblings, 1 reply; 4+ messages in thread
From: Osama Abdelkader @ 2026-07-20 11:30 UTC (permalink / raw)
  To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
	Heiko Stuebner, dri-devel, linux-kernel
  Cc: Osama Abdelkader, stable

panthor_fw_load_section_entry() skips BO creation when the firmware section
VA range is empty. The section is still added to the firmware section list,
leaving section->mem as NULL.

Later reload and unplug paths iterate over all firmware sections and
dereference section->mem, which can lead to a NULL pointer dereference.

Reject zero-sized firmware sections before adding them to the section list.

Fixes: 2718d91816ee ("drm/panthor: Add the FW logical block")
Cc: stable@vger.kernel.org
Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
---
 drivers/gpu/drm/panthor/panthor_fw.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c
index a338c4f0a7f5..6335893d3f16 100644
--- a/drivers/gpu/drm/panthor/panthor_fw.c
+++ b/drivers/gpu/drm/panthor/panthor_fw.c
@@ -596,6 +596,11 @@ static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
 	}
 
 	section_size = hdr.va.end - hdr.va.start;
+	if (!section_size) {
+		drm_err(&ptdev->base, "Firmware corrupted, zero-sized section\n");
+		return -EINVAL;
+	}
+
 	data_size = hdr.data.end - hdr.data.start;
 	if (data_size > section_size) {
 		drm_err(&ptdev->base, "Firmware corrupted, section data exceeds section size\n");
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/panthor: reject zero-sized firmware sections
  2026-07-20 11:30 [PATCH] drm/panthor: reject zero-sized firmware sections Osama Abdelkader
@ 2026-07-24 16:03 ` Steven Price
  2026-07-24 17:26   ` [PATCH v2] drm/panthor: skip " Osama Abdelkader
  0 siblings, 1 reply; 4+ messages in thread
From: Steven Price @ 2026-07-24 16:03 UTC (permalink / raw)
  To: Osama Abdelkader, Boris Brezillon, Liviu Dudau, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
	Heiko Stuebner, dri-devel, linux-kernel
  Cc: stable

On 20/07/2026 12:30, Osama Abdelkader wrote:
> panthor_fw_load_section_entry() skips BO creation when the firmware section
> VA range is empty. The section is still added to the firmware section list,
> leaving section->mem as NULL.
> 
> Later reload and unplug paths iterate over all firmware sections and
> dereference section->mem, which can lead to a NULL pointer dereference.

Good catch.

> Reject zero-sized firmware sections before adding them to the section list.

Sadly we were trying to support zero-sized sections - hence the "if
(section_size)" further down.

I think it would probably be better to just not add the section to the
list if it's zero sized and otherwise accept the firmware.

Thanks,
Steve

> Fixes: 2718d91816ee ("drm/panthor: Add the FW logical block")
> Cc: stable@vger.kernel.org
> Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
> ---
>  drivers/gpu/drm/panthor/panthor_fw.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c
> index a338c4f0a7f5..6335893d3f16 100644
> --- a/drivers/gpu/drm/panthor/panthor_fw.c
> +++ b/drivers/gpu/drm/panthor/panthor_fw.c
> @@ -596,6 +596,11 @@ static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
>  	}
>  
>  	section_size = hdr.va.end - hdr.va.start;
> +	if (!section_size) {
> +		drm_err(&ptdev->base, "Firmware corrupted, zero-sized section\n");
> +		return -EINVAL;
> +	}
> +
>  	data_size = hdr.data.end - hdr.data.start;
>  	if (data_size > section_size) {
>  		drm_err(&ptdev->base, "Firmware corrupted, section data exceeds section size\n");


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] drm/panthor: skip zero-sized firmware sections
  2026-07-24 16:03 ` Steven Price
@ 2026-07-24 17:26   ` Osama Abdelkader
  2026-07-28 16:09     ` Liviu Dudau
  0 siblings, 1 reply; 4+ messages in thread
From: Osama Abdelkader @ 2026-07-24 17:26 UTC (permalink / raw)
  To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
	Heiko Stuebner, dri-devel, linux-kernel
  Cc: Osama Abdelkader, stable

panthor_fw_load_section_entry() skips BO creation when the firmware section
VA range is empty. If such a section is added to the firmware section list,
section->mem is left as NULL.

Later reload and unplug paths iterate over all firmware sections and
dereference section->mem, which can lead to a NULL pointer dereference.

Zero-sized firmware sections are valid, so accept them as no-op entries but
skip adding them to the section list.

Fixes: 2718d91816ee ("drm/panthor: Add the FW logical block")
Cc: stable@vger.kernel.org
Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
---
 drivers/gpu/drm/panthor/panthor_fw.c | 4 ++++
 1 file changed, 4 insertions(+)

v2:
- Accept zero-sized firmware sections as no-op entries instead of rejecting
  them, as suggested by Steven.

diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c
index a338c4f0a7f5..66d9f5947af0 100644
--- a/drivers/gpu/drm/panthor/panthor_fw.c
+++ b/drivers/gpu/drm/panthor/panthor_fw.c
@@ -601,8 +601,11 @@ static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
 	if (data_size > section_size) {
 		drm_err(&ptdev->base, "Firmware corrupted, section data exceeds section size\n");
 		return -EINVAL;
 	}
 
+	if (!section_size)
+		return 0;
+
 	name_len = iter->size - iter->offset;
 
 	section = drmm_kzalloc(&ptdev->base, sizeof(*section), GFP_KERNEL);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] drm/panthor: skip zero-sized firmware sections
  2026-07-24 17:26   ` [PATCH v2] drm/panthor: skip " Osama Abdelkader
@ 2026-07-28 16:09     ` Liviu Dudau
  0 siblings, 0 replies; 4+ messages in thread
From: Liviu Dudau @ 2026-07-28 16:09 UTC (permalink / raw)
  To: Osama Abdelkader
  Cc: Boris Brezillon, Steven Price, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Heiko Stuebner,
	dri-devel, linux-kernel, stable

On Fri, Jul 24, 2026 at 07:26:20PM +0200, Osama Abdelkader wrote:
> panthor_fw_load_section_entry() skips BO creation when the firmware section
> VA range is empty. If such a section is added to the firmware section list,
> section->mem is left as NULL.
> 
> Later reload and unplug paths iterate over all firmware sections and
> dereference section->mem, which can lead to a NULL pointer dereference.
> 
> Zero-sized firmware sections are valid, so accept them as no-op entries but
> skip adding them to the section list.
> 
> Fixes: 2718d91816ee ("drm/panthor: Add the FW logical block")
> Cc: stable@vger.kernel.org
> Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>

Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>

Best regards,
Liviu

> ---
>  drivers/gpu/drm/panthor/panthor_fw.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> v2:
> - Accept zero-sized firmware sections as no-op entries instead of rejecting
>   them, as suggested by Steven.
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor/panthor_fw.c
> index a338c4f0a7f5..66d9f5947af0 100644
> --- a/drivers/gpu/drm/panthor/panthor_fw.c
> +++ b/drivers/gpu/drm/panthor/panthor_fw.c
> @@ -601,8 +601,11 @@ static int panthor_fw_load_section_entry(struct panthor_device *ptdev,
>  	if (data_size > section_size) {
>  		drm_err(&ptdev->base, "Firmware corrupted, section data exceeds section size\n");
>  		return -EINVAL;
>  	}
>  
> +	if (!section_size)
> +		return 0;
> +
>  	name_len = iter->size - iter->offset;
>  
>  	section = drmm_kzalloc(&ptdev->base, sizeof(*section), GFP_KERNEL);
> -- 
> 2.43.0
> 

-- 
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-07-28 16:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-20 11:30 [PATCH] drm/panthor: reject zero-sized firmware sections Osama Abdelkader
2026-07-24 16:03 ` Steven Price
2026-07-24 17:26   ` [PATCH v2] drm/panthor: skip " Osama Abdelkader
2026-07-28 16:09     ` Liviu Dudau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox