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=1796202944; b=w0oCB5F7SQm0vOF8DcbC3qiLZHg3oGGrwMZerRguY+42os/Rn7MM0XkJNL0wuA+Z1gbo y79n7Zr/tICqxWZbhZv1loM0u/okTGaCIN3CAeZfMnx8ntij7XVtfs0hN3giQpb0/9y4G kRGuiUWrK+1wq+e4T301SARjAB7W9weujC9uJRKrBYyogvoMfEZ5796CuhVzvm6W8oJMY 4WRRGbuc07D8zQ1bJRvDLId5vz3L2T7pSBzQ5dtHweYvw+3L6DEBuQAdfkjL0XXaN9NtV 7aFRrIVaL9/pE3LKCT7GE9+CqLVlsH7z9ELMkRsOP2sH/bvSAFB98h8KcDzAZV2JpPA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796202944; 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-Proofpoint-Spam-Details-Enc:X-Proofpoint-ORIG-GUID: X-Proofpoint-Spam-Info:X-Proofpoint-GUID:X-Authority-Analysis: X-Proofpoint-Virus-Version:X-Proofpoint-Spam-Details; bh=zHDSuj//lC0OH+5QeHtX/TDg7ct53PlhgiMJt6b8CEI=; b=2f19bvM4TXaZx/tOCKTUTTI8KM86PBoMJGhl8D6rc4WZZKtYboE+FelOOjAVBj7TU1nl gZE2axUFwn0m6k8C5lix6guMKW/6AD4oo8Ul6+Ly6tYbdUtK+dWkYkBZLcOrEmbb89J1P 4UEmoW+AhuCbrBTLkEBixmfOdF/5a6xEJqy8XRO26ObhjM6ppDFzD7+CGOb/boJSjSZvs ripSMB6ZTGpJFO7fEs8GaeZa3/KuS8HR+CoE9xenDiYvfvLW9PdTKQwOMCKuPRJHX9RJR 4yWDISaBEohOgOLlFVtanUB3dWL72ZERaL5L+nYKO8qnC1ijAIl2I1cg3G9cHbuAcpw== 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 67237606A329 for ; Wed, 2 Dec 2026 09:15:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 67237606A329 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 (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B26pTQ94111442 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 4ja29vkgqw-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-386ad819860so9967548eec.0 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=y2fNvsbrTL7Z6SrDrJioUo739V9zzpHvXkBeA8wuFILG/uOaE8gG8VArgU70/fDCLe VMMaAQEgjbqXLCtD/L7UeTcnykZ85vbw90aFBXhrBlbOk8IkFxLkXCbJpNmVzwV8gs4k iDOUjvxlACi4W+qVcEfdxCFsJP17x5QQp+07n9JPhJGkFHa/inXLB+x04+fNui7XKIGp 6cCj+YZg8fgivMmmc0LdxMvWWPpdlnTPg3obPUvu1gW60U9fEuMnrLS3ha6UUb/7Lu7X Bh2Xgehe/Cjesz8slXWQEdCdv56VfiVbCEM43ebUXiT7clevDpHYp4jPBWCVrCeTRlbG GspA== X-Forwarded-Encrypted: i=1; AL+hErHUFGednhExMjyLkJAuoXF4PBVnI2Cv8Gml7+2cNhTusvmnDGnXxcWWfRNayuKM8XdVgOpAuME=@vger.kernel.org X-Gm-Message-State: APuU4Z+inpP23F647YZ+BeX0qiJ0bEaGRjgzb7rRq2uUR8BZWnjnijVb QGhQp48HBptM1etsI8xsvMJOUyEQmOlRbY6Vv0z0T+Uv/OB0rjcdhRK1bqGscmcZEXPdssZhoWt MoCwj6/9fgWOE9WeBXv5Bl9qH/O5iYYZDdZZN0k2GTXl6ZY3wV7fBJRNFQX8= X-Gm-Gg: AZFdTZdBW0xkioVqEgHOQSz9Kit4ew2CPyi7sD0y9fRtiK5wryxRG9/vKKEhYVHWtb/ ajSgZYyRU6YEI28Mwv8u7YxbTjgbt/CZskH9o0X+laAPDEAdjIstUlRGd/Nae1r6Kn8eR40XW+j 33i2LFQ+V4ep6w+/etSn1Y6aOXem15e8P6lxWhT4rd6y36wzbv2lIj56itmoKRKwgbWAhMYzs+B zN9pLpK7BU3qCVtMbQ5wgFkn89FkFHJBD0gURfAbjTlSHq/Xj4J6NYLhKxzY/35UtA+mwnIw9+v x17u8uJF1vYiZfpF59aX+oJgS6pndntV9NfIjOGtmwpO3EG4pk7Hp9CmT6ZtaqzQ/lIIey+Nbvc d5puY2nhjFHY9OZ7YQX9q00viNY0yXYZlpYQn/UOhcAELxHptZLfz8Q+OSZsZxwoBuXxIBusCDJ 0TqDQ= X-Received: by 2002:a05:693c:8951:10b0:386:b4a1:d92a with SMTP id 5a478bee46e88-386b4a1daa3mr29669917eec.1.1796202941705; 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: stable@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-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAyMDAzNiBTYWx0ZWRfX+LP2Lb/afyqH C91n5ZLIBP1QT1sNRkZ9L2xWz78qvAj872EeGDKY3DqVhHYvrOdA1Tzj3L2vJNHnymfsYy1c0DI SjqhV3Z/2H4A6DWiXJv+BuVxZM2pvwGe3UGmgK3pKyVSC8Y+trCkeEzWCW7LNOhjPkHG6FJalV2 vgjtQG/8Z4q4MqJEhp/QS23qdd7tEUV+3Msy0UVdc7YC24uPpQ1R7y5EpVrbdHqSXG1s+kdXtr8 lP0YTtSOCxfns2syamLADKXxaEUJ0gO3lD6ZFH1vD3uJIoc0PF9Qcb1EKsjx63CJRXY/EKdJNfa ps8kb6gnv8R1+Ko5RHY9/klGvx3jzurmCw7EG0DnRm4kgtfvEFfs8dRffL4YCzC7uC5cKI9PyCG cndQGlS8xH5/cFpK/RR2tKwTLWOYb82YwiZLtHX1w3W5Bio7wvlJl8XzlkfTrPyWIXMof2nmyFe 7BthdiXuUT1rWjkZkIg== X-Proofpoint-ORIG-GUID: my-hnQf0NLxoqemTkpYG135U6M0iVI1c X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAyMDAzNiBTYWx0ZWRfXzafXrcyxYmfY DIGGmOYMLrJ1+m4/VsIn+UPNZwnGTrFDWRVFyEZOVNwsne46BCrglLhzfdLOklsUNH2SG8AZgKk vUIvgKKqSCp2QwazT0qNvftbRpOz6Pc= X-Proofpoint-GUID: my-hnQf0NLxoqemTkpYG135U6M0iVI1c X-Authority-Analysis: v=2.4 cv=JvFkP84C 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=yOCtJkima9RkubShWh1s:22 a=VwQbUJbxAAAA:8 a=EUspDBNiAAAA:8 a=nIuUYn6eYUHrZjy3AOsA:9 a=QEXdDO2ut3YA:10 a=bBxd6f-gb0O0v-kibOvt:22 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 suspectscore=0 clxscore=1015 adultscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 impostorscore=0 bulkscore=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 > >