Re: [PATCH v2 07/11] staging: media: cedrus: validate VP8 frame size
From: Nicolas Dufresne
Date: Thu Nov 26 2026 - 17:39:38 EST
Le lundi 09 novembre 2026 à 18:50 +0100, Jernej Skrabec a écrit :
> A VP8 key frame can change the frame size. If userspace doesn't
> reallocate the capture buffers, the hardware writes and reads past the
> buffers, which shows up as IOMMU page faults and decode timeouts.
>
> Like for the H.264 and HEVC SPS, reject frames beyond the hardware
> limits in try_ctrl, and fail the job in the setup callback if the frame
> doesn't fit the buffers. The VP8 frame size register holds the size in
> 8-bit macroblock counts, so VP8 frames are limited to 4080 pixels in
> width.
>
> Fixes: 3c39a16d30d8 ("media: cedrus: Add support for VP8 decoding")
> Signed-off-by: Jernej Skrabec <jernej.skrabec@xxxxxxxxx>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@xxxxxxxxxxxxx>
> ---
> drivers/staging/media/sunxi/cedrus/cedrus.c | 10 ++++++++++
> drivers/staging/media/sunxi/cedrus/cedrus_vp8.c | 3 +++
> 2 files changed, 13 insertions(+)
>
> diff --git a/drivers/staging/media/sunxi/cedrus/cedrus.c b/drivers/staging/media/sunxi/cedrus/cedrus.c
> index 197213911bf7..6c6aa45f5f96 100644
> --- a/drivers/staging/media/sunxi/cedrus/cedrus.c
> +++ b/drivers/staging/media/sunxi/cedrus/cedrus.c
> @@ -28,6 +28,8 @@
> #include "cedrus_dec.h"
> #include "cedrus_hw.h"
>
> +#define CEDRUS_VP8_MAX_WIDTH 4080U
> +
> /*
> * Reject picture sizes beyond the hardware limits. Whether the picture fits
> * the buffers is checked when a job is set up, see cedrus_check_pic_size().
> @@ -54,6 +56,13 @@ static int cedrus_try_ctrl(struct v4l2_ctrl *ctrl)
> if (!cedrus_pic_size_supported(cedrus_h264_sps_width(sps),
> cedrus_h264_sps_height(sps)))
> return -EINVAL;
> + } else if (ctrl->id == V4L2_CID_STATELESS_VP8_FRAME) {
> + const struct v4l2_ctrl_vp8_frame *frame = ctrl->p_new.p_vp8_frame;
> +
> + /* The VP8 frame size register holds 8-bit macroblock counts. */
> + if (!cedrus_pic_size_supported(frame->width, frame->height) ||
> + frame->width > CEDRUS_VP8_MAX_WIDTH)
> + return -EINVAL;
> } else if (ctrl->id == V4L2_CID_STATELESS_HEVC_SPS) {
> const struct v4l2_ctrl_hevc_sps *sps = ctrl->p_new.p_hevc_sps;
> struct cedrus_ctx *ctx = container_of(ctrl->handler, struct cedrus_ctx, hdl);
> @@ -248,6 +257,7 @@ static const struct cedrus_control cedrus_controls[] = {
> {
> .cfg = {
> .id = V4L2_CID_STATELESS_VP8_FRAME,
> + .ops = &cedrus_ctrl_ops,
> },
> .capabilities = CEDRUS_CAPABILITY_VP8_DEC,
> },
> diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_vp8.c b/drivers/staging/media/sunxi/cedrus/cedrus_vp8.c
> index 969677a3bbf9..fecca343bd92 100644
> --- a/drivers/staging/media/sunxi/cedrus/cedrus_vp8.c
> +++ b/drivers/staging/media/sunxi/cedrus/cedrus_vp8.c
> @@ -662,6 +662,9 @@ static int cedrus_vp8_setup(struct cedrus_ctx *ctx, struct cedrus_run *run)
> int header_size;
> u32 reg;
>
> + if (cedrus_check_pic_size(ctx, slice->width, slice->height))
> + return -EINVAL;
> +
> cedrus_engine_enable(ctx);
>
> cedrus_write(dev, VE_H264_CTRL, VE_H264_CTRL_VP8);
Attachment:
signature.asc
Description: This is a digitally signed message part