From: Arun Iyengar via B4 Relay <devnull+aiyengar1990.gmail.com@kernel.org>
To: Maxime Ripard <mripard@kernel.org>,
Paul Kocialkowski <paulk@sys-base.io>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Chen-Yu Tsai <wens@kernel.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>,
Hans Verkuil <hverkuil@kernel.org>
Cc: linux-media@vger.kernel.org, linux-staging@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org,
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>,
Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
Dmitry Osipenko <dmitry.osipenko@collabora.com>,
Nicolas Dufresne <nicolas.dufresne@collabora.com>,
stable@vger.kernel.org, Arun Iyengar <aiyengar1990@gmail.com>
Subject: [PATCH 5/5] media: staging: cedrus: vp8: fail the job on a bit reader timeout
Date: Tue, 01 Dec 2026 15:27:01 +0000 [thread overview]
Message-ID: <20261201-b4-cedrus-bitreader-v1-5-678ded51faf1@gmail.com> (raw)
In-Reply-To: <20261201-b4-cedrus-bitreader-v1-0-678ded51faf1@gmail.com>
From: Arun Iyengar <aiyengar1990@gmail.com>
The VP8 header parser ignores bit reader timeouts and decodes the frame
from a wrong position. Stop reading after the first timeout and fail
the job.
Fixes: 3c39a16d30d8 ("media: cedrus: Add support for VP8 decoding")
Cc: stable@vger.kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
drivers/staging/media/sunxi/cedrus/cedrus_vp8.c | 159 ++++++++++++++----------
1 file changed, 91 insertions(+), 68 deletions(-)
diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_vp8.c b/drivers/staging/media/sunxi/cedrus/cedrus_vp8.c
index bb32232d37ff..b5ae9a2f9d96 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_vp8.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_vp8.c
@@ -433,87 +433,101 @@ static const u8 k_mv_entropy_update_probs[2][V4L2_VP8_MV_PROB_CNT] = {
254, 254, 254, 254, 254, 251, 251, 254, 254, 254 }
};
-static uint8_t read_bits(struct cedrus_dev *dev, unsigned int bits_count,
+struct cedrus_vp8_bits {
+ struct cedrus_dev *dev;
+ int error;
+};
+
+static uint8_t read_bits(struct cedrus_vp8_bits *b, unsigned int bits_count,
unsigned int probability)
{
+ struct cedrus_dev *dev = b->dev;
+
+ if (b->error)
+ return 0;
+
cedrus_write(dev, VE_H264_TRIGGER_TYPE,
VE_H264_TRIGGER_TYPE_VP8_GET_BITS |
VE_H264_TRIGGER_TYPE_BIN_LENS(bits_count) |
VE_H264_TRIGGER_TYPE_PROBABILITY(probability));
- cedrus_wait_for(dev, VE_H264_STATUS, VE_H264_STATUS_VLD_BUSY);
+ if (cedrus_wait_for(dev, VE_H264_STATUS, VE_H264_STATUS_VLD_BUSY)) {
+ dev_err_ratelimited(dev->dev, "timed out waiting to read bits\n");
+ b->error = -ETIMEDOUT;
+ return 0;
+ }
return cedrus_read(dev, VE_H264_BASIC_BITS);
}
-static void get_delta_q(struct cedrus_dev *dev)
+static void get_delta_q(struct cedrus_vp8_bits *b)
{
- if (read_bits(dev, 1, VP8_PROB_HALF)) {
- read_bits(dev, 4, VP8_PROB_HALF);
- read_bits(dev, 1, VP8_PROB_HALF);
+ if (read_bits(b, 1, VP8_PROB_HALF)) {
+ read_bits(b, 4, VP8_PROB_HALF);
+ read_bits(b, 1, VP8_PROB_HALF);
}
}
-static void process_segmentation_info(struct cedrus_dev *dev)
+static void process_segmentation_info(struct cedrus_vp8_bits *b)
{
int update, i;
- update = read_bits(dev, 1, VP8_PROB_HALF);
+ update = read_bits(b, 1, VP8_PROB_HALF);
- if (read_bits(dev, 1, VP8_PROB_HALF)) {
- read_bits(dev, 1, VP8_PROB_HALF);
+ if (read_bits(b, 1, VP8_PROB_HALF)) {
+ read_bits(b, 1, VP8_PROB_HALF);
for (i = 0; i < 4; i++)
- if (read_bits(dev, 1, VP8_PROB_HALF)) {
- read_bits(dev, 7, VP8_PROB_HALF);
- read_bits(dev, 1, VP8_PROB_HALF);
+ if (read_bits(b, 1, VP8_PROB_HALF)) {
+ read_bits(b, 7, VP8_PROB_HALF);
+ read_bits(b, 1, VP8_PROB_HALF);
}
for (i = 0; i < 4; i++)
- if (read_bits(dev, 1, VP8_PROB_HALF)) {
- read_bits(dev, 6, VP8_PROB_HALF);
- read_bits(dev, 1, VP8_PROB_HALF);
+ if (read_bits(b, 1, VP8_PROB_HALF)) {
+ read_bits(b, 6, VP8_PROB_HALF);
+ read_bits(b, 1, VP8_PROB_HALF);
}
}
if (update)
for (i = 0; i < 3; i++)
- if (read_bits(dev, 1, VP8_PROB_HALF))
- read_bits(dev, 8, VP8_PROB_HALF);
+ if (read_bits(b, 1, VP8_PROB_HALF))
+ read_bits(b, 8, VP8_PROB_HALF);
}
-static void process_ref_lf_delta_info(struct cedrus_dev *dev)
+static void process_ref_lf_delta_info(struct cedrus_vp8_bits *b)
{
- if (read_bits(dev, 1, VP8_PROB_HALF)) {
+ if (read_bits(b, 1, VP8_PROB_HALF)) {
int i;
for (i = 0; i < 4; i++)
- if (read_bits(dev, 1, VP8_PROB_HALF)) {
- read_bits(dev, 6, VP8_PROB_HALF);
- read_bits(dev, 1, VP8_PROB_HALF);
+ if (read_bits(b, 1, VP8_PROB_HALF)) {
+ read_bits(b, 6, VP8_PROB_HALF);
+ read_bits(b, 1, VP8_PROB_HALF);
}
for (i = 0; i < 4; i++)
- if (read_bits(dev, 1, VP8_PROB_HALF)) {
- read_bits(dev, 6, VP8_PROB_HALF);
- read_bits(dev, 1, VP8_PROB_HALF);
+ if (read_bits(b, 1, VP8_PROB_HALF)) {
+ read_bits(b, 6, VP8_PROB_HALF);
+ read_bits(b, 1, VP8_PROB_HALF);
}
}
}
-static void process_ref_frame_info(struct cedrus_dev *dev)
+static void process_ref_frame_info(struct cedrus_vp8_bits *b)
{
- u8 refresh_golden_frame = read_bits(dev, 1, VP8_PROB_HALF);
- u8 refresh_alt_ref_frame = read_bits(dev, 1, VP8_PROB_HALF);
+ u8 refresh_golden_frame = read_bits(b, 1, VP8_PROB_HALF);
+ u8 refresh_alt_ref_frame = read_bits(b, 1, VP8_PROB_HALF);
if (!refresh_golden_frame)
- read_bits(dev, 2, VP8_PROB_HALF);
+ read_bits(b, 2, VP8_PROB_HALF);
if (!refresh_alt_ref_frame)
- read_bits(dev, 2, VP8_PROB_HALF);
+ read_bits(b, 2, VP8_PROB_HALF);
- read_bits(dev, 1, VP8_PROB_HALF);
- read_bits(dev, 1, VP8_PROB_HALF);
+ read_bits(b, 1, VP8_PROB_HALF);
+ read_bits(b, 1, VP8_PROB_HALF);
}
static void cedrus_irq_clear(struct cedrus_dev *dev)
@@ -522,73 +536,79 @@ static void cedrus_irq_clear(struct cedrus_dev *dev)
VE_H264_STATUS_INT_MASK);
}
-static void cedrus_read_header(struct cedrus_dev *dev,
- const struct v4l2_ctrl_vp8_frame *slice)
+static int cedrus_read_header(struct cedrus_dev *dev,
+ const struct v4l2_ctrl_vp8_frame *slice)
{
+ struct cedrus_vp8_bits b = { .dev = dev };
int i, j;
if (V4L2_VP8_FRAME_IS_KEY_FRAME(slice)) {
- read_bits(dev, 1, VP8_PROB_HALF);
- read_bits(dev, 1, VP8_PROB_HALF);
+ read_bits(&b, 1, VP8_PROB_HALF);
+ read_bits(&b, 1, VP8_PROB_HALF);
}
- if (read_bits(dev, 1, VP8_PROB_HALF))
- process_segmentation_info(dev);
+ if (read_bits(&b, 1, VP8_PROB_HALF))
+ process_segmentation_info(&b);
- read_bits(dev, 1, VP8_PROB_HALF);
- read_bits(dev, 6, VP8_PROB_HALF);
- read_bits(dev, 3, VP8_PROB_HALF);
+ read_bits(&b, 1, VP8_PROB_HALF);
+ read_bits(&b, 6, VP8_PROB_HALF);
+ read_bits(&b, 3, VP8_PROB_HALF);
- if (read_bits(dev, 1, VP8_PROB_HALF))
- process_ref_lf_delta_info(dev);
+ if (read_bits(&b, 1, VP8_PROB_HALF))
+ process_ref_lf_delta_info(&b);
- read_bits(dev, 2, VP8_PROB_HALF);
+ read_bits(&b, 2, VP8_PROB_HALF);
/* y_ac_qi */
- read_bits(dev, 7, VP8_PROB_HALF);
+ read_bits(&b, 7, VP8_PROB_HALF);
/* Parses y_dc_delta, y2_dc_delta, etc. */
for (i = 0; i < QUANT_DELTA_COUNT; i++)
- get_delta_q(dev);
+ get_delta_q(&b);
if (!V4L2_VP8_FRAME_IS_KEY_FRAME(slice))
- process_ref_frame_info(dev);
+ process_ref_frame_info(&b);
- read_bits(dev, 1, VP8_PROB_HALF);
+ read_bits(&b, 1, VP8_PROB_HALF);
if (!V4L2_VP8_FRAME_IS_KEY_FRAME(slice))
- read_bits(dev, 1, VP8_PROB_HALF);
+ read_bits(&b, 1, VP8_PROB_HALF);
+
+ if (b.error)
+ return b.error;
cedrus_write(dev, VE_H264_TRIGGER_TYPE, VE_H264_TRIGGER_TYPE_VP8_UPDATE_COEF);
cedrus_wait_for(dev, VE_H264_STATUS, VE_H264_STATUS_VP8_UPPROB_BUSY);
cedrus_irq_clear(dev);
- if (read_bits(dev, 1, VP8_PROB_HALF))
- read_bits(dev, 8, VP8_PROB_HALF);
+ if (read_bits(&b, 1, VP8_PROB_HALF))
+ read_bits(&b, 8, VP8_PROB_HALF);
if (!V4L2_VP8_FRAME_IS_KEY_FRAME(slice)) {
- read_bits(dev, 8, VP8_PROB_HALF);
- read_bits(dev, 8, VP8_PROB_HALF);
- read_bits(dev, 8, VP8_PROB_HALF);
-
- if (read_bits(dev, 1, VP8_PROB_HALF)) {
- read_bits(dev, 8, VP8_PROB_HALF);
- read_bits(dev, 8, VP8_PROB_HALF);
- read_bits(dev, 8, VP8_PROB_HALF);
- read_bits(dev, 8, VP8_PROB_HALF);
+ read_bits(&b, 8, VP8_PROB_HALF);
+ read_bits(&b, 8, VP8_PROB_HALF);
+ read_bits(&b, 8, VP8_PROB_HALF);
+
+ if (read_bits(&b, 1, VP8_PROB_HALF)) {
+ read_bits(&b, 8, VP8_PROB_HALF);
+ read_bits(&b, 8, VP8_PROB_HALF);
+ read_bits(&b, 8, VP8_PROB_HALF);
+ read_bits(&b, 8, VP8_PROB_HALF);
}
- if (read_bits(dev, 1, VP8_PROB_HALF)) {
- read_bits(dev, 8, VP8_PROB_HALF);
- read_bits(dev, 8, VP8_PROB_HALF);
- read_bits(dev, 8, VP8_PROB_HALF);
+ if (read_bits(&b, 1, VP8_PROB_HALF)) {
+ read_bits(&b, 8, VP8_PROB_HALF);
+ read_bits(&b, 8, VP8_PROB_HALF);
+ read_bits(&b, 8, VP8_PROB_HALF);
}
for (i = 0; i < 2; i++)
for (j = 0; j < V4L2_VP8_MV_PROB_CNT; j++)
- if (read_bits(dev, 1, k_mv_entropy_update_probs[i][j]))
- read_bits(dev, 7, VP8_PROB_HALF);
+ if (read_bits(&b, 1, k_mv_entropy_update_probs[i][j]))
+ read_bits(&b, 7, VP8_PROB_HALF);
}
+
+ return b.error;
}
static void cedrus_vp8_update_probs(const struct v4l2_ctrl_vp8_frame *slice,
@@ -659,6 +679,7 @@ static int cedrus_vp8_setup(struct cedrus_ctx *ctx, struct cedrus_run *run)
struct cedrus_dev *dev = ctx->dev;
dma_addr_t luma_addr, chroma_addr;
dma_addr_t src_buf_addr;
+ int ret;
int header_size;
u32 reg;
@@ -766,7 +787,9 @@ static int cedrus_vp8_setup(struct cedrus_ctx *ctx, struct cedrus_run *run)
reg |= VE_VP8_PPS_PIC_TYPE_P_FRAME;
cedrus_write(dev, VE_VP8_PPS, reg);
- cedrus_read_header(dev, slice);
+ ret = cedrus_read_header(dev, slice);
+ if (ret)
+ return ret;
/* reset registers changed by HW */
cedrus_write(dev, VE_H264_CUR_MB_NUM, 0);
--
2.55.0
prev parent reply other threads:[~2026-12-01 15:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 15:26 [PATCH 0/5] media: staging: cedrus: bound and check the bit reader setup Arun Iyengar via B4 Relay
2026-12-01 15:26 ` [PATCH 1/5] media: staging: cedrus: h264: bound the wait for the bit skip Arun Iyengar via B4 Relay
2026-12-01 15:26 ` [PATCH 2/5] media: staging: cedrus: h264: reject a slice header larger than the slice Arun Iyengar via B4 Relay
2026-12-01 15:26 ` [PATCH 3/5] media: staging: cedrus: h265: reject a slice data offset past " Arun Iyengar via B4 Relay
2026-12-01 15:27 ` [PATCH 4/5] media: staging: cedrus: h265: fail the job when the bit reader times out Arun Iyengar via B4 Relay
2026-12-01 15:27 ` Arun Iyengar via B4 Relay [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201-b4-cedrus-bitreader-v1-5-678ded51faf1@gmail.com \
--to=devnull+aiyengar1990.gmail.com@kernel.org \
--cc=aiyengar1990@gmail.com \
--cc=dmitry.osipenko@collabora.com \
--cc=ezequiel@vanguardiasur.com.ar \
--cc=gregkh@linuxfoundation.org \
--cc=hverkuil@kernel.org \
--cc=jernej.skrabec@gmail.com \
--cc=linkmauve@linkmauve.fr \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=linux-sunxi@lists.linux.dev \
--cc=mchehab@kernel.org \
--cc=mripard@kernel.org \
--cc=nicolas.dufresne@collabora.com \
--cc=paulk@sys-base.io \
--cc=samuel@sholland.org \
--cc=stable@vger.kernel.org \
--cc=wens@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox