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=185.203.200.13 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796036337; b=otTCF5bVaUo0Kps0evviCDHgLS/3UT+mD10eKzez8keZNoYoMGeO3cbXSf+0fRGmBBWw 4pqGWW5BnEw1gTnJcnZfF5JZkrwQvYkfPyeGqgUtiVmNR/P0YnJmMBIphMcVBtHKgGpE8 6d6G98cRv5d0HwDSfCZMyciRjEBOeCpQYlyAwp6FSbYQxUwrW7yDiFNcfCncysW9UaTLD iLxXcniVa7TH0gdRZy2lENITBRZxvDx07hmPzDf1tniDfuGB0iMpOLzceEz0Llz2rQ8o7 cr1cjle6zN7GUTgFXPnDvBkGFkZg02YwhQjG2A9GAN8Vm7BsyUYBRJJAg6vS0uDebfw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796036337; h=DMARC-Filter:Received:DKIM-Signature:Message-ID:From:Subject:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=FLCe/FH31QMSbB27jeyUEqObBydkwO9Br8eqR+QWv5Q=; b=b1cyB92x0YF6Yo72PFd3XKj6f5Jy0Lf4NxQJV2F/iNAeamIkJCxWSIfpbj9vD0JUAOt2 zwP8mJi1GpTB0J2zB5pLPJKFS/I2WHMDswJ0eWznqnr40lAlvRV9Dlzm/Dunuk4vwA2L4 FWlpSLTnyNoR5D4grhGpUQs3Dz98c9GX9rzwUpdo+qlfICl8aCaY6aIlUtpoSmqHQ1HpV bKWGyuiM6cD+rKnbzObdx7jOhp2NhP9yvMFHuaQbs3CH17CNnaSTsysE4XimiGWUxSg+g awiInCUelXhA8WRbY6v04Nf6jJ6mq4J/S+3mJJv1oHF/Mxgov9QYHlzAGJyjWbDhaGg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; dkim=pass header.d=pengutronix.de header.i=@pengutronix.de header.a=rsa-sha256 header.s=20260414 header.b="K/4JR8S5"; arc=pass header.oldest-pass=0 smtp.remote-ip=185.203.200.13 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) (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 CAB68606A31C; Mon, 30 Nov 2026 10:58:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CAB68606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=pengutronix.de header.i=@pengutronix.de header.a=rsa-sha256 header.s=20260414 header.b=K/4JR8S5 Received: from [127.0.0.1] (unknown [IPv6:2a02:560:5c0a:3200:9ebf:dff:fe00:fdb5]) (Authenticated sender: sha@pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id B4563205A49; Mon, 30 Nov 2026 11:58:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de; s=20260414; t=1796036333; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FLCe/FH31QMSbB27jeyUEqObBydkwO9Br8eqR+QWv5Q=; b=K/4JR8S59hD+nYBuM6P37rrjI5yUvKkzQJkXrFGB2t1W5XdxFgkKA+Oq8CyB9W6iHVnwMo oHLHHN8A1OgLcNw+irqf2IfTP89ZlMkXNlQvdzWQr72OJ+fqpzOw2Gtco/DLDoh5poqk1q /A9mI8uRXYTVHuIivlb+ciR681hqudKAPmyWM23rjaOD/tRHY32Ppp9QidV2H+IJUD4Vr/ Kz8WjujYgArYJIicwoBXcWSyM+v1ecb/wlUJzAr9oQFbJ/PeFqIXjzVpemepdkGJO+5EGu ebKQzemsUDCo3/JReP6ZI3ma3YcxcQTyXufbe56MfqPaq4+7GcdvAymWjcpTfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de; s=20260414; t=1796036333; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FLCe/FH31QMSbB27jeyUEqObBydkwO9Br8eqR+QWv5Q=; b=EfaAXeaEH3TUnP4WEQRSOsyBuz9sm8hDGn7SMaaAcfJ7lEQnMH1qZDh4oDk8Iobuxniy0K CgUOayIvTE1p9V41sdcm9gL14MN/vX0+zlC8NRbIYmJS9I9a3v8nF0ukQhp/Xb2v4sdGG8 37uNXeE5w4ZWNJZojQtD7Kgsd78VDws5hqDWxKoT9h9H5kdCWfzX+xNti4xWglY2c456fs oZAclTra0y1FIRRwm557l4iC3wsxeCzbiizUl5NDzbvTkhT1j/uI7kasp2vdBckejQU6F5 Zcyz1Q/xLLusSQLPur2LlunqtnFlls9NSEsua4/bEwPfMwO/wNkAvdKb3JvgsA== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=sha@pengutronix.de smtp.mailfrom=s.hauer@pengutronix.de ARC-Seal: i=1; s=20260414; d=pengutronix.de; t=1796036333; a=rsa-sha256; cv=none; b=cED8p7P5/G9DnUAUmeSfQQpeTSOqsBaBYwJL2x9TPkycpSpD84o03XQU8zcRjNQMbIq0iR RfsR/f9Xc9dDC0mvZYgsw6xTGqH6RDGGQBcyQGaq+BoCj5B2vz7s1RcB3spMpc+UptPS2X P4DpTDsZJxszjMN9fy5ogPEAROl1hPPoO4ogxBBz00hJ7VFpalISpF4O8dz/C2uh3h8K9Z eAEsz9AMy/GfrYWVyIYfodoctF40LVILXJ13W8WheBIM2Cwfb4oOupc6OEK4JJu/FdxfGk 8HhUZBFTT9ucIY3d4I00HfecY6FIkIDkcbd9gIVA2iL3nnk9Mb811Fkq5ffsyQ== Message-ID: <4c7ef880-0de6-4cc3-96fd-e1d4fd5fde6d@pengutronix.de> From: "Sascha Hauer" Subject: Re: [PATCH] media: synopsys: hdmirx: move the reset bulk data out of the driver data To: "Dmitry Osipenko" Cc: "Sascha Hauer" , "Mauro Carvalho Chehab" , "Philipp Zabel" , "Hans Verkuil" , linux-media@vger.kernel.org, kernel@collabora.com, linux-kernel@vger.kernel.org, stable@vger.kernel.org In-Reply-To: References: <20261116-hdmirx-resets-uaf-v1-1-1903146a3118@pengutronix.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 10:58:53 +0000 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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. > >=20 > > Give the array an allocation of its own with devm_kcalloc(), so it lives > > exactly as long as devres needs it. > >=20 > > Fixes: 03ec4aa9817b ("media: synopsys: hdmirx: free the driver data whe= n 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. > >=20 > > The remaining patches of the series will follow as v4, rebased onto this > > and with the v4l2-compliance output you asked for. > >=20 > > 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(-) > >=20 > > diff --git a/drivers/media/platform/synopsys/hdmirx/snps_hdmirx.c b/dri= vers/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 e= vent */ > > - 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_de= v *hdmirx_dev) > > } > > } > > =20 > > + hdmirx_dev->resets =3D devm_kcalloc(dev, HDMIRX_NUM_RST, > > + sizeof(*hdmirx_dev->resets), > > + GFP_KERNEL); > > + if (!hdmirx_dev->resets) > > + return -ENOMEM; >=20 > hdmirx_dev->resets array is a part of hdmirx_dev struct, the hdmirx_dev=20 > is used by hdmirx_v4l2_release(). This looks like a slop, what am I missi= ng? 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. Sascha --=20 Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |