From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.180.11 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796075177; b=pY1++mWm2JYqfRRyQsVRx9hvUZT8t0tSc600KY9Q0K9dfzrhsmC68avH2SEWuY8N2gQX Rz3LxS2u2FqqxyYtkYDQCV8JYqsib0TbKfqvK5SRzIPvmbLXMJY+h1b791oU/SQ17UUBs ftQ64CAKf8W7z8yzXzkksHv61bUG9yjyd/jyCtZNhFsVXHk2felDlyegkfPEx29XyeWnT yyHRVRApfoVMgDBE0nICAqtBNZtlDFNgkk78vAXS0DOCUILgZc1gIEp7mBHjoGl0EiFhk I34Y54PUonEfUQoeRyrhfUYndOR0wf2Pb/tPXI6aLhEXEMsQHt6Wmkt18+E3e5iGEvw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796075177; h=DMARC-Filter:DKIM-Signature:Received:Message-ID:Date:MIME-Version: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-ZohoMailClient; bh=/RurHDUIkR3hwkKlRP5LdYmT6SLZkemze7gQVMUc05g=; b=c9oNobMOovKb2Dr8h7sdlKijlNylv3kYCgU/mIFRHoqjOVHEYKUCgKBp6bg7BGgkHW3e euPcsW4TcP9OdEIKZQKbo1MWLtVoEVrz0oa26Gizqxw72eSHLeVjkSu4tMRE9zpN6t0u4 GW9O8eV9YQx8br6H5FLeqUMY4wqVj7WU+Mb+aoT7gySMs3nTwKlVU71BSpOq4J35KopCM tBBv8bLtq7LztTo+/zAYv7Id6Asvna5SseT+ToDFg65P+c5FtH/6hjzT77pCcY7l9ucb+ ga3I/BsMZyuA0u/MhIk8/pQuDZ97xP74NDRjnMlEvlHsTTL4s6nLMegFjykBNGrnexA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=zohomail header.b=dD9h7Qsn; arc=pass header.oldest-pass=0 smtp.remote-ip=165.173.180.11 Received: from sender6-op-o11.zoho.com (sender6-op-o11.zoho.com [165.173.180.11]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A3EB606A31A; Mon, 30 Nov 2026 21:46:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5A3EB606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=zohomail header.b=dD9h7Qsn ARC-Seal: i=1; a=rsa-sha256; t=1796075143; cv=none; d=zohomail.com; s=zohoarc; b=I2iI2MvAPjPq7ECi9QLtQYGRwcWVONGUshZBRS/YI8rCU5XFKuznluU1TcDdW9Ugc0axMxxuxDmNd15k9iPVMXZHGd/6B4ib1nd0FuJ6YXFoQ6cCs1z6o7haJidLnO1wFEjlSk64Rd6+Fk0NsnlhiVm4MUIv1kZzBh8nPH+xJus= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1796075143; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=/RurHDUIkR3hwkKlRP5LdYmT6SLZkemze7gQVMUc05g=; b=Y9R5/UxbrAlhp+JSP3UpX4djrmKCFPSvVK22+jgRE355MAv4A5jEfO70v1bwy0Cf7nxMSFMwfeiAa/rAOVhkzhjDgU+Tlq/Eag79z1K1PIzwWcywUtk/m28wkkWHCS0D9mjSK4+o4Be/VKZz2Jir7KppTR97djiX4Lr90icbezQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=dmitry.osipenko@collabora.com; dmarc=pass header.from= DKIM-Signature: a=rsa-sha256; b=dD9h7QsnrLvrHU5SE7fQXULbJ11mpuPXmUVqubHVSQfN+MSo+wtdpwavuT3sI6FoaxOgGc0WdBrjJHni0VDNsZ9/IcByYcKoBomuUMIo8Y7Wb9BBx1Yo58K1MxYvfFVddnzXec+EtnctaBokaxOjt2IQTRBpqve/HaQ570/ppGY=; c=relaxed/relaxed; s=zohomail; d=collabora.com; v=1; bh=/RurHDUIkR3hwkKlRP5LdYmT6SLZkemze7gQVMUc05g=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc; Received: by smtp.zohomail.com with SMTPS id 1796075140293898.9524497885377; Mon, 30 Nov 2026 13:45:40 -0800 (PST) Message-ID: Date: Tue, 1 Dec 2026 00:45:36 +0300 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] media: synopsys: hdmirx: move the reset bulk data out of the driver data To: Sascha Hauer Cc: Mauro Carvalho Chehab , Philipp Zabel , Hans Verkuil , linux-media@vger.kernel.org, kernel@collabora.com, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20261116-hdmirx-resets-uaf-v1-1-1903146a3118@pengutronix.de> <4c7ef880-0de6-4cc3-96fd-e1d4fd5fde6d@pengutronix.de> Content-Language: en-US From: Dmitry Osipenko In-Reply-To: <4c7ef880-0de6-4cc3-96fd-e1d4fd5fde6d@pengutronix.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ZohoMailClient: External 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 >>> --- >>> 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 -- Best regards, Dmitry