[PATCH] media: mediatek: vcodec: NUL-terminate debugfs input
Nicolas Dufresne
nicolas at ndufresne.ca
Thu Nov 26 13:53:32 PST 2026
Le jeudi 29 octobre 2026 à 13:30 +0800, Jiale Yao a écrit :
> mtk_vdec_dbgfs_write() allows userspace to overwrite every byte in the
> persistent debugfs buffer. The read handler later searches that buffer with
> strstr(), which can read past its end when no NUL remains.
>
> Reserve one byte and terminate the copied input at the updated file
> position before releasing the debugfs lock.
>
> Fixes: 5e488a4fd859 ("media: mediatek: vcodec: Add a debugfs file to get different useful information")
> Cc: stable at vger.kernel.org
> Signed-off-by: Jiale Yao <yaojiale02 at 163.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne at collabora.com>
> ---
> .../media/platform/mediatek/vcodec/common/mtk_vcodec_dbgfs.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> 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 2da11521fc7b..8528534e41ef 100644
> --- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_dbgfs.c
> +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_dbgfs.c
> @@ -77,8 +77,11 @@ static ssize_t mtk_vdec_dbgfs_write(struct file *filp, const char __user *ubuf,
> struct mtk_vcodec_dbgfs *dbgfs = &vcodec_dev->dbgfs;
>
> mutex_lock(&dbgfs->dbgfs_lock);
> - dbgfs->buf_size = simple_write_to_buffer(dbgfs->dbgfs_buf, sizeof(dbgfs->dbgfs_buf),
> + dbgfs->buf_size = simple_write_to_buffer(dbgfs->dbgfs_buf,
> + sizeof(dbgfs->dbgfs_buf) - 1,
> ppos, ubuf, count);
> + if (dbgfs->buf_size > 0)
> + dbgfs->dbgfs_buf[*ppos] = '\0';
> mutex_unlock(&dbgfs->dbgfs_lock);
> if (dbgfs->buf_size > 0)
> return count;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20261126/c645f87f/attachment-0001.sig>
More information about the linux-arm-kernel
mailing list