From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796202943; b=5TBcx6LQni9H1FA1+jdMcrcE8CIEv85BWeYC+/tAd9OM07qGJOzE+y3Z+en4M+pmgctm SzSCv0X9P8vke1boQJe64uWmEYcwD3Bq/pn7oJ9zzRag8TolrBqeaHfOc4cR+1RyMxsx3 Bfx6FMea/FHvTrgwvy9d85miJ/iGumZaPxiUPYMXJRFUniEIRnfdf0MeTewes0dK3nPzX zwmGHKUZUmleLVYZbEB6xv+UeZDlSuKCm44NwKMOtTF24yFxBG7rT+8zSVv7LnUft/isr aIRmMNvR6rPS3NxUYhYfz4nma5/ILUmgkCyqYhxXBodS2pvKP4NLEP+GKcNB2K4HNZQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796202943; h=DMARC-Filter:Received:DKIM-Signature:Received:Received: DKIM-Signature:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Gm-Gg:X-Received:X-Received:Received:Message-ID: Date:MIME-Version:User-Agent:From:Subject:To:Cc:References: Content-Language:In-Reply-To:Content-Type:Content-Transfer-Encoding: X-Authority-Analysis:X-Proofpoint-Spam-Info: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-ORIG-GUID: X-Proofpoint-GUID:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=zHDSuj//lC0OH+5QeHtX/TDg7ct53PlhgiMJt6b8CEI=; b=YeNtChgAwdI2e3YVkkPxUzS/a+7yg600v1U7X3ddkIOoMrZgeQRFyfPsUkqEW3J1+Lxm 1FTwaL20yWRPqm3xrCZ/ezXeVbHb47DI2U89KhpPoWH5XsTnMW3JZBoVHah6pjhb8bl6N 9qeG82Bn6L0uKRXcbxIXqcTub5egYSaDY3lyUufP4LwgY8tGP7VZJ/2vdE/iSgiKggnYu eD+/3QYxUDgRAWu2acT3yHtyAJDQhNRCrjH8mms4iTjtsKNB+kVxr5JFIkc4g/ckpSqeO 81N2r2e7LgaVdb3ICyBLRjubwdXd7MjplsxJSRBDj9nu5fn843eJ/NHE6s9yTUDFvZw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=VeqCVFz0; dkim=pass header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=ChTYQQsk; arc=none smtp.remote-ip=205.220.168.131 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (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 672FA606A32A for ; Wed, 2 Dec 2026 09:15:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 672FA606A32A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=VeqCVFz0; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.a=rsa-sha256 header.s=google header.b=ChTYQQsk Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B26p28S854623 for ; Wed, 2 Dec 2026 09:15:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= zHDSuj//lC0OH+5QeHtX/TDg7ct53PlhgiMJt6b8CEI=; b=VeqCVFz08++Cy6R+ iaZSvze9rCw0HTca/m+cmmR3GXBkpGK34/A/TBPKLFgwsmYRa0wD3DxXaF3y643d caemEfDrr5tnXl5UbXNV4nRwZu6tOyiX6EJ/sGPuqH4rUyBnGnJu8NgVfIQ9yy7c GSP7Zt8bfjdfE2OFys437btVGGNl4DW4ZkAfpgTLn9TTRG7v1A05Rg6+zV405oeu v7iCEpdWLfQCS7caoR+bjVBz+DjFICBtyPXSxGTqPlwjtqDy65vffSj0PfTxcs4Q FEobxSszZG65LBexrD8rcLUBtBvEZXjo+DGABLQPj/iHSiZTChkIonxkrp2PMsWq iPB8IQ== Received: from mail-dy1-f198.google.com (mail-dy1-f198.google.com [74.125.82.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4ja4kyau6j-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 02 Dec 2026 09:15:42 +0000 (GMT) Received: by mail-dy1-f198.google.com with SMTP id 5a478bee46e88-386b8624cf7so1139407eec.1 for ; Wed, 02 Dec 2026 01:15:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1796202942; x=1796807742; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:subject:from:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=zHDSuj//lC0OH+5QeHtX/TDg7ct53PlhgiMJt6b8CEI=; b=ChTYQQsk0s7ohK9pEa/0DWKuJQahl71Tnj34g/SI0U2hmfaZJzJV5QICfV9xN2uSuh T6+PyLnzpKPLs5P2k9vTty+9Kp3ALrEXpzajqpuZDe+28tl2UtB+Xi2sozKr+YE8y1xb 5jgcx4KZdqDyX6K2m9ipwxla2+VpoU+c1cO1ob64P7+pmo573o2OwWO6dPKs8f1wSDvv pageL5AVFzp8K/HEifj6iGbZCsm5A5LhkhVcdnv5u+L9wOh/pEZaoJ+bC2mZKQXZxiIr rmWUkuha9gMR9j2fSJj4hBpX8linA7gpoTKXeOWtuS30Y3pg+20xey2/D7rf9ivpiUAs mkYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796202942; x=1796807742; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:subject:from:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=zHDSuj//lC0OH+5QeHtX/TDg7ct53PlhgiMJt6b8CEI=; b=P2ixOmkXQeaeJOK6OE1PbVnJw9YkMhtoHQ+7gQHsPN6Q5bEt6DbIsG9ttNqyVRqD0Y S7iN0KlbJNlziDZYQAvGkhX8k6JmtQkKbVHku4Kzron4UzxwG/dzRjNBRHjkxyda95me cDYKADnUQHGekxsyHitBiQDtQGxa9jdLadlZXzXl2PlkOFhMaTYb9l9xDLFGrd4XB09M HqT8hgfmO0rRm2owcNrwUWbjcGYCCwUh6H1YapfpQLB0L3Kdwscti4aCK3ISEGVjkTnQ StGrUOniV05ojo1+Qjf20B/HJ6HiRAEFHuxYCk5YKz/CTWEaIOEhlKYw+6TT2Z50ixMR fd+w== X-Forwarded-Encrypted: i=1; AL+hErF5SDt8RxELMP+KSdJxnzvpuKItSQMIx7ZsywEvHLuaEZ9evPh03YHBpOHANrtRV6/M/BHkpvIREHdcvAQ=@vger.kernel.org X-Gm-Message-State: APuU4Z8v3/AltdA09zn/4mt41yR0b6/ScWsXhng+mKxqfO0ICmiHOs2U NwFlI/20Wd07mhUAgMC+1Vve6b3nTzu3uBzLRlXeCpoPM7Pa0QAcx+mvlA89B4nz0YCHcRjZsyV XxeCa/xrGlBj0KLg/NGY8act+2qYzjSJ6B9US2nWdBPXg9BndW8iwe/CIc9azpPKEAgc= X-Gm-Gg: AZFdTZevkpoikd8V75yY9uLOVDUs9RoVbKy2d8OSH8x5bfElQZyG3mnfTCSicu6p35s fJvZoQ2SvhcNzLvaDUTVqye/BJs+m4sowqVzrPMe2mzb8JhfMhSOeWVCmaTdGPY+LuVjL7bsPgl nOZcG9nhaXlKWevQ3aKLFOud3qAH1vNK2340vw8fx6xm5FNUR/N0uHGE1biBouayB8yj03/EgwK mmHhy5XJ/gAfwhUSk2CJz6EkflLIUbrfPmoCYIm1WqmGnYqhoaFLq2p9VrHDdNs+SZLfJWfGrKL WoN94ywI1hO40gNuh1M2luTK6IxD9E7bqZ+mP8kgRlZN61zbaPqLY8Wi0C908xtAdpoGRgczcJx cv0eybLC0Oj5eKOz+Kzeg2inslVWeZJB6LgVrYf3huwhA4b0PxdNIUijx3mGA8IPSBhCvciygHh 1id10= X-Received: by 2002:a05:693c:8951:10b0:386:b4a1:d92a with SMTP id 5a478bee46e88-386b4a1daa3mr29669914eec.1.1796202941688; Wed, 02 Dec 2026 01:15:41 -0800 (PST) X-Received: by 2002:a05:693c:8951:10b0:386:b4a1:d92a with SMTP id 5a478bee46e88-386b4a1daa3mr29669871eec.1.1796202941024; Wed, 02 Dec 2026 01:15:41 -0800 (PST) Received: from [10.204.100.41] ([202.46.23.25]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-386c7c62a91sm78538001eec.17.2026.12.02.01.15.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Dec 2026 01:15:40 -0800 (PST) Message-ID: Date: Wed, 2 Dec 2026 14:45:33 +0530 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/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 From: Vishnu Reddy Subject: Re: [PATCH v3 3/4] media: iris: Fix use-after-free on unbind with open sessions To: bod@kernel.org Cc: Vikash Garodia , Dikshita Agarwal , Abhinav Kumar , Mauro Carvalho Chehab , Hans Verkuil , Stefan Schmidt , Dmitry Baryshkov , Hungyu Lin , linux-media@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Bryan O'Donoghue , sashiko-bot , stable@vger.kernel.org References: <20261119-iris-handle-unbind-v3-0-52d467a13907@oss.qualcomm.com> <20261119-iris-handle-unbind-v3-3-52d467a13907@oss.qualcomm.com> <179604427888.1329975.5206765366800243564.b4-reply@b4> Content-Language: en-US In-Reply-To: <179604427888.1329975.5206765366800243564.b4-reply@b4> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Authority-Analysis: v=2.4 cv=O8ysLx9W c=1 sm=1 tr=0 ts=6b0fe1be cx=c_pps a=wEP8DlPgTf/vqF+yE6f9lg==:117 a=ZePRamnt/+rB5gQjfz0u9A==:17 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=VwQbUJbxAAAA:8 a=EUspDBNiAAAA:8 a=nIuUYn6eYUHrZjy3AOsA:9 a=QEXdDO2ut3YA:10 a=bBxd6f-gb0O0v-kibOvt:22 X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAyMDAzNiBTYWx0ZWRfXxB6BxNbrQATM QJLWrUDs16SfIK7J2hj4onQys/dNUX9AiAwnkvnrmNoUl9fJf/bWd/GNoUzaYV2CIcmST91toZF 2k6oZ+3aj73yKcc/M9aoahmokTx/SPs= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAyMDAzNiBTYWx0ZWRfXzrmxmW5OnW0u EXjyQm4SUjP9TQfoyHUK1cl+EIpI7Fa83V5XuF84H7gwUDft4rAmkvN8UmHWYa8kZ6sF/gkAUul tYMnxG5E9xICU2F75Q7djOu615I86nKPwkDzUy2eU+RuOvuYegh/RAc1j7upwdnGQesu+EQ1oRm 2Mb9Gpz0QrFLrqf2lM/WvPp+Pq1MMBgNf5+WgNWVRwAzCUawrK7yEy3tI2L2Adhu9MmlzB7k/Bd WJBxMq61t1i5JwFa1S6mJa/+m9Zl5337kXfAtGa2HvZM0WbZMaiUGMWlkGXHCO4uS+cZCLlkOCG yUK+8GAdPweDdeUzEyy/jQIfrQvZFFoZ1OBp9wkTdA5TWCevvXa30LB5CUm7gYvhE2Gb2TtJoBK LgExj04pBT48aYkVRwQYsRLX0H/dDFP2+VixPxZ/NJvaZaABsSQ8sCxnQpeJxUOIUGh27RjvLYz IPBO0a3h+cpyH3AC0Qw== X-Proofpoint-ORIG-GUID: dVtPzlAPzGdpnITVBexsYggy3P18TycF X-Proofpoint-GUID: dVtPzlAPzGdpnITVBexsYggy3P18TycF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-02_02,2026-12-01_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 suspectscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612020036 On 11/30/2026 6:41 PM, bod@kernel.org wrote: > On 2026-11-19 17:15 +0530, Vishnu Reddy wrote: >> The driver can be unbound through sysfs while a client has a video >> session open. The core is devm allocated and freed when remove() >> returns, so the open sessions then use freed memory. >> >> Only the core structure needs to outlive remove(), because it is the >> only thing the file operations of an open session still use. Allocate >> it with kzalloc and tie it to the reference count of its v4l2_device, >> which every registered video device holds. It is freed when the last >> file descriptor is closed. The other devm resources (register mapping, >> response packet, clocks, power domains, interconnects) are only used by >> the power on/off sequence, the clock and bandwidth votes and the >> interrupt handler. All of them are released with the unbind, after the >> core is shut down. >> >> To make sure nothing uses them afterwards, set a removing flag at the >> start of iris_remove(). It makes core init, new sessions, command >> writes and the clock and interconnect votes fail with -ENODEV, so a >> client still holding a file descriptor cannot power the hardware on or >> vote for resources that are gone. A client waiting for the firmware >> only times out and returns an error without touching them. Runtime PM >> is also disabled explicitly in iris_remove() instead of with devm, >> because its callbacks use the core. >> >> Callers that hold a runtime PM reference, such as iris_open(), >> iris_hfi_queue_cmd_write() and iris_scale_power(), can still be running >> when remove() starts, as video_unregister_device() does not wait for >> them. Take an rw_semaphore for read around the reference and wait for >> it in iris_remove(), so that the references are dropped before runtime >> PM is disabled and the unbind releases the resources of the device. >> >> Fixes: 38506cb7e8d2 ("media: iris: add platform driver for iris video device") >> Reported-by: sashiko-bot >> Closes: https://lore.kernel.org/all/20260926064921.976721F000FF@smtp.kernel.org >> Cc: stable@vger.kernel.org >> Signed-off-by: Vishnu Reddy > A patch this size reworking object lifetimes ~ 102 insertions can't really > be presented to stable. This is a rearch. Will drop stable. >> drivers/media/platform/qcom/iris/iris_core.c | 5 +++ >> drivers/media/platform/qcom/iris/iris_core.h | 4 ++ >> drivers/media/platform/qcom/iris/iris_hfi_queue.c | 18 ++++++++- >> drivers/media/platform/qcom/iris/iris_power.c | 24 +++++++++++- >> drivers/media/platform/qcom/iris/iris_probe.c | 48 ++++++++++++++++++----- >> drivers/media/platform/qcom/iris/iris_vidc.c | 15 ++++++- >> 6 files changed, 102 insertions(+), 12 deletions(-) >> >> diff --git a/drivers/media/platform/qcom/iris/iris_core.c b/drivers/media/platform/qcom/iris/iris_core.c >> index d558475986ff0..9c0a9a2e4be07 100644 >> --- a/drivers/media/platform/qcom/iris/iris_core.c >> +++ b/drivers/media/platform/qcom/iris/iris_core.c >> @@ -56,6 +56,11 @@ int iris_core_init(struct iris_core *core) >> int ret; >> >> mutex_lock(&core->lock); >> + if (core->removing) { >> + ret = -ENODEV; >> + goto exit; >> + } >> + > This flag stuff in the code - another flag on top of an existing state > screams hack. > > If there is an interdependence between allocations we roll by hand and > allocations we let devm take care of then having to flag that to the driver > ane expecting to maintain that flag long term is asking for bugs. > > To be honest, I'm already dubious about core->state so I just don't get why > we need another meta state on top of our existing state. core->state is the firmware state, not the device lifetime. After iris_core_deinit() sets DEINIT, the next open() calls iris_core_init() and boots the firmware again. Without the removing flag, an open racing with remove() would re-init the core after it has been torn down. The removing flag prevents that. > I think this needs to be looked at again. Are we manually allocating or > devm'ing. > > Commit to one and the code will flow naturally from the design. Having two > methods is more complexity to think about; having one method reduces the > bugsurface. > > Is the thing to do here to drop the devm allocations and frees so you can > fully control what you are taking partial control of with the hand > allocations ? struct iris_core is the only hand allocation, because open file handles keep using it after remove(). devm frees at unbind, so it cannot be devm. Everything else is devm and is not used after remove(), since remove() stops all users first. Making everything a hand allocation would not change this. Running sessions must still not go wrong, and in-flight opens must still be rejected. Simply allocating in probe and freeing in remove() does not handle either case. core->removing is what makes both paths fail safely once remove() has started. > The LLM is babbling at me about specific things that go wrong in this code, > rather than post that verbatim here, I think the overall conclusion is - > don't mix and match - commit to one strategy. > > If devm can't support unbind, then either drop user-space initiated unbind > or drop devm. As explained above, only struct iris_core outlives remove(), and it is refcounted. Dropping devm would not fix anything. Setting suppress_bind_attrs to true would block user-space initiated unbind, but as discussed in v1, it hides the problem instead of fixing remove(). Unbind is generic driver-core behaviour, and remove() should be safe whenever it is called. > --- > bod > >