From: David Carlier <devnexen@gmail.com>
To: Jacopo Mondi <jacopo.mondi@ideasonboard.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Michael Riesch <michael.riesch@collabora.com>,
Daniel Scally <dan.scally@ideasonboard.com>,
Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>,
Hans Verkuil <hverkuil+cisco@kernel.org>
Cc: David Carlier <devnexen@gmail.com>,
stable@vger.kernel.org,
Sakari Ailus <sakari.ailus@linux.intel.com>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] media: v4l2-isp: reject zero-sized parameter blocks
Date: Tue, 18 Aug 2026 11:56:42 +0100 [thread overview]
Message-ID: <20260818105642.65381-1-devnexen@gmail.com> (raw)
v4l2_isp_params_validate_buffer() walks the blocks of a parameters
buffer by adding block->size to the current offset, but never bounds
that size from below. A block with size 0 is not caught by the
block->size > buffer_size test, and the comparison against info->size
passes as well when the driver's type_info[] entry is an uninitialised
hole, both sizes being 0. The walk then makes no forward progress and
loops forever.
Drivers build their type_info[] arrays with designated initialisers
indexed by their block type enumeration, so an enumerator left without
an entry leaves a zeroed hole rather than failing the build. Drivers
call the validator from vb2 .buf_prepare, so such a hole turns a
VIDIOC_QBUF on the parameters video device into an unkillable task
spinning with the queue mutex held.
Reject a block smaller than its own header. A block's size includes its
header, so anything below that is malformed whatever the driver table
contains, and rejecting it is what keeps the walk moving. Blocks
carrying only a header to disable a block are exactly that size and
still pass.
An empty type info entry can then no longer stall the walk, so skip
such a block instead of failing the whole buffer: drivers may reserve
uAPI block types they do not implement yet, and are free to ignore the
block when processing the buffer.
Fixes: 3cb6de6fafb8 ("media: v4l2-core: Introduce v4l2-isp.c")
Cc: stable@vger.kernel.org
Suggested-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: David Carlier <devnexen@gmail.com>
---
v2:
- skip a block whose type info entry is empty instead of
matching it against a zeroed entry, so a type the driver
does not implement is ignored rather than failing the
whole buffer (Jacopo)
- reworded the commit message, which no longer leans on
rppx1: its missing AWBG_POST entry is being fixed at
https://patchwork.linuxtv.org/project/linux-media/list/?series=29170
drivers/media/v4l2-core/v4l2-isp.c | 41 ++++++++++++++++++++----------
1 file changed, 28 insertions(+), 13 deletions(-)
diff --git a/drivers/media/v4l2-core/v4l2-isp.c b/drivers/media/v4l2-core/v4l2-isp.c
index 1eb46e080afa..439477b2b941 100644
--- a/drivers/media/v4l2-core/v4l2-isp.c
+++ b/drivers/media/v4l2-core/v4l2-isp.c
@@ -84,6 +84,13 @@ int v4l2_isp_params_validate_buffer(struct device *dev, struct vb2_buffer *vb,
return -EINVAL;
}
+ if (block->size < sizeof(*block)) {
+ dev_dbg(dev,
+ "Invalid block size %u at offset %zu\n",
+ block->size, block_offset);
+ return -EINVAL;
+ }
+
if (block->size > buffer_size) {
dev_dbg(dev, "Premature end of parameters data\n");
return -EINVAL;
@@ -100,23 +107,31 @@ int v4l2_isp_params_validate_buffer(struct device *dev, struct vb2_buffer *vb,
}
/*
- * Match the block reported size against the type info provided
- * one, but allow the block to only contain the header in
- * case it is going to be disabled.
+ * An empty type info entry denotes a block type the driver
+ * does not support. Skip the block, it is up to the driver to
+ * ignore it when processing the buffer.
*/
info = &type_info[block->type];
- if (block->size != info->size &&
- (!(block->flags & V4L2_ISP_PARAMS_FL_BLOCK_DISABLE) ||
- block->size != sizeof(*block))) {
- dev_dbg(dev,
- "Invalid block size %u (expected %zu) at offset %zu\n",
- block->size, info->size, block_offset);
- return -EINVAL;
+ if (info->size) {
+ /*
+ * Match the block reported size against the type info
+ * provided one, but allow the block to only contain the
+ * header in case it is going to be disabled.
+ */
+ if (block->size != info->size &&
+ (!(block->flags & V4L2_ISP_PARAMS_FL_BLOCK_DISABLE) ||
+ block->size != sizeof(*block))) {
+ dev_dbg(dev,
+ "Invalid block size %u (expected %zu) at offset %zu\n",
+ block->size, info->size, block_offset);
+ return -EINVAL;
+ }
+
+ if (info->block_validate &&
+ info->block_validate(dev, block))
+ return -EINVAL;
}
- if (info->block_validate && info->block_validate(dev, block))
- return -EINVAL;
-
block_offset += block->size;
buffer_size -= block->size;
}
--
2.55.0
reply other threads:[~2026-08-18 10:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260818105642.65381-1-devnexen@gmail.com \
--to=devnexen@gmail.com \
--cc=dan.scally@ideasonboard.com \
--cc=hverkuil+cisco@kernel.org \
--cc=jacopo.mondi@ideasonboard.com \
--cc=laurent.pinchart+renesas@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=michael.riesch@collabora.com \
--cc=sakari.ailus@linux.intel.com \
--cc=stable@vger.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