media: ipu6: A few defensive fixes for ipu7 buttress, fw-com and mmu paths
Subsystems (2)
cover media: ipu6: A few defensive fixes for ipu7 buttress, fw-com and mmu paths
This series fixes several bugs found while reviewing the ipu7 buttress power on/off, fw-com and mmu paths: a boot-config leak on a queue memory allocation failure, a skipped cleanup step on a buttress power on/off timeout, unchecked firmware-supplied queue indices used in pointer arithmetic in ipu7_fw_com_get_token(), and a missing "is this iova mapped" check in ipu6_mmu_iova_to_phys() that could dereference an invalid pointer for an unmapped iova.
A related fix for a missing NULL check on the output pin queue in the ipu7 isr was dropped from this series, since an equivalent patch is already on the list:
https://lore.kernel.org/linux-media/[email protected]/
Manik Bajpai (4):
media: ipu6: Free boot config on queue memory alloc failure
media: ipu6: Always run cleanup in ipu7 power on/off on timeout
media: ipu6: Validate fw-com queue indices before use
media: ipu6: Fix NULL deref in ipu6_mmu_iova_to_phys()
drivers/media/pci/intel/ipu6/ipu6-buttress.c | 24 ++++++++++++-------- drivers/media/pci/intel/ipu6/ipu6-mmu.c | 11 ++++++++- drivers/media/pci/intel/ipu6/ipu7-boot.c | 1 + drivers/media/pci/intel/ipu6/ipu7-fw-com.c | 14 +++++++++++- drivers/media/pci/intel/ipu6/ipu7-fw-com.h | 5 +++- drivers/media/pci/intel/ipu6/ipu7-fw-isys.c | 7 +++--- 6 files changed, 47 insertions(+), 15 deletions(-)
Signature · 1 line
2.53.0
PATCH 1/4 media: ipu6: Free boot config on queue memory alloc failure
If the queue_mem allocation in ipu7_init_boot_config() fails, the function returned -ENOMEM without freeing the boot_config buffer it had already allocated. The current caller happens to clean up via ipu7_fw_isys_cleanup() -> ipu7_release_boot_config() on any failure from this function, so this is not an active leak today, but ipu7_init_boot_config() should not rely on a specific caller undoing its partial allocations.
Call the existing ipu7_release_boot_config() helper before returning, so the function cleans up after itself on its own error path, independent of what the caller does.
--- drivers/media/pci/intel/ipu6/ipu7-boot.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/pci/intel/ipu6/ipu7-boot.c +1 -0
@@ -246,6 +246,7 @@ int ipu7_init_boot_config(struct ipu6_bus_device *adev, GFP_KERNEL, 0);if (!fwctx->queue_mem) {dev_err (dev,"Failed to allocate queue memory.\n" ); +ipu7_release_boot_config (adev);return -ENOMEM ; } fwctx->queue_mem_size = total_queue_size_aligned;
Signature · 1 line
2.53.0
PATCH 2/4 media: ipu6: Always run cleanup in ipu7 power on/off on timeout
In reply to Manik Bajpai__ipu7_power_on() and __ipu7_power_off() both return early when the pwr_status readl_poll_timeout() call times out, skipping cleanup that was previously done only on the success path:
- __ipu7_power_on() left the clock-ownership override bit set in SLEEP_LEVEL_CFG instead of clearing it, which could break subsequent power transitions.
- __ipu7_power_off() skipped D2D power-down and NDE-disable, leaving those subsystems powered despite reporting a failure.
- Additionally, the return value of ipu7_isys_d2d_power() in __ipu7_power_off() was discarded, silently masking D2D power-down failures.
Always run the clock-override clear / D2D-NDE teardown regardless of whether the status poll timed out, and propagate a D2D power-down failure through the return value when the poll itself succeeded.
--- drivers/media/pci/intel/ipu6/ipu6-buttress.c | 24 ++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-)
drivers/media/pci/intel/ipu6/ipu6-buttress.c +15 -9
@@ -530,16 +530,15 @@ static int __ipu7_power_on(struct device *dev, ret =readl_poll_timeout (isp->base + isp->buttress.regs->pwr_status, val, (val & ctrl->pwr_sts_mask) == pwr_sts,100 ,BUTTRESS_POWER_TIMEOUT_US ); -if (ret) { +if (ret)dev_err (&isp->pdev->dev,"Change power status timeout with 0x%x\n" , val); -return ret; - } +/* Always drop the clock override, even if the poll above timed out. */ slp =readl (isp->base +IPU7_BUTTRESS_REG_SLEEP_LEVEL_CFG );writel (slp & ~ovrd_clk, isp->base +IPU7_BUTTRESS_REG_SLEEP_LEVEL_CFG ); -return 0 ; +return ret; } static int __ipu7_power_off(struct device *dev,
@@ -555,18 +554,25 @@ static int __ipu7_power_off(struct device *dev, ret =readl_poll_timeout (isp->base + isp->buttress.regs->pwr_status, val, (val & ctrl->pwr_sts_mask) == pwr_sts,100 ,BUTTRESS_POWER_TIMEOUT_US ); -if (ret) { +if (ret)dev_err (&isp->pdev->dev,"Change power status timeout with 0x%x\n" , val); -return ret; - } +/* Always release D2D/NDE, even if the power status poll timed out. */ if (ctrl->subsys_id ==IPU_ISYS ) { -ipu7_isys_d2d_power (isp, false); +int d2d_ret; + + d2d_ret =ipu7_isys_d2d_power (isp, false); +if (d2d_ret) { +dev_err (&isp->pdev->dev, +"D2D power down failed (%d)\n" , d2d_ret); +if (!ret) + ret = d2d_ret; + }ipu7_nde_control (isp, false); } -return 0 ; +return ret; } static int __ipu6_power(struct device *dev,
Signature · 1 line
2.53.0
PATCH 3/4 media: ipu6: Validate fw-com queue indices before use
In reply to Manik Bajpaiipu7_fw_com_get_token() reads read_index/write_index directly from firmware-shared memory and uses them unchecked in pointer arithmetic to compute a token address:
token = queue_params->token_array_mem + read_index * queue_params->token_size_in_bytes;
If firmware ever writes a corrupted or out-of-range index into that shared memory, this computes a pointer outside token_array_mem.
Reject indices that are not smaller than max_capacity before doing any pointer arithmetic.
--- drivers/media/pci/intel/ipu6/ipu7-fw-com.c | 14 +++++++++++++- drivers/media/pci/intel/ipu6/ipu7-fw-com.h | 5 ++++- drivers/media/pci/intel/ipu6/ipu7-fw-isys.c | 7 ++++--- 3 files changed, 21 insertions(+), 5 deletions(-)
drivers/media/pci/intel/ipu6/ipu7-fw-com.c +13 -1
@@ -3,6 +3,7 @@* Copyright (C) 2026 Intel Corporation */ +#include <linux/device.h> #include <linux/io.h> #include "ipu7-fw-com.h"
@@ -13,7 +14,8 @@ static void __iomem *ipu7_fw_com_get_indices(struct ipu7_fw_com_context *ctx,return ctx->queue_indices + (q *sizeof (struct ipu7_fw_com_queue_indices )); } -void *ipu7_fw_com_get_token (struct ipu7_fw_com_context *ctx,int q) +void *ipu7_fw_com_get_token (struct device *dev,struct ipu7_fw_com_context *ctx, +int q) {struct ipu7_fw_com_queue_config *queue_params = &ctx->queue_configs[q];void __iomem *queue_indices =ipu7_fw_com_get_indices (ctx, q);
@@ -25,6 +27,16 @@ void *ipu7_fw_com_get_token(struct ipu7_fw_com_context *ctx, int q) read_index));void *token =NULL ; +/* Indices come from firmware-shared memory; don't trust them blindly. */ +if (read_index >= queue_params->max_capacity || + write_index >= queue_params->max_capacity) { +dev_err_once (dev, +"ipu7-fw-com: bad queue %d index (r=%u w=%u cap=%u)\n" , + q, read_index, write_index, + queue_params->max_capacity); +return NULL ; + } +if (q < ctx->num_output_queues) {/* Output queue */ bool empty = (write_index == read_index);
drivers/media/pci/intel/ipu6/ipu7-fw-com.h +4 -1
@@ -6,6 +6,8 @@#include <linux/types.h> +struct device ; +struct ipu7_fw_com_queue_config {void *token_array_mem;u32 queue_size;
@@ -46,7 +48,8 @@ struct ipu7_fw_com_queue_indices { };void ipu7_fw_com_put_token (struct ipu7_fw_com_context *ctx,int q); -void *ipu7_fw_com_get_token (struct ipu7_fw_com_context *ctx,int q); +void *ipu7_fw_com_get_token (struct device *dev,struct ipu7_fw_com_context *ctx, +int q);struct ipu7_fw_com_queue_params_config *ipu7_fw_com_get_queue_config (struct ipu7_fw_com_config *config);
drivers/media/pci/intel/ipu6/ipu7-fw-isys.c +4 -3
@@ -147,7 +147,8 @@ static int ipu7_fw_isys_init(struct ipu6_isys *isys, unsigned int num_streams)static struct ipu7_insys_resp *ipu7_fw_isys_get_resp (struct ipu6_isys *isys) { -return ipu7_fw_com_get_token (isys->fwctx,IPU7_INSYS_OUTPUT_MSG_QUEUE ); +return ipu7_fw_com_get_token (&isys->adev->auxdev.dev, isys->fwctx, +IPU7_INSYS_OUTPUT_MSG_QUEUE ); }static void ipu7_fw_isys_put_resp (struct ipu6_isys *isys)
@@ -219,7 +220,6 @@ ipu7_fw_isys_send_cmd(struct ipu6_isys *isys, const unsigned int stream_handle, size_t size, u16 send_type) {struct ipu7_fw_com_context *ctx = isys->fwctx; -/*struct device *dev = &isys->adev->auxdev.dev;*/ struct ipu7_insys_send_queue_token *token;if (send_type >=N_IPU7_INSYS_SEND_TYPE )
@@ -228,7 +228,8 @@ ipu7_fw_isys_send_cmd(struct ipu6_isys *isys, const unsigned int stream_handle,if (cpu_mapped_buf)clflush_cache_range (cpu_mapped_buf, size); - token =ipu7_fw_com_get_token (ctx, stream_handle + + token =ipu7_fw_com_get_token (&isys->adev->auxdev.dev, ctx, + stream_handle +IPU7_INSYS_INPUT_MSG_QUEUE );if (!token)return -EBUSY ;
Signature · 1 line
2.53.0
PATCH 4/4 media: ipu6: Fix NULL deref in ipu6_mmu_iova_to_phys()
In reply to Manik Bajpaiipu6_mmu_iova_to_phys() looked up the L2 page table for the given iova and dereferenced it immediately, without checking whether the corresponding L1 entry is actually mapped. l2_map() and l2_unmap() already guard the equivalent lookup by checking the L1 entry against mmu_info->dummy_l2_pteval before touching l2_pts[].
An unmapped iova (e.g. a stale address passed from a debug path) would dereference an invalid pointer and crash.
Add the same "is this L1 entry mapped" check used by l2_map()/ l2_unmap(), returning 0 for an unmapped iova instead of crashing.
--- drivers/media/pci/intel/ipu6/ipu6-mmu.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/media/pci/intel/ipu6/ipu6-mmu.c +10 -1
@@ -566,10 +566,19 @@ phys_addr_t ipu6_mmu_iova_to_phys(struct ipu6_mmu_info *mmu_info, {phys_addr_t phy_addr;unsigned long flags; +u32 l1_idx = iova >>ISP_L1PT_SHIFT ;u32 *l2_pt;spin_lock_irqsave (&mmu_info->lock, flags); - l2_pt = mmu_info->l2_pts[iova >>ISP_L1PT_SHIFT ]; +if (mmu_info->l1_pt[l1_idx] == mmu_info->dummy_l2_pteval) { +spin_unlock_irqrestore (&mmu_info->lock, flags); +dev_err (mmu_info->dev, +"iova_to_phys: no mapping for iova %pad\n" , + &iova); +return 0 ; + } + + l2_pt = mmu_info->l2_pts[l1_idx]; phy_addr = (phys_addr_t )l2_pt[(iova &ISP_L2PT_MASK ) >>ISP_L2PT_SHIFT ]; phy_addr <<=ISP_PAGE_SHIFT ;spin_unlock_irqrestore (&mmu_info->lock, flags);
Signature · 1 line
2.53.0
Sakari Ailus
maintainerRe: [PATCH v1 4/4] media: ipu6: Fix NULL deref in ipu6_mmu_iova_to_phys()
Hi Manik,
Quoted 11 lines · Manik Bajpai
ipu6_mmu_iova_to_phys()looked up the L2 page table for the given iova and dereferenced it immediately, without checking whether the corresponding L1 entry is actually mapped.l2_map()andl2_unmap()already guard the equivalent lookup by checking the L1 entry againstmmu_info->dummy_l2_ptevalbefore touching l2_pts[].An unmapped iova (e.g. a stale address passed from a debug path) would dereference an invalid pointer and crash.
Add the same "is this L1 entry mapped" check used by l2_map()/
l2_unmap(), returning 0 for an unmapped iova instead of crashing.
Have you observed this somewhere? I guess it shouldn't happen, but if it has happened, I think we should add a Fixes: tag and Cc: stable here.
Signature · 3 lines
Regards, Sakari Ailus
v2 cover media: ipu6: A few defensive fixes for ipu7 buttress, fw-com and mmu paths
This series fixes several bugs found while reviewing the ipu7 buttress power on/off, fw-com and mmu paths: a boot-config leak on a queue memory allocation failure, a skipped cleanup step on a buttress power on/off timeout, unchecked firmware-supplied queue indices used in pointer arithmetic in ipu7_fw_com_get_token(), and a missing "is this iova mapped" check in ipu6_mmu_iova_to_phys() that could dereference an invalid pointer for an unmapped iova.
A related fix for a missing NULL check on the output pin queue in the ipu7 isr was dropped from this series, since an equivalent patch is already on the list:
https://lore.kernel.org/linux-media/[email protected]/
v2:
- ipu6_mmu_iova_to_phys(): this was found via code review, not from an observed crash (comparing against l2_map()/l2_unmap(), which already guard the equivalent lookup). Added a Fixes: tag pointing at the commit that introduced the unguarded lookup, but skipped a stable-tree backport since there's no confirmed real-world trigger (Sakari).
Manik Bajpai (4):
media: ipu6: Free boot config on queue memory alloc failure
media: ipu6: Always run cleanup in ipu7 power on/off on timeout
media: ipu6: Validate fw-com queue indices before use
media: ipu6: Fix NULL deref in ipu6_mmu_iova_to_phys()
drivers/media/pci/intel/ipu6/ipu6-buttress.c | 24 ++++++++++++-------- drivers/media/pci/intel/ipu6/ipu6-mmu.c | 11 ++++++++- drivers/media/pci/intel/ipu6/ipu7-boot.c | 1 + drivers/media/pci/intel/ipu6/ipu7-fw-com.c | 14 +++++++++++- drivers/media/pci/intel/ipu6/ipu7-fw-com.h | 5 +++- drivers/media/pci/intel/ipu6/ipu7-fw-isys.c | 7 +++--- 6 files changed, 47 insertions(+), 15 deletions(-)
Signature · 1 line
2.53.0
PATCH v2 1/4 media: ipu6: Free boot config on queue memory alloc failure
If the queue_mem allocation in ipu7_init_boot_config() fails, the function returned -ENOMEM without freeing the boot_config buffer it had already allocated. The current caller happens to clean up via ipu7_fw_isys_cleanup() -> ipu7_release_boot_config() on any failure from this function, so this is not an active leak today, but ipu7_init_boot_config() should not rely on a specific caller undoing its partial allocations.
Call the existing ipu7_release_boot_config() helper before returning, so the function cleans up after itself on its own error path, independent of what the caller does.
--- drivers/media/pci/intel/ipu6/ipu7-boot.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/pci/intel/ipu6/ipu7-boot.c +1 -0
@@ -246,6 +246,7 @@ int ipu7_init_boot_config(struct ipu6_bus_device *adev, GFP_KERNEL, 0);if (!fwctx->queue_mem) {dev_err (dev,"Failed to allocate queue memory.\n" ); +ipu7_release_boot_config (adev);return -ENOMEM ; } fwctx->queue_mem_size = total_queue_size_aligned;
Signature · 1 line
2.53.0
Sakari Ailus
maintainerRe: [PATCH v2 1/4] media: ipu6: Free boot config on queue memory alloc failure
Hi Manik,
Quoted 23 lines · Manik Bajpai
If the
queue_memallocation inipu7_init_boot_config()fails, the function returned-ENOMEMwithout freeing theboot_configbuffer it had already allocated. The current caller happens to clean up viaipu7_fw_isys_cleanup()->ipu7_release_boot_config()on any failure from this function, so this is not an active leak today, butipu7_init_boot_config()should not rely on a specific caller undoing its partial allocations.Call the existing
ipu7_release_boot_config()helper before returning, so the function cleans up after itself on its own error path, independent of what the caller does.Assisted-by Claude:claude-sonnet-5Signed-off-by Manik Bajpai <[email protected]>--- drivers/media/pci/intel/ipu6/ipu7-boot.c | 1 + 1 file changed, 1 insertion(+)drivers/media/pci/intel/ipu6/ipu7-boot.c +0
-0
drivers/media/pci/intel/ipu6/ipu7-boot.c int ipu7_init_boot_config(struct ipu6_bus_device *adev, · line 249
Quoted 4 lines
drivers/media/pci/intel/ipu6/ipu7-boot.c +1
-0@@ -246,6 +246,7 @@ int ipu7_init_boot_config(struct ipu6_bus_device *adev, GFP_KERNEL, 0);if (!fwctx->queue_mem) {dev_err (dev,"Failed to allocate queue memory.\n" ); +ipu7_release_boot_config (adev);
I believe on error, the caller already calls ipu7_fw_isys_cleanup() that includes a call to ipu7_release_boot_config().
The rest of the patches seem fine to me.
Quoted 3 lines
drivers/media/pci/intel/ipu6/ipu7-boot.c +0
-0return -ENOMEM ; } fwctx->queue_mem_size = total_queue_size_aligned;
Signature · 3 lines
Kind regards, Sakari Ailus
PATCH v2 2/4 media: ipu6: Always run cleanup in ipu7 power on/off on timeout
In reply to Manik Bajpai__ipu7_power_on() and __ipu7_power_off() both return early when the pwr_status readl_poll_timeout() call times out, skipping cleanup that was previously done only on the success path:
- __ipu7_power_on() left the clock-ownership override bit set in SLEEP_LEVEL_CFG instead of clearing it, which could break subsequent power transitions.
- __ipu7_power_off() skipped D2D power-down and NDE-disable, leaving those subsystems powered despite reporting a failure.
- Additionally, the return value of ipu7_isys_d2d_power() in __ipu7_power_off() was discarded, silently masking D2D power-down failures.
Always run the clock-override clear / D2D-NDE teardown regardless of whether the status poll timed out, and propagate a D2D power-down failure through the return value when the poll itself succeeded.
--- drivers/media/pci/intel/ipu6/ipu6-buttress.c | 24 ++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-)
drivers/media/pci/intel/ipu6/ipu6-buttress.c +15 -9
@@ -530,16 +530,15 @@ static int __ipu7_power_on(struct device *dev, ret =readl_poll_timeout (isp->base + isp->buttress.regs->pwr_status, val, (val & ctrl->pwr_sts_mask) == pwr_sts,100 ,BUTTRESS_POWER_TIMEOUT_US ); -if (ret) { +if (ret)dev_err (&isp->pdev->dev,"Change power status timeout with 0x%x\n" , val); -return ret; - } +/* Always drop the clock override, even if the poll above timed out. */ slp =readl (isp->base +IPU7_BUTTRESS_REG_SLEEP_LEVEL_CFG );writel (slp & ~ovrd_clk, isp->base +IPU7_BUTTRESS_REG_SLEEP_LEVEL_CFG ); -return 0 ; +return ret; } static int __ipu7_power_off(struct device *dev,
@@ -555,18 +554,25 @@ static int __ipu7_power_off(struct device *dev, ret =readl_poll_timeout (isp->base + isp->buttress.regs->pwr_status, val, (val & ctrl->pwr_sts_mask) == pwr_sts,100 ,BUTTRESS_POWER_TIMEOUT_US ); -if (ret) { +if (ret)dev_err (&isp->pdev->dev,"Change power status timeout with 0x%x\n" , val); -return ret; - } +/* Always release D2D/NDE, even if the power status poll timed out. */ if (ctrl->subsys_id ==IPU_ISYS ) { -ipu7_isys_d2d_power (isp, false); +int d2d_ret; + + d2d_ret =ipu7_isys_d2d_power (isp, false); +if (d2d_ret) { +dev_err (&isp->pdev->dev, +"D2D power down failed (%d)\n" , d2d_ret); +if (!ret) + ret = d2d_ret; + }ipu7_nde_control (isp, false); } -return 0 ; +return ret; } static int __ipu6_power(struct device *dev,
Signature · 1 line
2.53.0
Re: [PATCH v2 2/4] media: ipu6: Always run cleanup in ipu7 power on/off on timeout
Hi Manik,
Quoted 50 lines · Manik Bajpai
__ipu7_power_on()and__ipu7_power_off()both return early when thepwr_statusreadl_poll_timeout()call times out, skipping cleanup that was previously done only on the success path:-
__ipu7_power_on()left the clock-ownership override bit set inSLEEP_LEVEL_CFGinstead of clearing it, which could break subsequent power transitions.-
__ipu7_power_off()skipped D2D power-down and NDE-disable, leaving those subsystems powered despite reporting a failure.- Additionally, the return value of
ipu7_isys_d2d_power()in__ipu7_power_off()was discarded, silently masking D2D power-down failures.Always run the clock-override clear / D2D-NDE teardown regardless of whether the status poll timed out, and propagate a D2D power-down failure through the return value when the poll itself succeeded.
Assisted-by Claude:claude-sonnet-5Signed-off-by Manik Bajpai <[email protected]>--- drivers/media/pci/intel/ipu6/ipu6-buttress.c | 24 ++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-)drivers/media/pci/intel/ipu6/ipu6-buttress.c +3
-4@@ -530,16 +530,15 @@ static int __ipu7_power_on(struct device *dev, ret =readl_poll_timeout (isp->base + isp->buttress.regs->pwr_status, val, (val & ctrl->pwr_sts_mask) == pwr_sts,100 ,BUTTRESS_POWER_TIMEOUT_US ); -if (ret) { +if (ret)dev_err (&isp->pdev->dev,"Change power status timeout with 0x%x\n" , val); -return ret; - } +/* Always drop the clock override, even if the poll above timed out. */ slp =readl (isp->base +IPU7_BUTTRESS_REG_SLEEP_LEVEL_CFG );writel (slp & ~ovrd_clk, isp->base +IPU7_BUTTRESS_REG_SLEEP_LEVEL_CFG ); -return 0 ; +return ret; } static int __ipu7_power_off(struct device *dev,
drivers/media/pci/intel/ipu6/ipu6-buttress.c static int __ipu7_power_off(struct device *dev, · line 560
Quoted 10 lines
drivers/media/pci/intel/ipu6/ipu6-buttress.c +1
-3@@ -555,18 +554,25 @@ static int __ipu7_power_off(struct device *dev, ret =readl_poll_timeout (isp->base + isp->buttress.regs->pwr_status, val, (val & ctrl->pwr_sts_mask) == pwr_sts,100 ,BUTTRESS_POWER_TIMEOUT_US ); -if (ret) { +if (ret)dev_err (&isp->pdev->dev,"Change power status timeout with 0x%x\n" , val); -return ret; - }
I wonder if powering down D2D/NDE is right thing to do. In a caller, bus_pm_runtime_suspend(), we try to recover from error and call isys_runtime_pm_resume(). But after this change the D2D and NDE would be powered off and recovery would not make sense.
Quoted 23 lines
drivers/media/pci/intel/ipu6/ipu6-buttress.c +11
-2+/* Always release D2D/NDE, even if the power status poll timed out. */ if (ctrl->subsys_id ==IPU_ISYS ) { -ipu7_isys_d2d_power (isp, false); +int d2d_ret; + + d2d_ret =ipu7_isys_d2d_power (isp, false); +if (d2d_ret) { +dev_err (&isp->pdev->dev, +"D2D power down failed (%d)\n" , d2d_ret); +if (!ret) + ret = d2d_ret; + }ipu7_nde_control (isp, false); } -return 0 ; +return ret; } static int __ipu6_power(struct device *dev,Signature · 1 line
2.53.0
PATCH v2 3/4 media: ipu6: Validate fw-com queue indices before use
In reply to Manik Bajpaiipu7_fw_com_get_token() reads read_index/write_index directly from firmware-shared memory and uses them unchecked in pointer arithmetic to compute a token address:
token = queue_params->token_array_mem + read_index * queue_params->token_size_in_bytes;
If firmware ever writes a corrupted or out-of-range index into that shared memory, this computes a pointer outside token_array_mem.
Reject indices that are not smaller than max_capacity before doing any pointer arithmetic.
--- drivers/media/pci/intel/ipu6/ipu7-fw-com.c | 14 +++++++++++++- drivers/media/pci/intel/ipu6/ipu7-fw-com.h | 5 ++++- drivers/media/pci/intel/ipu6/ipu7-fw-isys.c | 7 ++++--- 3 files changed, 21 insertions(+), 5 deletions(-)
drivers/media/pci/intel/ipu6/ipu7-fw-com.c +13 -1
@@ -3,6 +3,7 @@* Copyright (C) 2026 Intel Corporation */ +#include <linux/device.h> #include <linux/io.h> #include "ipu7-fw-com.h"
@@ -13,7 +14,8 @@ static void __iomem *ipu7_fw_com_get_indices(struct ipu7_fw_com_context *ctx,return ctx->queue_indices + (q *sizeof (struct ipu7_fw_com_queue_indices )); } -void *ipu7_fw_com_get_token (struct ipu7_fw_com_context *ctx,int q) +void *ipu7_fw_com_get_token (struct device *dev,struct ipu7_fw_com_context *ctx, +int q) {struct ipu7_fw_com_queue_config *queue_params = &ctx->queue_configs[q];void __iomem *queue_indices =ipu7_fw_com_get_indices (ctx, q);
@@ -25,6 +27,16 @@ void *ipu7_fw_com_get_token(struct ipu7_fw_com_context *ctx, int q) read_index));void *token =NULL ; +/* Indices come from firmware-shared memory; don't trust them blindly. */ +if (read_index >= queue_params->max_capacity || + write_index >= queue_params->max_capacity) { +dev_err_once (dev, +"ipu7-fw-com: bad queue %d index (r=%u w=%u cap=%u)\n" , + q, read_index, write_index, + queue_params->max_capacity); +return NULL ; + } +if (q < ctx->num_output_queues) {/* Output queue */ bool empty = (write_index == read_index);
drivers/media/pci/intel/ipu6/ipu7-fw-com.h +4 -1
@@ -6,6 +6,8 @@#include <linux/types.h> +struct device ; +struct ipu7_fw_com_queue_config {void *token_array_mem;u32 queue_size;
@@ -46,7 +48,8 @@ struct ipu7_fw_com_queue_indices { };void ipu7_fw_com_put_token (struct ipu7_fw_com_context *ctx,int q); -void *ipu7_fw_com_get_token (struct ipu7_fw_com_context *ctx,int q); +void *ipu7_fw_com_get_token (struct device *dev,struct ipu7_fw_com_context *ctx, +int q);struct ipu7_fw_com_queue_params_config *ipu7_fw_com_get_queue_config (struct ipu7_fw_com_config *config);
drivers/media/pci/intel/ipu6/ipu7-fw-isys.c +4 -3
@@ -147,7 +147,8 @@ static int ipu7_fw_isys_init(struct ipu6_isys *isys, unsigned int num_streams)static struct ipu7_insys_resp *ipu7_fw_isys_get_resp (struct ipu6_isys *isys) { -return ipu7_fw_com_get_token (isys->fwctx,IPU7_INSYS_OUTPUT_MSG_QUEUE ); +return ipu7_fw_com_get_token (&isys->adev->auxdev.dev, isys->fwctx, +IPU7_INSYS_OUTPUT_MSG_QUEUE ); }static void ipu7_fw_isys_put_resp (struct ipu6_isys *isys)
@@ -219,7 +220,6 @@ ipu7_fw_isys_send_cmd(struct ipu6_isys *isys, const unsigned int stream_handle, size_t size, u16 send_type) {struct ipu7_fw_com_context *ctx = isys->fwctx; -/*struct device *dev = &isys->adev->auxdev.dev;*/ struct ipu7_insys_send_queue_token *token;if (send_type >=N_IPU7_INSYS_SEND_TYPE )
@@ -228,7 +228,8 @@ ipu7_fw_isys_send_cmd(struct ipu6_isys *isys, const unsigned int stream_handle,if (cpu_mapped_buf)clflush_cache_range (cpu_mapped_buf, size); - token =ipu7_fw_com_get_token (ctx, stream_handle + + token =ipu7_fw_com_get_token (&isys->adev->auxdev.dev, ctx, + stream_handle +IPU7_INSYS_INPUT_MSG_QUEUE );if (!token)return -EBUSY ;
Signature · 1 line
2.53.0
PATCH v2 4/4 media: ipu6: Fix NULL deref in ipu6_mmu_iova_to_phys()
In reply to Manik Bajpaiipu6_mmu_iova_to_phys() looked up the L2 page table for the given iova and dereferenced it immediately, without checking whether the corresponding L1 entry is actually mapped. l2_map() and l2_unmap() already guard the equivalent lookup by checking the L1 entry against mmu_info->dummy_l2_pteval before touching l2_pts[].
An unmapped iova (e.g. a stale address passed from a debug path) would dereference an invalid pointer and crash.
Add the same "is this L1 entry mapped" check used by l2_map()/ l2_unmap(), returning 0 for an unmapped iova instead of crashing.
--- drivers/media/pci/intel/ipu6/ipu6-mmu.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/media/pci/intel/ipu6/ipu6-mmu.c +10 -1
@@ -566,10 +566,19 @@ phys_addr_t ipu6_mmu_iova_to_phys(struct ipu6_mmu_info *mmu_info, {phys_addr_t phy_addr;unsigned long flags; +u32 l1_idx = iova >>ISP_L1PT_SHIFT ;u32 *l2_pt;spin_lock_irqsave (&mmu_info->lock, flags); - l2_pt = mmu_info->l2_pts[iova >>ISP_L1PT_SHIFT ]; +if (mmu_info->l1_pt[l1_idx] == mmu_info->dummy_l2_pteval) { +spin_unlock_irqrestore (&mmu_info->lock, flags); +dev_err (mmu_info->dev, +"iova_to_phys: no mapping for iova %pad\n" , + &iova); +return 0 ; + } + + l2_pt = mmu_info->l2_pts[l1_idx]; phy_addr = (phys_addr_t )l2_pt[(iova &ISP_L2PT_MASK ) >>ISP_L2PT_SHIFT ]; phy_addr <<=ISP_PAGE_SHIFT ;spin_unlock_irqrestore (&mmu_info->lock, flags);
Signature · 1 line
2.53.0