From: sashiko-bot@kernel.org
To: "Detlev Casanova" <detlev.casanova@collabora.com>
Cc: linux-trace-kernel@vger.kernel.org, media-ci@linuxtv.org
Subject: Re: [PATCH v4 3/9] media: Add tgid and fd fields in v4l2_fh struct
Date: Fri, 27 Nov 2026 16:57:26 +0000 [thread overview]
Message-ID: <sashiko-outbox-237953@kernel.org> (raw)
In-Reply-To: <20261127-v4l2-add-ftrace-v4-3-24138479002f@collabora.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] media: v4l2: file descriptor 0 overwritten with -1 in
__video_do_ioctl()
- [Low] media: v4l2: mismatched tgid and fd across processes in
__video_do_ioctl()
--
commit 85c2231f2b1b5eff1384b64415c724ad919f3c23
Author: Detlev Casanova <detlev.casanova@collabora.com>
media: Add tgid and fd fields in v4l2_fh struct
This commit adds tgid and fd fields to struct v4l2_fh, recording the
opening process's tgid in v4l2_fh_init() and resolving the file descriptor
in __video_do_ioctl() for tracing.
> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
> index 17ba1ae707355..29ca2f7959efb 100644
> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
[ ... ]
> @@ -3063,6 +3064,16 @@ void v4l_printk_ioctl(const char *prefix, unsigned int cmd)
> }
> EXPORT_SYMBOL(v4l_printk_ioctl);
>
> +static int _file_iterate(const void *priv, struct file *filp, unsigned int fd)
> +{
> + const struct file *fh_filp = priv;
> +
> + if (fh_filp == filp)
> + return fd + 1;
> +
> + return 0;
> +}
> +
> static long __video_do_ioctl(struct file *file,
> unsigned int cmd, void *arg)
> {
> @@ -3111,6 +3122,12 @@ static long __video_do_ioctl(struct file *file,
> goto unlock;
> }
>
> + if (unlikely(vfh->fd < 0)) {
> + vfh->fd = iterate_fd(current->files, 0, _file_iterate, file) - 1;
[Severity: Low]
Can vfh->tgid and vfh->fd belong to different processes if the file is
inherited across fork() or passed over SCM_RIGHTS before the first ioctl?
v4l2_fh_init() records current->tgid at open() time, whereas iterate_fd()
looks up vfh->fd in current->files of whichever process issues the first
ioctl, breaking the documented struct v4l2_fh contract that @fd belongs to
the process in @tgid.
> + if (!vfh->fd)
> + vfh->fd = -1;
> + }
[Severity: Medium]
Does the !vfh->fd check overwrite a valid file descriptor 0 with -1?
_file_iterate() returns fd + 1 on a match and 0 otherwise, so subtracting
1 from iterate_fd() already maps a missing entry to -1 and fd 0 to 0.
When the video device is opened on fd 0, resetting vfh->fd to -1 records
the wrong descriptor for tracing and causes every subsequent ioctl on this
handle to repeat the iterate_fd() scan.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127-v4l2-add-ftrace-v4-0-24138479002f@collabora.com?part=3
next prev parent reply other threads:[~2026-11-27 16:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 16:45 [PATCH v4 0/9] v4l2: Add tracing for stateless codecs Detlev Casanova
2026-11-27 16:45 ` [PATCH v4 1/9] media: Move visl traces to v4l2-core Detlev Casanova
2026-11-27 16:45 ` [PATCH v4 2/9] media: Map each struct field to its own trace field Detlev Casanova
2026-11-27 16:45 ` [PATCH v4 3/9] media: Add tgid and fd fields in v4l2_fh struct Detlev Casanova
2026-11-27 16:57 ` sashiko-bot [this message]
2026-11-27 16:45 ` [PATCH v4 4/9] media: Add tgid and fd to the v4l2-requests trace fields Detlev Casanova
2026-11-27 16:45 ` [PATCH v4 5/9] media: Add missing types to v4l2_ctrl_ptr Detlev Casanova
2026-11-27 16:45 ` [PATCH v4 6/9] media: Trace the stateless controls when set in v4l2-ctrls-core.c Detlev Casanova
2026-11-27 16:45 ` [PATCH v4 7/9] media: Add stream on/off traces and run them in the ioctl Detlev Casanova
2026-11-27 16:45 ` [PATCH v4 8/9] media: Add HW run/done trace events Detlev Casanova
2026-11-27 16:45 ` [PATCH v4 9/9] media: hantro: Add v4l2_hw run/done traces Detlev Casanova
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=sashiko-outbox-237953@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=detlev.casanova@collabora.com \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=media-ci@linuxtv.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