* [PATCH] media: qcom: camss: vfe: Fix out-of-bounds access in vfe_isr_reg_update()
@ 2025-12-27 10:24 Alper Ak
2025-12-29 0:12 ` Bryan O'Donoghue
0 siblings, 1 reply; 4+ messages in thread
From: Alper Ak @ 2025-12-27 10:24 UTC (permalink / raw)
To: hverkuil, mchehab
Cc: Alper Ak, Robert Foss, Todor Tomov, Bryan O'Donoghue,
Vladimir Zapolskiy, Jonathan Marek, linux-media, linux-arm-msm,
linux-kernel
vfe_isr() iterates using MSM_VFE_IMAGE_MASTERS_NUM(7) as the loop
bound and passes the index to vfe_isr_reg_update(). However,
vfe->line[] array is defined with VFE_LINE_NUM_MAX(4):
struct vfe_line line[VFE_LINE_NUM_MAX];
When index is 4, 5, 6, the access to vfe->line[line_id] exceeds
the array bounds and resulting in out-of-bounds memory access.
Add a bounds check to ensure line_id is within valid range before
accessing the array.
Fixes: 4edc8eae715c ("media: camss: Add initial support for VFE hardware version Titan 480")
Signed-off-by: Alper Ak <alperyasinak1@gmail.com>
---
drivers/media/platform/qcom/camss/camss-vfe-480.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/media/platform/qcom/camss/camss-vfe-480.c b/drivers/media/platform/qcom/camss/camss-vfe-480.c
index 4feea590a47b..fac111135c78 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe-480.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe-480.c
@@ -237,6 +237,9 @@ static void vfe_isr_reg_update(struct vfe_device *vfe, enum vfe_line_id line_id)
struct vfe_output *output;
unsigned long flags;
+ if (line_id >= VFE_LINE_NUM_MAX)
+ return;
+
spin_lock_irqsave(&vfe->output_lock, flags);
vfe_reg_update_clear(vfe, line_id);
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] media: qcom: camss: vfe: Fix out-of-bounds access in vfe_isr_reg_update()
2025-12-27 10:24 [PATCH] media: qcom: camss: vfe: Fix out-of-bounds access in vfe_isr_reg_update() Alper Ak
@ 2025-12-29 0:12 ` Bryan O'Donoghue
2025-12-29 7:52 ` [PATCH v2] " Alper Ak
0 siblings, 1 reply; 4+ messages in thread
From: Bryan O'Donoghue @ 2025-12-29 0:12 UTC (permalink / raw)
To: Alper Ak, hverkuil, mchehab
Cc: Robert Foss, Todor Tomov, Vladimir Zapolskiy, Jonathan Marek,
linux-media, linux-arm-msm, linux-kernel
On 27/12/2025 10:24, Alper Ak wrote:
> vfe_isr() iterates using MSM_VFE_IMAGE_MASTERS_NUM(7) as the loop
> bound and passes the index to vfe_isr_reg_update(). However,
> vfe->line[] array is defined with VFE_LINE_NUM_MAX(4):
>
> struct vfe_line line[VFE_LINE_NUM_MAX];
>
> When index is 4, 5, 6, the access to vfe->line[line_id] exceeds
> the array bounds and resulting in out-of-bounds memory access.
>
> Add a bounds check to ensure line_id is within valid range before
> accessing the array.
>
> Fixes: 4edc8eae715c ("media: camss: Add initial support for VFE hardware version Titan 480")
> Signed-off-by: Alper Ak <alperyasinak1@gmail.com>
> ---
> drivers/media/platform/qcom/camss/camss-vfe-480.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/media/platform/qcom/camss/camss-vfe-480.c b/drivers/media/platform/qcom/camss/camss-vfe-480.c
> index 4feea590a47b..fac111135c78 100644
> --- a/drivers/media/platform/qcom/camss/camss-vfe-480.c
> +++ b/drivers/media/platform/qcom/camss/camss-vfe-480.c
> @@ -237,6 +237,9 @@ static void vfe_isr_reg_update(struct vfe_device *vfe, enum vfe_line_id line_id)
> struct vfe_output *output;
> unsigned long flags;
>
> + if (line_id >= VFE_LINE_NUM_MAX)
> + return;
> +
> spin_lock_irqsave(&vfe->output_lock, flags);
> vfe_reg_update_clear(vfe, line_id);
>
A logical bug.
I think we shouldn't be calling this function at all with a index that
is too large though.
Something like this instead. An explicit loop for the output lines and
another loop for the write-master completions.
diff --git a/drivers/media/platform/qcom/camss/camss-vfe-480.c
b/drivers/media/platform/qcom/camss/camss-vfe-480.c
index 4feea590a47bc..d73f733fde045 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe-480.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe-480.c
@@ -202,11 +202,13 @@ static irqreturn_t vfe_isr(int irq, void *dev)
writel_relaxed(status, vfe->base + VFE_BUS_IRQ_CLEAR(0));
writel_relaxed(1, vfe->base + VFE_BUS_IRQ_CLEAR_GLOBAL);
- /* Loop through all WMs IRQs */
- for (i = 0; i < MSM_VFE_IMAGE_MASTERS_NUM; i++) {
+ for (i = 0; i < MAX_VFE_OUTPUT_LINES; i++) {
if (status & BUS_IRQ_MASK_0_RDI_RUP(vfe, i))
vfe_isr_reg_update(vfe, i);
+ }
+ /* Loop through all WMs IRQs */
+ for (i = 0; i < MSM_VFE_IMAGE_MASTERS_NUM; i++) {
if (status & BUS_IRQ_MASK_0_COMP_DONE(vfe,
RDI_COMP_GROUP(i)))
vfe_buf_done(vfe, i);
}
---
bod
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] media: qcom: camss: vfe: Fix out-of-bounds access in vfe_isr_reg_update()
2025-12-29 0:12 ` Bryan O'Donoghue
@ 2025-12-29 7:52 ` Alper Ak
2025-12-30 10:04 ` Bryan O'Donoghue
0 siblings, 1 reply; 4+ messages in thread
From: Alper Ak @ 2025-12-29 7:52 UTC (permalink / raw)
To: bryan.odonoghue
Cc: alperyasinak1, hverkuil, jonathan, linux-arm-msm, linux-kernel,
linux-media, mchehab, rfoss, todor.too, vladimir.zapolskiy
vfe_isr() iterates using MSM_VFE_IMAGE_MASTERS_NUM(7) as the loop
bound and passes the index to vfe_isr_reg_update(). However,
vfe->line[] array is defined with VFE_LINE_NUM_MAX(4):
struct vfe_line line[VFE_LINE_NUM_MAX];
When index is 4, 5, 6, the access to vfe->line[line_id] exceeds
the array bounds and resulting in out-of-bounds memory access.
Fix this by using separate loops for output lines and write masters.
Fixes: 4edc8eae715c ("media: camss: Add initial support for VFE hardware version Titan 480")
Signed-off-by: Alper Ak <alperyasinak1@gmail.com>
---
drivers/media/platform/qcom/camss/camss-vfe-480.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/media/platform/qcom/camss/camss-vfe-480.c b/drivers/media/platform/qcom/camss/camss-vfe-480.c
index 4feea590a47b..d73f733fde04 100644
--- a/drivers/media/platform/qcom/camss/camss-vfe-480.c
+++ b/drivers/media/platform/qcom/camss/camss-vfe-480.c
@@ -202,11 +202,13 @@ static irqreturn_t vfe_isr(int irq, void *dev)
writel_relaxed(status, vfe->base + VFE_BUS_IRQ_CLEAR(0));
writel_relaxed(1, vfe->base + VFE_BUS_IRQ_CLEAR_GLOBAL);
- /* Loop through all WMs IRQs */
- for (i = 0; i < MSM_VFE_IMAGE_MASTERS_NUM; i++) {
+ for (i = 0; i < MAX_VFE_OUTPUT_LINES; i++) {
if (status & BUS_IRQ_MASK_0_RDI_RUP(vfe, i))
vfe_isr_reg_update(vfe, i);
+ }
+ /* Loop through all WMs IRQs */
+ for (i = 0; i < MSM_VFE_IMAGE_MASTERS_NUM; i++) {
if (status & BUS_IRQ_MASK_0_COMP_DONE(vfe, RDI_COMP_GROUP(i)))
vfe_buf_done(vfe, i);
}
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] media: qcom: camss: vfe: Fix out-of-bounds access in vfe_isr_reg_update()
2025-12-29 7:52 ` [PATCH v2] " Alper Ak
@ 2025-12-30 10:04 ` Bryan O'Donoghue
0 siblings, 0 replies; 4+ messages in thread
From: Bryan O'Donoghue @ 2025-12-30 10:04 UTC (permalink / raw)
To: Alper Ak
Cc: hverkuil, jonathan, linux-arm-msm, linux-kernel, linux-media,
mchehab, rfoss, todor.too, vladimir.zapolskiy
On 29/12/2025 07:52, Alper Ak wrote:
> vfe_isr() iterates using MSM_VFE_IMAGE_MASTERS_NUM(7) as the loop
> bound and passes the index to vfe_isr_reg_update(). However,
> vfe->line[] array is defined with VFE_LINE_NUM_MAX(4):
>
> struct vfe_line line[VFE_LINE_NUM_MAX];
>
> When index is 4, 5, 6, the access to vfe->line[line_id] exceeds
> the array bounds and resulting in out-of-bounds memory access.
>
> Fix this by using separate loops for output lines and write masters.
>
> Fixes: 4edc8eae715c ("media: camss: Add initial support for VFE hardware version Titan 480")
> Signed-off-by: Alper Ak <alperyasinak1@gmail.com>
> ---
> drivers/media/platform/qcom/camss/camss-vfe-480.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/platform/qcom/camss/camss-vfe-480.c b/drivers/media/platform/qcom/camss/camss-vfe-480.c
> index 4feea590a47b..d73f733fde04 100644
> --- a/drivers/media/platform/qcom/camss/camss-vfe-480.c
> +++ b/drivers/media/platform/qcom/camss/camss-vfe-480.c
> @@ -202,11 +202,13 @@ static irqreturn_t vfe_isr(int irq, void *dev)
> writel_relaxed(status, vfe->base + VFE_BUS_IRQ_CLEAR(0));
> writel_relaxed(1, vfe->base + VFE_BUS_IRQ_CLEAR_GLOBAL);
>
> - /* Loop through all WMs IRQs */
> - for (i = 0; i < MSM_VFE_IMAGE_MASTERS_NUM; i++) {
> + for (i = 0; i < MAX_VFE_OUTPUT_LINES; i++) {
> if (status & BUS_IRQ_MASK_0_RDI_RUP(vfe, i))
> vfe_isr_reg_update(vfe, i);
> + }
>
> + /* Loop through all WMs IRQs */
> + for (i = 0; i < MSM_VFE_IMAGE_MASTERS_NUM; i++) {
> if (status & BUS_IRQ_MASK_0_COMP_DONE(vfe, RDI_COMP_GROUP(i)))
> vfe_buf_done(vfe, i);
> }
LGTM - assuming hardware tests pass.
Reviewed-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
---
bod
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-12-30 10:04 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-27 10:24 [PATCH] media: qcom: camss: vfe: Fix out-of-bounds access in vfe_isr_reg_update() Alper Ak
2025-12-29 0:12 ` Bryan O'Donoghue
2025-12-29 7:52 ` [PATCH v2] " Alper Ak
2025-12-30 10:04 ` Bryan O'Donoghue
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®