From 00a90e1bc382ba695a2575cbae0cad012a5631ac Mon Sep 17 00:00:00 2001 From: AxxzyWasTaken Date: Sat, 7 Nov 2026 11:19:07 +0000 Subject: [PATCH] media: apple: avd: check the AV1 tile entries before using them The tile group control is user data. A request with fewer entries than the frame has tiles made avd-av1 read past the array, and an entry past the coded data sent the engine to wild addresses: DART faults, a frame timeout, then recovery. Chromium's VA path hit this with 8 tiles and 1 entry on an M4 Max. Refuse such a request. Signed-off-by: AxxzyWasTaken --- drivers/media/platform/apple/avd/avd-av1.c | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/apple/avd/avd-av1.c b/drivers/media/platform/apple/avd/avd-av1.c index d5d3207deaa0b..67dca20402b54 100644 --- a/drivers/media/platform/apple/avd/avd-av1.c +++ b/drivers/media/platform/apple/avd/avd-av1.c @@ -1396,10 +1396,36 @@ static void update_dec_buf_info(struct avd_decoded_buffer *buf, buf->av1.ref_frame_idx[i] = frame->ref_frame_idx[i]; } +/* The engine fetches each tile from these: bad values make it read wild addresses. */ +static int avd_av1_check_tiles(struct avd_ctx *ctx, struct avd_av1_run *run, + unsigned int entries) +{ + size_t payload = vb2_get_plane_payload(&run->base.bufs.src->vb2_buf, 0); + unsigned int tiles = run->frame->tile_info.tile_cols * + run->frame->tile_info.tile_rows; + unsigned int t; + + if (entries < tiles) { + dev_err_ratelimited(ctx->dev->dev, "AV1: %u tiles but %u tile entries\n", + tiles, entries); + return -EINVAL; + } + for (t = 0; t < tiles; t++) { + const struct v4l2_ctrl_av1_tile_group_entry *e = &run->tile_group[t]; + + if ((u64)e->tile_offset + e->tile_size > payload) { + dev_err_ratelimited(ctx->dev->dev, "AV1: tile %u at %u+%u past %zu bytes\n", + t, e->tile_offset, e->tile_size, payload); + return -EINVAL; + } + } + return 0; +} + static int avd_av1_run_preamble(struct avd_ctx *ctx, struct avd_av1_run *run) { struct v4l2_ctrl *ctrl; - int dst_len, tlb_len; + int dst_len, ret, tlb_len; avd_run_preamble(ctx, &run->base); @@ -1436,6 +1462,9 @@ static int avd_av1_run_preamble(struct avd_ctx *ctx, struct avd_av1_run *run) if (WARN_ON(!ctrl)) return -EINVAL; run->tile_group = ctrl->p_cur.p; + ret = avd_av1_check_tiles(ctx, run, ctrl->elems); + if (ret) + return ret; ctrl = v4l2_ctrl_find(&ctx->ctrl_hdl, V4L2_CID_STATELESS_AV1_FILM_GRAIN);