From: Minseo Park <hiyoukou@gmail.com>
To: linux-media@vger.kernel.org
Cc: m.tretter@pengutronix.de, kernel@pengutronix.de,
mchehab@kernel.org, hverkuil@kernel.org,
linux-kernel@vger.kernel.org, Minseo Park <hiyoukou@gmail.com>
Subject: [PATCH] media: allegro: reject S_FMT on OUTPUT while buffers are allocated
Date: Thu, 26 Nov 2026 11:48:06 +0900 [thread overview]
Message-ID: <20261126024806.33434-1-hiyoukou@gmail.com> (raw)
allegro_s_fmt_vid_out() stores the requested frame size in the channel
without checking whether the OUTPUT queue already holds buffers. The
CAPTURE side does check, with vb2_is_busy(), but the OUTPUT side never
got the same guard.
The buffers are sized from channel->sizeimage_raw when REQBUFS runs
allegro_queue_setup(). Growing the frame size afterwards leaves the
queue holding buffers that are too small for the format the channel now
describes, and nothing catches it: allegro_buf_prepare() validates the
field order only, not the plane size.
allegro_device_run() then hands the encoder the small buffer together
with the new geometry:
src_y = vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0);
src_uv = src_y + (channel->stride * channel->height);
and allegro_mcu_send_encode_frame() passes channel->stride along with it.
Going from the smallest frame size the driver accepts to the largest, the
12 KiB that were allocated are described to the MCU as 11.9 MiB, with the
chroma plane starting 7.9 MiB past the end of the buffer. The MCU reads
whatever follows the allocation and encodes it into the CAPTURE buffer,
or faults, depending on whether an IOMMU covers the device.
Check vb2_is_busy() before storing the format, as the CAPTURE side does.
That is enough on its own: the core records the queue_setup() size in
vb2_plane.min_length when the buffers are created and rejects a DMABUF
shorter than that, and the queue offers only MMAP and DMABUF, so once the
format cannot change the buffers cannot be too small either.
This was found with the help of Claude (Anthropic), which also wrote the
patch and this changelog; I reviewed both against the source. See
Documentation/process/generated-content.rst. There is no reproducer: I
do not have the hardware, so this is compile tested only, W=1 with
COMPILE_TEST on x86_64.
Fixes: f20387dfd065 ("media: allegro: add Allegro DVT video IP core driver")
Cc: stable@vger.kernel.org
Signed-off-by: Minseo Park <hiyoukou@gmail.com>
---
Tool disclosure detail, per Documentation/process/generated-content.rst.
The assistant was asked to audit V4L2 S_FMT handlers for driver state
committed before validation, across a long interactive session rather
than from one prompt. The candidate list came from a script that
flagged .vidioc_s_fmt_* handlers writing driver state without a
vb2_is_busy() guard; it was calibrated against a known case first, and
its output was read by hand. The asymmetry with allegro_s_fmt_vid_cap()
and the path through allegro_device_run() were established by reading
the code, not by the script.
Review and a test on real hardware would be appreciated.
drivers/media/platform/allegro-dvt/allegro-core.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/media/platform/allegro-dvt/allegro-core.c b/drivers/media/platform/allegro-dvt/allegro-core.c
index dc76986ce48d..b241a7208deb 100644
--- a/drivers/media/platform/allegro-dvt/allegro-core.c
+++ b/drivers/media/platform/allegro-dvt/allegro-core.c
@@ -3461,12 +3461,17 @@ static int allegro_s_fmt_vid_out(struct file *file, void *fh,
struct v4l2_format *f)
{
struct allegro_channel *channel = file_to_channel(file);
+ struct vb2_queue *vq;
int err;
err = allegro_try_fmt_vid_out(file, fh, f);
if (err)
return err;
+ vq = v4l2_m2m_get_vq(channel->fh.m2m_ctx, f->type);
+ if (vb2_is_busy(vq))
+ return -EBUSY;
+
channel->width = f->fmt.pix.width;
channel->height = f->fmt.pix.height;
channel->stride = f->fmt.pix.bytesperline;
base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
--
2.43.0
reply other threads:[~2026-11-26 2:48 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=20261126024806.33434-1-hiyoukou@gmail.com \
--to=hiyoukou@gmail.com \
--cc=hverkuil@kernel.org \
--cc=kernel@pengutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=m.tretter@pengutronix.de \
--cc=mchehab@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
all inboxes | Powered by JetHome®