mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitry Osipenko <dmitry.osipenko@collabora.com>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	Hans Verkuil <hverkuil+cisco@kernel.org>,
	linux-media@vger.kernel.org, kernel@collabora.com,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] media: synopsys: hdmirx: move the reset bulk data out of the driver data
Date: Tue, 1 Dec 2026 00:45:36 +0300	[thread overview]
Message-ID: <a620e44b-a6a8-4cff-92e9-3595d0a870ec@collabora.com> (raw)
In-Reply-To: <4c7ef880-0de6-4cc3-96fd-e1d4fd5fde6d@pengutronix.de>

On 11/30/26 13:58, Sascha Hauer wrote:
> Hi Dmitry,
> 
> On 2026-11-26 19:18, Dmitry Osipenko wrote:
>> 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?
> 
> hdmirx_v4l2_release() frees hdmirx_dev and the reset array with it. The
> last thing hdmirx_remove() does is to call v4l2_device_put(). With no
> open filedescriptor hdmirx_v4l2_release() will be called immediately as
> a result, freeing the resets array. After hdmirx_remove() then the devres
> machinery runs and devm_reset_control_bulk_release() accesses the freed
> array. This patch avoids this by making the reset array a separate devm
> managed allocation.
Thanks, see now

Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>

-- 
Best regards,
Dmitry

      reply	other threads:[~2026-11-30 21:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 15:06 Sascha Hauer
2026-11-26 16:18 ` Dmitry Osipenko
2026-11-30 10:58   ` Sascha Hauer
2026-11-30 21:45     ` Dmitry Osipenko [this message]

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=a620e44b-a6a8-4cff-92e9-3595d0a870ec@collabora.com \
    --to=dmitry.osipenko@collabora.com \
    --cc=hverkuil+cisco@kernel.org \
    --cc=kernel@collabora.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=s.hauer@pengutronix.de \
    --cc=stable@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®