drm/panthor: reject zero-sized firmware sections
Subsystems (4)
PATCH 1/1 drm/panthor: reject zero-sized firmware sections
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.
--- drivers/gpu/drm/panthor/panthor_fw.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/panthor/panthor_fw.c +5 -0
@@ -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" );
Signature · 1 line
2.43.0
Steven Price
maintainerQuoted 6 lines · Osama Abdelkader
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, leavingsection->memas 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.
Quoted 1 line
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
Quoted 23 lines
Fixes 2718d91816ee ("drm/panthor: Add the FW logical block")Signed-off-by Osama Abdelkader <[email protected]>--- drivers/gpu/drm/panthor/panthor_fw.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/gpu/drm/panthor/panthor_fw.c +5
-0@@ -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" );
PATCH v2 1/1 drm/panthor: skip zero-sized firmware sections
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.
--- 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.
drivers/gpu/drm/panthor/panthor_fw.c +3 -0
@@ -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 );
Signature · 1 line
2.43.0
Re: [PATCH v2] drm/panthor: skip zero-sized firmware sections
Quoted 7 lines · Osama Abdelkader
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->memis 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.
Quoted 6 lines
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")Signed-off-by Osama Abdelkader <[email protected]>
Best regards,
Liviu
Quoted 27 lines
--- 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.drivers/gpu/drm/panthor/panthor_fw.c +3
-0@@ -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 );Signature · 1 line
2.43.0
Signature · 8 lines
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯Re: [PATCH v2] drm/panthor: skip zero-sized firmware sections
In reply to Osama AbdelkaderQuoted 7 lines · Osama Abdelkader
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->memis 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.
Quoted 6 lines
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")Signed-off-by Osama Abdelkader <[email protected]>
I'll push this to drm-misc-fixes.
Thanks,
Steve
Quoted 24 lines
--- 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.drivers/gpu/drm/panthor/panthor_fw.c +3
-0@@ -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 );