From: sashiko-bot@kernel.org
To: "Kyrie Wu" <kyrie.wu@mediatek.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org,
media-ci@linuxtv.org
Subject: Re: [PATCH v6 06/14] media: mediatek: vcodec: add debug information
Date: Mon, 20 Jul 2026 01:31:35 +0000 [thread overview]
Message-ID: <20260720013136.345FA1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260720012056.1026551-7-kyrie.wu@mediatek.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Lack of adequate locking on the `dbgfs_head` instance list allows concurrent list modifications, leading to Use-After-Free and list corruption.
- [High] Misuse of `snprintf` return values combined with a TOCTOU race on `inst_count` leads to an out-of-bounds read and WARN_ON_ONCE.
--
--- Patch [6]: [PATCH v6 06/14] media: mediatek: vcodec: add debug information ---
commit 339b2440735f521e0732ed61e123f2dc8ea944d3
Author: Kyrie Wu <kyrie.wu@mediatek.com>
media: mediatek: vcodec: add debug information
This commit adds hevc and av1 output format printing to the debugfs
output. It also introduces 10-bit capture format and bitstream
information to the debug output.
> diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_dbgfs.c b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_dbgfs.c
> index 2da11521fc7b9..a9e52a32079d3 100644
> --- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_dbgfs.c
> +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_dbgfs.c
[ ... ]
> @@ -122,9 +138,10 @@ static ssize_t mtk_vdec_dbgfs_read(struct file *filp, char __user *ubuf,
[Severity: Critical]
This is a pre-existing issue, but does the iteration surrounding this code
adequately protect against concurrent list modifications?
In mtk_vdec_dbgfs_read(), the list is traversed under dbgfs_lock:
mutex_lock(&dbgfs->dbgfs_lock);
list_for_each_entry(dbgfs_inst, &dbgfs->dbgfs_head, node) {
However, if a user process rapidly opens and closes the V4L2 device,
mtk_vcodec_dbgfs_remove() unlinks and frees the list element locklessly with
respect to the debugfs read lock:
mtk_vcodec_dbgfs_remove()
list_del(&dbgfs_inst->node);
kfree(dbgfs_inst);
Since the two paths acquire different locks, they can execute concurrently.
Can this lead to a use-after-free or list corruption when the reader hits a
freed node or poisoned list pointers?
>
> if (dbgfs_index[MTK_VDEC_DBGFS_PICINFO]) {
> curr_len = snprintf(buf + used_len, total_len - used_len,
> - "\treal(%dx%d)=>align(%dx%d)\n",
> + "\treal(%dx%d)=>align(%dx%d) 10bit(%d)\n",
> ctx->picinfo.pic_w, ctx->picinfo.pic_h,
> - ctx->picinfo.buf_w, ctx->picinfo.buf_h);
> + ctx->picinfo.buf_w, ctx->picinfo.buf_h,
> + ctx->is_10bit_bitstream);
> used_len += curr_len;
[Severity: High]
This is a pre-existing issue, but could this accumulation of used_len result
in an out-of-bounds read and a kernel warning?
The total_len is calculated earlier based on a lockless read of inst_count:
mtk_vdec_dbgfs_read()
int total_len = 200 * (dbgfs->inst_count == 0 ? 1 : dbgfs->inst_count);
If concurrent device opens increase the number of instances after this buffer
is allocated, used_len can exceed total_len.
When total_len - used_len becomes negative, snprintf receives a massive size
parameter. While vsnprintf catches sizes greater than INT_MAX and prevents a
heap overflow, it issues a WARN_ON_ONCE.
Furthermore, snprintf returns the length it would have written, which is
added to used_len. Later, simple_read_from_buffer() will use this inflated
used_len to read past the end of the heap allocation into userspace.
> }
>
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260720012056.1026551-1-kyrie.wu@mediatek.com?part=6
next prev parent reply other threads:[~2026-07-20 1:31 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-20 1:20 [PATCH v6 00/14] media: mediatek: vcodec: support video decoder in mt8196 Kyrie Wu
2026-07-20 1:20 ` [PATCH v6 01/14] media: mediatek: vcodec: support vcp architecture Kyrie Wu
2026-07-20 1:36 ` sashiko-bot
2026-07-20 12:57 ` Nicolas Dufresne
2026-07-20 1:20 ` [PATCH v6 02/14] media: mediatek: vcodec: add driver to support vcp Kyrie Wu
2026-07-20 1:36 ` sashiko-bot
2026-07-20 1:20 ` [PATCH v6 03/14] media: mediatek: vcodec: add driver to support vcp encoder Kyrie Wu
2026-07-20 1:45 ` sashiko-bot
2026-07-20 1:20 ` [PATCH v6 04/14] media: mediatek: vcodec: get different firmware ipi id Kyrie Wu
2026-07-20 1:44 ` sashiko-bot
2026-07-20 1:20 ` [PATCH v6 05/14] media: mediatek: vcodec: get share memory address Kyrie Wu
2026-07-20 1:40 ` sashiko-bot
2026-07-20 1:20 ` [PATCH v6 06/14] media: mediatek: vcodec: add debug information Kyrie Wu
2026-07-20 1:31 ` sashiko-bot [this message]
2026-07-20 1:20 ` [PATCH v6 07/14] media: mediatek: vcodec: send share memory address to vcp Kyrie Wu
2026-07-20 1:32 ` sashiko-bot
2026-07-20 1:20 ` [PATCH v6 08/14] dt-bindings: media: mediatek: vcodec: add decoder dt-bindings for mt8196 Kyrie Wu
2026-07-20 1:29 ` sashiko-bot
2026-07-20 5:46 ` Krzysztof Kozlowski
2026-07-20 5:49 ` Krzysztof Kozlowski
2026-07-20 6:26 ` Kyrie Wu (吴晗)
2026-07-20 10:19 ` Krzysztof Kozlowski
2026-07-20 1:20 ` [PATCH v6 09/14] media: mediatek: vcodec: add decoder compatible to support mt8196 Kyrie Wu
2026-07-20 1:36 ` sashiko-bot
2026-07-20 1:20 ` [PATCH v6 10/14] media: mediatek: vcodec: define MT8196 vcodec levels Kyrie Wu
2026-07-20 1:20 ` [PATCH v6 11/14] media: mediatek: vcodec: support 36bit iova address Kyrie Wu
2026-07-20 1:20 ` [PATCH v6 12/14] media: mediatek: vcodec: clean xpc status Kyrie Wu
2026-07-20 2:03 ` sashiko-bot
2026-07-20 1:20 ` [PATCH v6 13/14] media: mediatek: decoder: fill av1 buffer size with picinfo Kyrie Wu
2026-07-20 1:48 ` sashiko-bot
2026-07-20 1:20 ` [PATCH v6 14/14] media: mediatek: decoder: support av1 extend vsi Kyrie Wu
2026-07-20 1:50 ` sashiko-bot
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=20260720013136.345FA1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=kyrie.wu@mediatek.com \
--cc=media-ci@linuxtv.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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