mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] media: synopsys: hdmirx: move the reset bulk data out of the driver data
@ 2026-11-16 15:06 Sascha Hauer
  2026-11-26 16:18 ` Dmitry Osipenko
  0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2026-11-16 15:06 UTC (permalink / raw)
  To: Dmitry Osipenko, Mauro Carvalho Chehab, Philipp Zabel,
	Sascha Hauer, Hans Verkuil
  Cc: linux-media, kernel, linux-kernel, stable

devm_reset_control_bulk_get_exclusive() keeps a pointer to the bulk data
it is handed and releases the controls through it when devres is torn
down. Since the driver data is freed from the v4l2_device release
callback, remove() and the probe error paths may free it before that
happens: on every unbind without an open file descriptor, and on every
probe that fails after hdmirx_parse_dt(), in practice a deferral.
devm_reset_control_bulk_release() then reads the controls from freed
memory. KASAN reports the use-after-free, the controls stay claimed, and
the deferred probe fails for good with -EBUSY on the exclusive get.

Give the array an allocation of its own with devm_kcalloc(), so it lives
exactly as long as devres needs it.

Fixes: 03ec4aa9817b ("media: synopsys: hdmirx: free the driver data when the last user is gone")
Cc: stable@vger.kernel.org
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
Hans, this fixes the patch you applied from v3 of the hdmirx bridge
series. Sashiko pointed out the use-after-free on v3, and the fix was
meant to go into v4 of that patch. If you can still replace 03ec4aa9817b
in your tree, please squash this into it; otherwise it applies on top.

The remaining patches of the series will follow as v4, rebased onto this
and with the v4l2-compliance output you asked for.

The fix was developed with the help of an AI coding assistant (Claude),
which also drafted this message.
---
 drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c b/drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c
index a241761b1bcd9..8a5304603c00d 100644
--- a/drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c
+++ b/drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c
@@ -144,7 +144,8 @@ struct snps_hdmirx_dev {
 	struct mutex phy_rw_lock; /* to protect phy r/w configuration */
 	struct mutex stream_lock; /* to lock video stream capture */
 	struct mutex work_lock; /* to lock the critical section of hotplug event */
-	struct reset_control_bulk_data resets[HDMIRX_NUM_RST];
+	/* devres may release these after the driver data is freed */
+	struct reset_control_bulk_data *resets;
 	struct clk_bulk_data *clks;
 	struct regmap *grf;
 	struct regmap *vo1_grf;
@@ -2296,6 +2297,12 @@ static int hdmirx_parse_dt(struct snps_hdmirx_dev *hdmirx_dev)
 		}
 	}
 
+	hdmirx_dev->resets = devm_kcalloc(dev, HDMIRX_NUM_RST,
+					  sizeof(*hdmirx_dev->resets),
+					  GFP_KERNEL);
+	if (!hdmirx_dev->resets)
+		return -ENOMEM;
+
 	hdmirx_dev->resets[HDMIRX_RST_A].id = "axi";
 	hdmirx_dev->resets[HDMIRX_RST_P].id = "apb";
 	hdmirx_dev->resets[HDMIRX_RST_REF].id = "ref";

---
base-commit: 48fe5a7834cc10081887d7bcd9ff0a4cadc3fa8c
change-id: 20261116-hdmirx-resets-uaf-d6792101954b

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] media: synopsys: hdmirx: move the reset bulk data out of the driver data
  2026-11-16 15:06 [PATCH] media: synopsys: hdmirx: move the reset bulk data out of the driver data Sascha Hauer
@ 2026-11-26 16:18 ` Dmitry Osipenko
  0 siblings, 0 replies; 2+ messages in thread
From: Dmitry Osipenko @ 2026-11-26 16:18 UTC (permalink / raw)
  To: Sascha Hauer, Mauro Carvalho Chehab, Philipp Zabel, Hans Verkuil
  Cc: linux-media, kernel, linux-kernel, stable

On 11/16/26 18:06, Sascha Hauer wrote:
> devm_reset_control_bulk_get_exclusive() keeps a pointer to the bulk data
> it is handed and releases the controls through it when devres is torn
> down. Since the driver data is freed from the v4l2_device release
> callback, remove() and the probe error paths may free it before that
> happens: on every unbind without an open file descriptor, and on every
> probe that fails after hdmirx_parse_dt(), in practice a deferral.
> devm_reset_control_bulk_release() then reads the controls from freed
> memory. KASAN reports the use-after-free, the controls stay claimed, and
> the deferred probe fails for good with -EBUSY on the exclusive get.
> 
> Give the array an allocation of its own with devm_kcalloc(), so it lives
> exactly as long as devres needs it.
> 
> Fixes: 03ec4aa9817b ("media: synopsys: hdmirx: free the driver data when the last user is gone")
> Cc: stable@vger.kernel.org
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
> Hans, this fixes the patch you applied from v3 of the hdmirx bridge
> series. Sashiko pointed out the use-after-free on v3, and the fix was
> meant to go into v4 of that patch. If you can still replace 03ec4aa9817b
> in your tree, please squash this into it; otherwise it applies on top.
> 
> The remaining patches of the series will follow as v4, rebased onto this
> and with the v4l2-compliance output you asked for.
> 
> The fix was developed with the help of an AI coding assistant (Claude),
> which also drafted this message.
> ---
>   drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c b/drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c
> index a241761b1bcd9..8a5304603c00d 100644
> --- a/drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c
> +++ b/drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c
> @@ -144,7 +144,8 @@ struct snps_hdmirx_dev {
>   	struct mutex phy_rw_lock; /* to protect phy r/w configuration */
>   	struct mutex stream_lock; /* to lock video stream capture */
>   	struct mutex work_lock; /* to lock the critical section of hotplug event */
> -	struct reset_control_bulk_data resets[HDMIRX_NUM_RST];
> +	/* devres may release these after the driver data is freed */
> +	struct reset_control_bulk_data *resets;
>   	struct clk_bulk_data *clks;
>   	struct regmap *grf;
>   	struct regmap *vo1_grf;
> @@ -2296,6 +2297,12 @@ static int hdmirx_parse_dt(struct snps_hdmirx_dev *hdmirx_dev)
>   		}
>   	}
>   
> +	hdmirx_dev->resets = devm_kcalloc(dev, HDMIRX_NUM_RST,
> +					  sizeof(*hdmirx_dev->resets),
> +					  GFP_KERNEL);
> +	if (!hdmirx_dev->resets)
> +		return -ENOMEM;

hdmirx_dev->resets array is a part of hdmirx_dev struct, the hdmirx_dev 
is used by hdmirx_v4l2_release(). This looks like a slop, what am I missing?

-- 
Best regards,
Dmitry

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-26 16:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 15:06 [PATCH] media: synopsys: hdmirx: move the reset bulk data out of the driver data Sascha Hauer
2026-11-26 16:18 ` Dmitry Osipenko

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®