All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sascha Hauer" <s.hauer@pengutronix.de>
Cc: devicetree@vger.kernel.org, media-ci@linuxtv.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v2 7/9] media: v4l2-device: wait for notifications when unregistering a subdev
Date: Thu, 24 Sep 2026 12:14:18 +0000	[thread overview]
Message-ID: <20260924121418.A2F6A1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260924-hdmirx-media-v2-7-c12f641d8b0f@pengutronix.de>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] v4l2: NULL pointer deref or UAF in v4l2_subdev_notify()
--

commit 6588945fb74790836c51288e07f21eed874e7fe8
Author: Sascha Hauer <s.hauer@pengutronix.de>

media: v4l2-device: wait for notifications when unregistering a subdev

This commit introduces SRCU protection for v4l2_subdev_notify() to prevent
race conditions with subdevice unregistration. It adds a boolean flag and an
SRCU read-side critical section to ensure the callback doesn't run after the
bridge driver unbinds.

> diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
> --- a/drivers/media/v4l2-core/v4l2-device.c
> +++ b/drivers/media/v4l2-core/v4l2-device.c
[ ... ]
> +/*
> + * Stop notifications to sd->v4l2_dev and wait for those in progress.
> + * Callbacks read sd->v4l2_dev, so it must stay set until this returns.
> + */
> +static void v4l2_subdev_disable_notify(struct v4l2_subdev *sd)
> +{
> +	WRITE_ONCE(sd->notify_enabled, false);
> +	if (sd->v4l2_dev->notify)
> +		synchronize_srcu(&v4l2_subdev_notify_srcu);
> +}
> +

[Severity: High]
If the bridge driver does not provide a notify callback, this skips the SRCU
grace period. Could this break synchronization for a concurrent
v4l2_subdev_notify() reader that just observed notify_enabled as true?

[ ... ]
> +void v4l2_subdev_notify(struct v4l2_subdev *sd, unsigned int notification,
> +			void *arg)
> +{
> +	struct v4l2_device *v4l2_dev;
> +	int idx;
> +
> +	if (!sd)
> +		return;
> +
> +	idx = srcu_read_lock(&v4l2_subdev_notify_srcu);
> +	/* Pairs with smp_store_release() in __v4l2_device_register_subdev() */
> +	if (smp_load_acquire(&sd->notify_enabled)) {
> +		v4l2_dev = sd->v4l2_dev;
> +		if (v4l2_dev->notify)

[Severity: High]
Since the reader unconditionally dereferences v4l2_dev here regardless of
whether the callback is provided, could this lead to a NULL pointer 
dereference or use-after-free?

If a concurrent call to v4l2_subdev_disable_notify() skips the
synchronize_srcu() call because notify is NULL, the unregistering thread
will proceed to clear sd->v4l2_dev and potentially free the v4l2_device. 

If this reader is preempted right after checking notify_enabled, wouldn't
it wake up and dereference a NULL or dangling v4l2_dev pointer?

> +			v4l2_dev->notify(sd, notification, arg);
> +	}
> +	srcu_read_unlock(&v4l2_subdev_notify_srcu, idx);
> +}
> +EXPORT_SYMBOL_GPL(v4l2_subdev_notify);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260924-hdmirx-media-v2-0-c12f641d8b0f@pengutronix.de?part=7

  reply	other threads:[~2026-09-24 12:14 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24 12:05 [PATCH v2 0/9] media: synopsys: hdmirx: support an HDMI bridge in front of the receiver Sascha Hauer
2026-09-24 12:05 ` [PATCH v2 1/9] media: synopsys: hdmirx: add media device infrastructure Sascha Hauer
2026-09-24 12:17   ` sashiko-bot
2026-09-24 12:05 ` [PATCH v2 2/9] media: synopsys: hdmirx: add media entity for video capture device Sascha Hauer
2026-09-24 12:05 ` [PATCH v2 3/9] dt-bindings: media: snps,dw-hdmi-rx: add a port for a bridge in front Sascha Hauer
2026-09-24 12:16   ` sashiko-bot
2026-09-24 16:55   ` Conor Dooley
2026-09-24 12:05 ` [PATCH v2 4/9] media: synopsys: hdmirx: add async subdevice support Sascha Hauer
2026-09-24 12:05 ` [PATCH v2 5/9] media: synopsys: hdmirx: give the signal lock wait a real timeout Sascha Hauer
2026-09-24 12:06 ` [PATCH v2 6/9] media: synopsys: hdmirx: skip the 5V detect interrupt without a GPIO Sascha Hauer
2026-09-24 12:06 ` [PATCH v2 7/9] media: v4l2-device: wait for notifications when unregistering a subdev Sascha Hauer
2026-09-24 12:14   ` sashiko-bot [this message]
2026-09-24 12:06 ` [PATCH v2 8/9] media: v4l2-subdev: notify the bridge when the source power changes Sascha Hauer
2026-09-24 12:06 ` [PATCH v2 9/9] media: synopsys: hdmirx: get the 5V state from the upstream subdev Sascha Hauer

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=20260924121418.A2F6A1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=media-ci@linuxtv.org \
    --cc=robh@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.