Skip to content

Commit ba7e1b0

Browse files
Guoniu Zhougregkh
authored andcommitted
media: nxp: imx8-isi: Fix potential out-of-bounds issues
commit 57a7ec5 upstream. The maximum downscaling factor supported by ISI can be up to 16. Add minimum value constraint before applying the setting to hardware. Otherwise, the process will not respond even when Ctrl+C is executed. Fixes: cf21f32 ("media: nxp: Add i.MX8 ISI driver") Cc: stable@vger.kernel.org Reviewed-by: Frank Li <Frank.Li@nxp.com> Signed-off-by: Guoniu Zhou <guoniu.zhou@nxp.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Link: https://patch.msgid.link/20260323-isi-v3-1-8df53b24e622@oss.nxp.com Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 211f168 commit ba7e1b0

3 files changed

Lines changed: 32 additions & 8 deletions

File tree

drivers/media/platform/nxp/imx8-isi/imx8-isi-core.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define __MXC_ISI_CORE_H__
1212

1313
#include <linux/list.h>
14+
#include <linux/math.h>
1415
#include <linux/mutex.h>
1516
#include <linux/spinlock.h>
1617
#include <linux/types.h>
@@ -403,4 +404,19 @@ static inline void mxc_isi_debug_cleanup(struct mxc_isi_dev *isi)
403404
}
404405
#endif
405406

407+
/*
408+
* ISI scaling engine works in two parts: it performs pre-decimation of
409+
* the image followed by bilinear filtering to achieve the desired
410+
* downscaling factor.
411+
*
412+
* The decimation filter provides a maximum downscaling factor of 8, and
413+
* the subsequent bilinear filter provides a maximum downscaling factor
414+
* of 2. Combined, the maximum scaling factor can be up to 16.
415+
*/
416+
static inline unsigned int
417+
mxc_isi_clamp_downscale_16(unsigned int val, unsigned int max_val)
418+
{
419+
return clamp(val, max(1U, DIV_ROUND_UP(max_val, 16)), max_val);
420+
}
421+
406422
#endif /* __MXC_ISI_CORE_H__ */

drivers/media/platform/nxp/imx8-isi/imx8-isi-m2m.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,14 @@ __mxc_isi_m2m_try_fmt_vid(struct mxc_isi_m2m_ctx *ctx,
504504
const enum mxc_isi_video_type type)
505505
{
506506
if (type == MXC_ISI_VIDEO_M2M_CAP) {
507-
/* Downscaling only */
508-
pix->width = min(pix->width, ctx->queues.out.format.width);
509-
pix->height = min(pix->height, ctx->queues.out.format.height);
507+
const struct v4l2_pix_format_mplane *format =
508+
&ctx->queues.out.format;
509+
510+
/* Downscaling only, by up to 16. */
511+
pix->width = mxc_isi_clamp_downscale_16(pix->width,
512+
format->width);
513+
pix->height = mxc_isi_clamp_downscale_16(pix->height,
514+
format->height);
510515
}
511516

512517
return mxc_isi_format_try(ctx->m2m->pipe, pix, type);

drivers/media/platform/nxp/imx8-isi/imx8-isi-pipe.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -641,16 +641,19 @@ static int mxc_isi_pipe_set_selection(struct v4l2_subdev *sd,
641641
/* Composing is supported on the sink only. */
642642
return -EINVAL;
643643

644-
/* The sink crop is bound by the sink format downscaling only). */
644+
/*
645+
* The ISI supports downscaling only, with a factor up to 16.
646+
* Clamp the compose rectangle size accordingly.
647+
*/
645648
format = mxc_isi_pipe_get_pad_format(pipe, state,
646649
MXC_ISI_PIPE_PAD_SINK);
647650

648651
sel->r.left = 0;
649652
sel->r.top = 0;
650-
sel->r.width = clamp(sel->r.width, MXC_ISI_MIN_WIDTH,
651-
format->width);
652-
sel->r.height = clamp(sel->r.height, MXC_ISI_MIN_HEIGHT,
653-
format->height);
653+
sel->r.width = mxc_isi_clamp_downscale_16(sel->r.width,
654+
format->width);
655+
sel->r.height = mxc_isi_clamp_downscale_16(sel->r.height,
656+
format->height);
654657

655658
rect = mxc_isi_pipe_get_pad_compose(pipe, state,
656659
MXC_ISI_PIPE_PAD_SINK);

0 commit comments

Comments
 (0)